如何从GraphQL获得100多个结果

2024-09-28 01:33:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用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']))

Tags: 数据idjsondatasymbolqueryrequestspairs
1条回答
网友
1楼 · 发布于 2024-09-28 01:33:59

我想你最多可以查询1000个结果。只需要将"first"添加到查询中。如果有1000个以上的结果,那么首先执行查询#1,然后运行第二个查询,您可以使用skip函数跳过已经得到的1000个结果

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

相关问题 更多 >

    热门问题