如何从 GraphQL 中获取 100 多个结果

时间:2021-06-05 22:37:46

标签: python json python-requests graphql

我正在尝试使用 GraphQL 为 Uniswap 2.0 上的每个令牌对接收令牌对数据。当我运行我的代码时,我只得到 100 个结果,但我需要检索 1800 多个结果。我已经更改了几次查询,但无论我如何更改它,100 对的数据似乎总是有上限。如何获取所有对的数据?


import requests

query = """{
  pairs(orderBy: reserveUSD, orderDirection: asc) {
    id
    token0 {
      id
      symbol
      totalLiquidity
      totalSupply
    }
    token1 {
      id
      symbol
      totalLiquidity
      totalSupply
    }
    reserveUSD
    reserve0
    reserve1
    totalSupply
    volumeUSD
  }
}"""

url = 'https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2'
r = requests.post(url, json = {"query": query})#"{\n  pairs(first: 10, where: {reserveUSD_gt: \"1000000\", volumeUSD_gt: \"50000\"}, orderBy: reserveUSD, orderDirection: desc) {\n    id\n    token0 {\n      id\n      symbol\n    }\n    token1 {\n      id\n      symbol\n    }\n    reserveUSD\n    volumeUSD\n  }\n}\n","variables":None}) 
#print(r.text)
json_data = json.loads(r.text)
print(len(json_data['data']['pairs']))

0 个答案:

没有答案
相关问题