Queries
The subgraph can be queried to retrieve important information about Uniswap, pairs, tokens, transactions, users, and more. This page will provide examples for common queries.
To try these queries and run your own visit the subgraph sandbox.
Global Data
To query global data you can pass in the Ring Factory address and select from available fields.
Global Stats
All time volume in USD, total liquidity in USD, all time transaction count.
{
uniswapFactory(id: "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f"){
totalVolumeUSD
totalLiquidityUSD
txCount
}
}
Global Historical lookup
To get a snapshot of past state, use The Graph's block query feature and query at a previous block. See this post to get more information about fetching block numbers from timestamps. This can be used to calculate things like 24hr volume.
{
uniswapFactory(id: "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f", block: {number: 10291203}){
totalVolumeUSD
totalLiquidityUSD
txCount
}
}
Pair Data
Pair Overview
Fetch a snapshot of the current state of the pair with common values. This example fetches the DAI/WETH pair.
{
pair(id: "0xa478c2975ab1ea89e8196811f51a7b7ade33eb11"){
token0 {
id
symbol
name
derivedETH
}
token1 {
id
symbol
name
derivedETH
}
reserve0
reserve1
reserveUSD
trackedReserveETH
token0Price
token1Price
volumeUSD
txCount
}
}
All pairs in Uniswap
The Graph limits entity return amounts to 1000 per query as of now. To get all pairs on Ring use a loop and graphql skip query to fetch multiple chunks of 1000 pairs. The query would look like this (where skip is some incrementing variable passed into your query).
{
query pairs($skip: Int!) {
pairs(first: 1000, skip: $skip) {
id
}
}
}