loading...

Ethereum DEX GraphQL APIs with Examples

coinmonks profile image CoinMonks Originally published at bitquery.io on ・6 min read

We are now supporting Ethereum DEX trading data on our GraphQL APIs. You can get DEX trades, OHLC, trading volume, and other DEX related data for more than 18 Ethereum DEX protocols such as Uniswap, Balancer, Kyber, 0x, IDEX, etc.

Before we show some examples, here are a few important things to note:

  • GraphQL is an API query language, read this create your first GraphQL query.
  • Read this to learn how to call GraphQL queries as APIs programmatically.
  • GraphQL queries are highly flexible; therefore, you can change the following queries based on your needs or create a new one by following our GrpahQL schema (Available on our playground.)
  • You can test the following GraphQL queries on our Playground.
  • Our GraphQL endpoint is — https://graphql.bitquery.io/
  • Our GraphQL APIs support more than 20 blockchains. Check out our blog to see more examples.
  • You can also check DEX data on our blockchain explorer, here, here, and here.

Top DEX Protocols

The following query returns top DEX protocols based on the number of trades.

View this gist on GitHub

Result

{
  "data": {
    "ethereum": {
      "dexTrades": [
        {
          "protocol": "Uniswap v2",
          "started": "2020-05-05",
          "trades": 24836192
        },
        {
          "protocol": "IDEX",
          "started": "2017-09-27",
          "trades": 11819652
        },
        {
          "protocol": "EtherDelta",
          "started": "2016-07-09",
          "trades": 7441188
        },
        {
          "protocol": "Uniswap",
          "started": "2018-10-27",
          "trades": 4011690
        },
        {
          "protocol": "Zerox Exchange v2",
          "started": "2018-09-18",
          "trades": 2437436
        },
        ...
        ...
        ...
Enter fullscreen mode Exit fullscreen mode

Latest trades on a DEX Protocol

The following query shows how to get the latest trades for any DEX protocol. In this query, we are using the “Uniswap V2” protocol as an example.

View this gist on GitHub

Result

{
  "data": {
    "ethereum": {
      "dexTrades": [
        {
          "protocol": "Uniswap v2",
          "buyCurrency": {
            "symbol": "USDT",
            "address": "0xdac17f958d2ee523a2206206994597c13d831ec7"
          },
          "buyAmount": 1842158918.313746,
          "sellCurrency": {
            "symbol": "WETH",
            "address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
          },
          "sellAmount": 4977863.830826052,
          "trades": 379716
        },
        {
          "protocol": "Uniswap v2",
          "buyCurrency": {
            "symbol": "WETH",
            "address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
          },
          "buyAmount": 4920992.445139087,
          "sellCurrency": {
            "symbol": "USDT",
            "address": "0xdac17f958d2ee523a2206206994597c13d831ec7"
          },
          "sellAmount": 1831207530.946584,
          "trades": 368346
        },
        ...
        ...
        ...
Enter fullscreen mode Exit fullscreen mode

Latest trades of a specific currency pair on a DEX protocol

Now, if you want the latest trades for a specific currency pair, use the following query. We are getting the latest trade for USDT — WETH currency pair on Uniswap protocol (V2) in this query.

As you can see, you need to pass the smart contract address for the tokens to get the latest trades for them.

Here we are passing 0xdac17f958d2ee523a2206206994597c13d831ec7 for buyCurrency which is the USDT token’s address. And, 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 for sellCurrency which is the WETH token’s address.

View this gist on GitHub

Result

{
  "data": {
    "ethereum": {
      "dexTrades": [
        {
          "block": {
            "height": 11067734,
            "timestamp": {
              "iso8601": "2020-10-16T15:21:58Z"
            }
          },
          "transaction": {
            "hash": "0xa71a2c54355fb04b93d891a0750d4006238d8960da19db39e33d15c43debe08b"
          },
          "tradeIndex": "8",
          "buyCurrency": {
            "symbol": "USDT",
            "address": "0xdac17f958d2ee523a2206206994597c13d831ec7"
          },
          "buyAmount": 472.192504,
          "sellCurrency": {
            "symbol": "WETH",
            "address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
          },
          "sellAmount": 1.2889359336599604,
          "maker": {
            "address": "0x7a250d5630b4cf539739df2c5dacb4c659f2488d",
            "annotation": "Router 2, Uniswap, Router"
          },
          "taker": {
            "address": "0x0b7ded783106803dc03197028d26c86e548910a5",
            "annotation": null
          },
          "protocol": "Uniswap v2",
          "smartContract": {
            "address": {
              "address": "0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852",
              "annotation": null
            },
            "contractType": "DEX"
          }
        },
       ...
       ...
       ...
Enter fullscreen mode Exit fullscreen mode

OHLC data for currency pair on DEX

Open-high-low-close(also OHLC ) data used to create an OHLC chart, which illustrates movements in the price of a financial instrument over time.

Using the following query, you can get the OHLC data for any currency pair for any DEX protocol.

In this query, we are getting USDT-WETH currency pair’s OHLC data for 5 minutes interval.

We support the following time interval units.

  • second
  • minute
  • hour
  • day
  • month
  • year

Using the above units, you can create any type of chart candles. For example

  • 5-minute interval
timeInterval {
        minute(count: 5)
}
Enter fullscreen mode Exit fullscreen mode
  • 1-day interval
timeInterval {
        day(count: 1)
}
Enter fullscreen mode Exit fullscreen mode

Here is the query to get 5-minute OHLC data for the USDT-WETH currency pair on Uniswap protocol.

View this gist on GitHub

Result

{
  "data": {
    "ethereum": {
      "dexTrades": [
        {
          "timeInterval": {
            "minute": "2020-10-10 00:00:00"
          },
          "buyCurrency": {
            "symbol": "USDT",
            "address": "0xdac17f958d2ee523a2206206994597c13d831ec7"
          },
          "buyAmount": 15094.490436,
          "sellCurrency": {
            "symbol": "WETH",
            "address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
          },
          "sellAmount": 41.44903367094046,
          "trades": 15,
          "maximum_price": 0.002746776341103444,
          "minimum_price": 0.002737048849470252,
          "open_price": "0.002738970885840717",
          "close_price": "0.002746681535948033"
        },
        {
          "timeInterval": {
            "minute": "2020-10-10 00:05:00"
          },
          "buyCurrency": {
            "symbol": "USDT",
            "address": "0xdac17f958d2ee523a2206206994597c13d831ec7"
          },
          "buyAmount": 20978.805418,
          "sellCurrency": {
            "symbol": "WETH",
            "address": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
          },
          "sellAmount": 57.611814558084596,
          "trades": 25,
          "maximum_price": 0.002746774536198633,
          "minimum_price": 0.002738320503436713,
          "open_price": "0.002739092079021605",
          "close_price": "0.002746774536198633"
        },
        ...
        ...
        ...
Enter fullscreen mode Exit fullscreen mode

Monthly DEX trading volume for a specific Token

The following query gives us aggregated trading volume for a specific token on all DEX protocols. For example, in the query below, we are getting the trading volume for USDT token on all DEXs.

Note: We are passing the USDT token’s contract address, 0xdac17f958d2ee523a2206206994597c13d831ec7 to get the data in the query below. Our queries do not recognize token names. They only recognize smart contract addresses. So if you want to get trading volume for any other token, use the contract address for that token.

View this gist on GitHub

Result

{
  "data": {
    "ethereum": {
      "dexTrades": [
        {
          "date": {
            "date": "2018-08"
          },
          "amount": 195789.099416,
          "currency": {
            "symbol": "USDT"
          }
        },
        {
          "date": {
            "date": "2018-09"
          },
          "amount": 304211.822172,
          "currency": {
            "symbol": "USDT"
          }
        },
        ...
        ...
        ...
Enter fullscreen mode Exit fullscreen mode

If you have any questions or need help with your blockchain investigation, just hop on our Telegram channel. Also, let us know if you are looking for blockchain data APIs.

You might also be interested in:

About Bitquery

Bitquery is a set of software tools that parse, index, access, search, and use information across blockchain networks in a unified way. Our products are:

  • Coinpath® APIs provide blockchain money flow analysis for more than 24 blockchains. With Coinpath’s APIs, you can monitor blockchain transactions, investigate crypto crimes such as bitcoin money laundering, and create crypto forensics tools. Read this to get started with Coinpath®.

  • Digital Assets API provides index information related to all major cryptocurrencies, coins, and tokens.

  • DEX API provides real-time deposits and transactions, trades, and other related data on different DEX protocols like Uniswap, Kyber Network, Airswap, Matching Network, etc.

If you have any questions about our products, ask them on our Telegram channel or email us at hello@bitquery.io. Also, subscribe to our newsletter below, we will keep you updated with the latest in the cryptocurrency world.

The post Ethereum DEX GraphQL APIs with Examples appeared first on Bitquery.

Discussion

pic
Editor guide