Search code examples
apicryptographytokenuniswap

How to use TokenDayData in Uniswap


I am using uniswap v2 subgraph to get data. TokenDayData lets you search historically. I'm trying to query historical data for a token with this query:

{
  tokenDayData(id: "0x56143e2736c1b7f8a7d8c74707777850b46ac9af-19086.058842592593") {
    token {
      id
    }
  }
}

and getting the response:

  "data": {
    "tokenDayData": null
  }

How can I get real data?


Solution

  • I was just trying this myself and got this to work:

    {
      tokenDayDatas(
          where: {
            token: "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984",
            date_gt: 1661717376
          }, 
          orderBy: date, 
          orderDirection: asc) {
        date
        token {
          id
          symbol
        }
        volumeUSD,
        untrackedVolumeUSD,
        priceUSD,
        open,
        high,
        low,
        close
      }
    }
    

    some of the examples here helped: https://docs.uniswap.org/sdk/subgraph/subgraph-examples

    looks like you're using "tokenDayData" (which is what I used initially), but notice the working query uses "tokenDayDatas" (which is odd, but whatever)