Error 429 trying to get all balances for all pools

Hi,

I am trying to get balances for a number of pool addresses using the balances api in Ethereum in one currency - the quote currency of the pair in the pool.

Basically I send the request from a python program and include a list of addresses for each currency so it is several requests. In some cases there are 2000 addresses for a currency - e.g. WETH - in which case I’ve parsed it to request 200 addresses at a time otherwise you get an error 413. In most cases it is only one address sometimes 2 to 10 addresses.

The problem I’ve got is I get an error 429 - too many requests - and the process cancels. I added a sleep of 2 seconds between requests and I still get the 429. My question is, how many requests per second are acceptable so I can put the sleep accordingly?

Also, is there a more efficient way to get all balances? This has massive cost in points - last time it cancelled I was over 2000 points and hasn’t finished yet. I accept there are a lot of pools on my list - several thousand - but there must be a more efficient way to do this

Thanks

Can you share the code snippet you’re using?

Would love to, but I now replaced it by a call to an end point in GekoTerminal that is free and gets me the info I want.

The 429 I found out what the problem was: I am on the free account while I develop and it is limited to 10 calls a minute. I had included a 2 seconds sleep in between calls, it had to be 6 seconds while on the free account. It did work however, for circa 4000 addresses it used up around 6000 points, almost all my balance - very inefficient.

The code was straightforward: I used the balance api as in:

{ethereum(network: ethereum) {address(address: {in:[“0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640”, “0x824a30f2984f9013f2c8d0a29c0a3cc5fd5c0673”, “0x08c8fda33443797f339bb7b8b920e9a5fcec47bd”, “0xa18d5eceb5fe22ee3cc228fb9c32b65adcedfa13”, “0x11b815efb8f581194ae79006d24e0d814b7697f6”, “0xc7bbec68d12a0d1830360f8ec58fa599ba1b0e9b”, “0xff002b2a1f29ad5d794841011952a0bb5d3d2fdb”, “0x1b117c931af91a298e8b91977500becc431281e7”, “0x331c2ac6d63ebc2c5a7a1479773edb2a6fa0fdc4”, “0xb0d1674ac747923a2cda952c5633f86fc6a0b7b0”, “0xbbef3ac961e3daa56ffaefeacefdcb7142daf911”, “0x98555273b697fa2b4cf3e009403b5ae31fd2c7a1”, “0x93744987543d67ff8e1616506151853eff4f9237”, “0xff82180e5ac6ffa7bbf3a3ea2d62572eab1aeca1”, “0xaa9009d8a50e25b184e55701591def806aca6c52”, “0x0b85b3000bef3e26e01428d1b525a532ea7513b8”, “0x0f5420a6ae6532b3ad343412b520069784bf346d”, “0xab3f65c91bad49df8ebb4f15fc1f11655c2a78f7”, “0x180efc1349a69390ade25667487a826164c9c6e4”, “0x79db69ab1ed51261a9fdc3bf0e6db3fa48b8cc52”, “0xa1178a171ffd6388917d877eec42c311cf22317d”, “0x90a70993d2a02f4d4769008c255873dfc9d308ff”, “0x06da0fd433c1a5d7a4faa01111c044910a184553”, “0x45db8aff924cf951cd8d9989a66b4a73c1321801”, “0x8733b519bcecd77675f9bf38ff1db2a5595bbb98”, “0x2a6c340bcbb0a79d3deecd3bc5cbc2605ea9259f”, “0xdf41310dd5324760549a8f8643f3d3f202ab358b”, “0x433a00819c771b33fa7223a5b3499b24fbcd1bbc”, “0x733d23a4d326fc4602dd3416828b67d91254423c”, “0x2947dc50cc24cc55afbf22807a49cc302d65568c”, “0x5851583caf4b9006d7119ef2d1b459861d0390fe”, “0x3dcafb0b085e7a3ddbf54db5faa18ef28bebdc69”, “0xdf8ef47910ce4a196f83b86b80809f1c5201650a”, “0x588273e7483c091083a191f3d619844dc7bf9ce3”, “0x05ae023e8af124438e96a4a35e068ce860ecc027”, “0x60594a405d53811d3bc4766596efd80fd545a270”, “0xb7f27e5ebf97d88f37e16eddecc59523361a60e1”, “0x510100d5143e011db24e2aa38abe85d73d5b2177”, “0xa7f098116e0ec8087022a22608aae0a61dcf62ae”, “0x839e2d728bfead41fc642a0ec4132b33ebb09d11”, “0x3fdfd866fa9e1ab4b6f6762cbdce0bf787583dc3”, “0x6ce7c80e59071c459fe2ef564d2d3769e3912f55”, “0x10638b13dcfea9ebf19954bab67a13f335e5a1d5”, “0xf2498cf36ede4e28c188042a0f2fdf9d89aa4ba8”, “0x00aa5429d1b7c90d156c812653970c6f86d5b062”, “0xa6cc3c2531fdaa6ae1a3ca84c2855806728693e8”, “0x8b123ab20819181fac82229dad3c88fe75a14d9e”, “0x4046279adbab7fa822c0dbdb49677236d3353195”, “0xa480a984f974d9daf70113c7af9fb014068dd519”, “0x09d1d767edf8fa23a64c51fa559e0688e526812f”, “0x704ad8d95c12d7fea531738faa94402725acb035”, “0xfb4492a1cd2a28d08b0b2a3ffa567342ea93776f”, “0xeb7693fabb5901a000b847854f6e9c10180e5f96”, “0x6ca298d2983ab03aa1da7679389d955a4efee15c”, “0x04da3160550625c4a149bf7e9487f7018ebc0af1”, “0x12db505b4f16bcc2d9932b2264711154592fa6d0”, “0xeefaa1be6a07aa3dbf2356159d96593edaf9879c”, “0xc45a81bc23a64ea556ab4cdf08a86b61cdceea8b”, “0xf01e605b6335735e31f7f2941e67c9e52afdcaec”, “0x7ecee76ce0c89cebb85addccbb4b39ed9b1a6370”, “0xc6e40537215c1e041616478d8cfe312b1847b997”, “0x8d3cdb3987bb4f9e31b8ddff6aa610067ba270b9”, “0x60ea0ce89d6a4c0957ac430f759c78838f9b95fa”, “0x198063c23ac1317ff3cc57d9f54faac6b675d89f”, “0xa43fe16908251ee70ef74718545e4fe6c5ccec9f”, “0xb36ec83d844c0579ec2493f10b2087e96bb65460”, “0x49341e428eb3a4448eedcda0b19c33dd649c48a1”, “0x87bea39353eab877ba99c9528d2ba9b52fc84bce”, “0x998cd81a2a332c5bb13d8ee32aece738b9957098”, “0xa06591252908576a0f64a8560ec0c8051782377c”, “0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8”, “0x465e56cd21ad47d4d4790f17de5e0458f20c3719”, “0x47082a75bc16313ef92cfaca1feb885659c3c9b5”, “0x11950d141ecb863f01007add7d1a342041227b58”, “0xb21f2424f0de1ed055e3707fbeb712b4de27853e”, “0x109830a1aaad605bbf02a9dfa7b0b92ec2fb7daa”, “0xb03f87e577c4fe4685cf2c88a8473414bb1d04f1”, “0xdef1c0ded9bec7f1a1670819833240f027b25eff”, “0x4c3d9ef889d7d3e61513f893763a23aada293937”, “0xd032c6f4053e70f1631c8151f880fe194b5cf173”, “0xdfc620f4243a09a6b618f24d5b7481cdef463536”, “0x5f553ab4943080863060ae81942adc42f5baef56”, “0x5b9ae327279233c039c94bef1767c46b1c08ab20”, “0x4729be5898eedcd9fc5bc644b440f15820f11b65”, “0x1cace584e768fe624f37827529dcb94eea2e4d48”, “0x5b7e3e37a1aa6369386e5939053779abd3597508”, “0xe93d040aa0b2929b0a5160328d7fef474062d6fb”, “0xd05d35b500dee15aecbae563a28e790ae1594cb4”, “0x0f5a2eb364d8b722cba4e1e30e2cf57b6f515b2a”, “0x43de4318b6eb91a7cf37975dbb574396a7b5b5c6”, “0x20cd572154d7f8a4c0bce658ca61401af65162e2”, “0x2143b2f528f6d010c14e4037f9636aad2e32768a”, “0x1a214b749386f914dc3c587123c4c4e33aa380a1”, “0x6769ec150d26b051ef645c3fb929e15a2014ac8b”, “0x15160f34374726050645a655477e5611368ce92d”, “0x7e8754c7fa01a343716f56696b2ad384574ce87b”, “0x00d05f6176afa7c1cfe45a5629e1eb0f6a5519b0”, “0xc1b24a9ecf68c14ffe65263b1591c29dd341d09d”, “0x194c948244c6fcdd5765a4d8ca4b9dae803e0ca5”, “0x065f8d3e2b5d196e85ab609baa7be1598959811a”, “0xa478c2975ab1ea89e8196811f51a7b7ade33eb11”, “0x55d5c232d921b9eaa6b37b5845e439acd04b4dba”, “0xe0076d311a4628516d157ad684dbd2ddada3dafe”, “0x12cc685eeb95d3fcdfae0a996e214e51fa6f7548”, “0xe8c6c9227491c0a8156a0106a0204d881bb7e531”, “0xb02045ad2ca16e8f4675088140e369260bb280c8”, “0xa66cdad5facbcbf74d9b60dcc8034c2a485e63ff”, “0x2a0330c7e979a4d18e5b0c987b877da24dd37d04”, “0x3e70f4ea78032037f3b07b2460e82ace6181e919”, “0x29c830864930c897efa2b9e9851342187b82010e”, “0x9192f112f9f448bb255a9f0e65d0e331580bd8e7”, “0xc7e6b676bfc73ae40bcc4577f22aab1682c691c6”, “0x0f8aae138a30578e40cb3f97887daa949f11f4c5”, “0xd101821c56b4405af4a376cbe81fa0dc90207dc2”, “0x127452f3f9cdc0389b0bf59ce6131aa3bd763598”, “0xa3317773c682f527f8e5680b42389ec30c09dcc6”, “0xeb1b2622e07bcf5362b6f735e182e54e9bc75ba8”, “0xdae6d9662c4904026ac311a5fdc8917fdc51971a”, “0x12eb818437ba482f1ee8dda2fb4bed939e44a92a”, “0x4c083084c9d50334b343c44ec97d16011303cc73”, “0xc4f1a21425cbd1565e7c62c7650cff252eb0ac06”, “0x3a0ef60e803aae8e94f741e7f61c7cbe9501e569”, “0x795065dcc9f64b5614c407a6efdc400da6221fb0”, “0x0d6bbad08799c94698bb4771b3113715cd51f630”, “0xcd423f3ab39a11ff1d9208b7d37df56e902c932b”, “0x223249c56c0f0329c3f0266c4e553f17cd181d85”, “0xed330afb7a12be60c03b3d5aefa99f6cb5560af0”, “0xc52a18e7358b1c618bd8f0e784b35636775afb4e”, “0xdac866a3796f85cb84a914d98faec052e3b5596d”, “0xd13c58a2493c7ac37b4b9d5a0f9827576bbfc0e0”, “0x2dfee82f4250dd3f3c6811c5d2926ede8b37a7d5”, “0x7df301c4529c58546527f5b912c74ecccad0ae2d”, “0x55f90670419af9fb1d8ae3587c77505f64c03a8c”, “0x6c063a6e8cd45869b5eb75291e65a3de298f3aa8”, “0xefdf4dfc4e817197851266acf0082a80dab18b24”, “0x025d43e199c6911d06979d0887e076f0ef00e359”, “0x948b54a93f5ad1df6b8bff6dc249d99ca2eca052”, “0xe47313c95a10d43dee011c54e29ad674425fef21”, “0xfb30c2edd3650ed4f2235c18a86331524d103a2c”, “0x2dbf62bb56a912289adc82ac1959b3a4477639ca”, “0x8f1b19622a888c53c8ee4f7d7b4dc8f574ff9068”, “0xb3485b0fc82ef1e663b20973095ea2c33c667894”, “0x8fb8e9921922d2ffb529a95d28a0d06d275d7a59”, “0x74d9360003cb55a01f01110055dc68dbd0282e27”, “0xa3f558aebaecaf0e11ca4b2199cc5ed341edfd74”, “0x2a182e532a379cb2c7f1b34ce3f76f3f7d3596f7”, “0x7b8ac38aacd8ebca19b3d423bcbbd4c5815bab49”, “0x290a6a7460b308ee3f19023d2d00de604bcf5b42”, “0xc9e17adb7c6a348e6c8f829aabe1930e019ac504”, “0x0c30062368eefb96bf3ade1218e685306b8e89fa”, “0xf602ca3e74a99962d135fbfd351c3d66808f0da5”, “0x8a70b86153d2293400df87ac328aa9b0304d7e90”, “0xb25651a3574931cda977c3a3c265f68cc1a106b2”, “0x2a9d2ba41aba912316d16742f259412b681898db”, “0xf2cf06455f6b62c2a22944486da5789355bdd3cb”, “0x9e31efffe1e016f514f774f43d91a85ebbc11564”, “0x7cedc8bf96378b3e48cb52b9548e8f82de46138f”, “0xdb1f3654e44ed1f95297ddaa152306a9fb492bdb”, “0x0ae8d75e6168420a7d52a791c2465b43307408b4”, “0xc09bf2b1bc8725903c509e8caeef9190857215a8”, “0x03e67a3a7775f80e49cc8fe004592c5bc8e2d273”, “0x3a815d399de8def3e0d315f9502f485476117a65”, “0x1921b852f38bc68430780242b2628d0ca14cef83”, “0x24ba219db5647a7c4d786d5451d0360336642887”, “0x6f41040b9e098c2ac4b88e27b50d4e9ab486781b”, “0xff69e625afbc72c32cc5afea994ac2b6aacf0338”, “0x0e2c4be9f3408e5b1ff631576d946eb8c224b5ed”, “0x4daeac8ea49c9770fa496e4de76f6d021557b22d”, “0x3a897f7ce0ad8d665a34a5d270de6c0be1a3dea9”, “0xc697051d1c6296c24ae3bcef39aca743861d9a81”, “0xd2b96ab4b5317f000b9d9b266355157ba0337071”, “0xbe19c32b4cd202407e8eeb73e4e2949438461ae3”, “0xcbcdf9626bc03e24f779434178a73a0b4bad62ed”, “0x063e913f23d2314d75962871b10eecf48c539046”, “0xede8dd046586d22625ae7ff2708f879ef7bdb8cf”, “0x94385268a526349ac18edf41c01878774133c164”, “0x59354356ec5d56306791873f567d61ebf11dfbd5”, “0x8b07f791efa8cd73923279dd3b80a60da98460a2”, “0xc2e9f25be6257c210d7adf0d4cd6e3e881ba25f8”, “0x30c91cfb847daf9a17db8e78de9082f15577de7e”, “0x4305776b118d144e6882c38ad85114e79a6a0bf3”, “0xd04d14d2f9122372e41d2de9a82f721e9ea2f069”, “0xc0a6bb3d31bb63033176edba7c48542d6b4e406d”, “0xccb63225a7b19dcf66717e4d40c9a72b39331d61”, “0xa3d64865004142aba7b315c9fa43a5c26d5115c2”, “0x23bc662119649a78a6aa132e043c01a34c982700”, “0x9c04560df8dff626555317ccc2c336b9c24fda41”, “0x35ec40bd9ae9179097f06ccbc0e9c3f2d051cc30”, “0x48d20b3e529fb3dd7d91293f80638df582ab2daa”, “0x77bbc2b409c2c75e4999e8e3eb8309efff37cf2d”, “0x4de126d4940bb9a183e9b692d7f7dd5abb2638c5”, “0x819f3450da6f110ba6ea52195b3beafa246062de”, “0x4a2987c255ad7f9409c54a4fce7823441e14f08b”, “0xc88deb1ce0bc4a4306b7f20be2abd28ad3a5c8d1”, “0xe05d099bfd7f4aa9f2e696f6c3ebe181479961a5”, “0xf6d109fab08e84a005f34e1f5f0a8c5a02d0d0e5”, “0x5241b5dc927e3c2ca99e2182ef1eb1a7803593ed”, “0xd6930be646d3a7e2e7ec96b1a4d55d7f14be6a7e”, “0xc3f279090a47e80990fe3a9c30d24cb117ef91a8”]})
{address balances(currency: { in: [“0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2”]}) {value}}}}

I would request the balances for all pools for a certain currency - always one currency and all the addresses. For certain currencies like ETH there are almost 2000 pools hence I had to divide it in 10 calls of 200 addresses otherwise you get a 413 as the return string is too long for the server to manage.

And this is it

@crazysailor Use v2 APIs, you get all pool data without mentioning the addresses

query MyQuery {
  EVM(dataset: combined, network: eth) {
    DEXTradeByTokens(
      where: {Trade: {Side: {Currency: {SmartContract: {is: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"}}}}, Block: {Date: {after: "2023-10-11", before: "2023-10-13"}}}
      limit: {count: 100}
      orderBy: {descending: Block_Date}
    ) {
      sum(of: Trade_Amount)
      Block {
        Date
      }
      Trade {
        Dex {
          Pair {
            Name
            Symbol
          }
          ProtocolName
        }
      }
    }
  }
}

sample response:

"Trade": {
          "Dex": {
            "Pair": {
              "Name": "Bico Balancer Pool Token",
              "Symbol": "BBPT"
            },
            "ProtocolName": "balancer_v2"
          }
        },
        "sum": "5594.995184988732301209"
      },
      {
        "Block": {
          "Date": "2023-10-12"
        },
        "Trade": {
          "Dex": {
            "Pair": {
              "Name": "Convergence LP Token",
              "Symbol": "CLP"
            },
            "ProtocolName": "uniswap_v2"
          }
        },
        "sum": "2164.813025"
      },
      {
        "Block": {
          "Date": "2023-10-12"
        },
        "Trade": {
          "Dex": {
            "Pair": {
              "Name": "Oats And Grains",
              "Symbol": "OG"
            },
            "ProtocolName": "balancer_v2"
          }
        },
        "sum": "367.047006"
      }, ....

Thanks, I’ll give it a go.

My question is, does the sum of Trade_Amount is the size of the pool? Meaning, how much money is tied up in the pool?

Also, is this number expressed in USD?

Thanks

the sum of trade_amount gives you liquidity. I will check how to get balances without mentioning pool addresses.

if you mention addresses, use Token Holder API, much simpler

@crazysailor Out of curiosity, what are trying to build?

I am working on a triangular arbitrage bot. The data returned by these queries will be used to calculate potential pairs to do the trades. Then I will execute a smart contract to do the 3 swaps - which I am currently developing.

this is the bit that is taking longer as I have very little experience with solidity - as opposed to Python and Javascript which I am more experienced.

Cheers

And apologies for my late reply, I’ve been focusing on the smart contract and haven’t done much work on this the last couple of weeks. Didn’t see your questions before