curl
, along with many other HTTP packages or GraphQL clients implemented in various programming languages. For the examples below, we will use the requests
package, a popular and user-friendly HTTP client library for Python.
We will write a Python function to query the subgraph. GraphQL queries are stored as separate files. You can find all the scripts and queries in the GitHub repository.
.env
) and paste your Chainstack endpoint URL there.
.env
).
.graphql
files in the Queries
folder. We will read each query file, execute it, and store its result in the Outputs
folder.
_meta
. Additionally, there is the deployment
field, which provides us with the unique identifier for the subgraph deployment. Append it to https://ipfsgw.com/ipfs/
to check the subgraph manifest content. hasIndexingErrors
indicates where there have been any indexing errors.
swaps
entity with a few parameters: first
to limit the response size, orderBy
and orderDirection
to sort swaps by time in descending order.
getPair
function of the UniswapV2 Factory Contract (no gas is needed). You can also query the subgraph using specific conditions, such as traded pairs with USDC (this will be covered later in the tutorial). Use where
to filter the results.
amountUSD
field. In the Explorer, we can see there is a special field for this called amountUSD_gte
. This field compares values to see if they are greater than or equal to a specified input.
token
entity with the argument id
(token address). Since prices are in ETH, we should also include ethPrice
from the bundles
entity.
tokenDayDatas
, which stores historical data sets for all tokens. Prices are in USD.
id
) since July 1, 2024 (hourStartUnix_gte
).
reserveUSD
in descending order.
createdAtBlockNumber
in descending order.
id
of the pair to get data for a specific pair. To find the largest positions, sort by liquidityTokenBalance
in descending order.
block
in descending order, filtering for a specific pair.
uniswapDayDatas
entity.