DEV Community

loading...

Daily Price data from uniswap via subgraph (TheGraph)

hhatto profile image Hideo Hattori ・1 min read

daily data

# thegraph.sh
curl -v \
  -X POST "https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2" \
  -H "Content-Type: application/json" \
  -d \
'{"query": "{tokenDayDatas(first: 3, orderBy: date, orderDirection: desc, where: { token: \"0x5caf454ba92e6f2c929df14667ee360ed9fd5b26\"}) { id date token { id symbol } priceUSD } }",
  "variables":null
}'
$ sh ./thegraph.sh | jq
{
  "data": {
    "tokenDayDatas": [
      {
        "date": 1600819200,
        "id": "0x5caf454ba92e6f2c929df14667ee360ed9fd5b26-18528",
        "priceUSD": "2.806800389425393983069918593327176",
        "token": {
          "id": "0x5caf454ba92e6f2c929df14667ee360ed9fd5b26",
          "symbol": "DEV"
        }
      },
      {
        "date": 1600732800,
        "id": "0x5caf454ba92e6f2c929df14667ee360ed9fd5b26-18527",
        "priceUSD": "3.03633060835788742357890476280017",
        "token": {
          "id": "0x5caf454ba92e6f2c929df14667ee360ed9fd5b26",
          "symbol": "DEV"
        }
      },
      {
        "date": 1600646400,
        "id": "0x5caf454ba92e6f2c929df14667ee360ed9fd5b26-18526",
        "priceUSD": "3.233086904554954033846620475375757",
        "token": {
          "id": "0x5caf454ba92e6f2c929df14667ee360ed9fd5b26",
          "symbol": "DEV"
        }
      }
    ]
  }
}

update: 2020.09.24

semi-realtime data

ETH-USD price

$ curl -X POST "https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2" -H "Content-Type: application/json" -d \
'{"query": "{bundle(id: 1) { id ethPrice } }",
  "variables":null
}'
{"data":{"bundle":{"ethPrice":"338.9406833562309124607125730378295","id":"1"}}}

DEV-ETH price

$ curl -X POST "https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2" -H "Content-Type: application/json" -d \
'{"query": "{token(id: \"0x5caf454ba92e6f2c929df14667ee360ed9fd5b26\") { id derivedETH } }",
  "variables":null
}'
{"data":{"token":{"derivedETH":"0.008128160843209088915463402585521696","id":"0x5caf454ba92e6f2c929df14667ee360ed9fd5b26"}}}

Discussion (0)

pic
Editor guide