Ethereum DEX GraphQL APIs with Examples
Tags: product, tutorial, bitqueryapis
Published: 2020-10-29 15:25:50

---
title: Ethereum DEX GraphQL APIs with Examples
published: true
date: 2020-10-16 15:50:00 UTC
tags: Product,Tutorial,bitqueryapis
canonical_url: https://bitquery.io/blog/ethereum-dex-graphql-api?utm_source=rss&utm_medium=rss&utm_campaign=ethereum-dex-graphql-api
---

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](https://bitquery.io/blog/blockchain-graphql-query).
- Read [this](https://bitquery.io/blog/graphql-with-python-javascript-and-ruby) 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](https://graphql.bitquery.io/).)
- You can **test the following GraphQL queries** on our [**Playground**](https://graphql.bitquery.io/).
- Our GraphQL endpoint is — [https://graphql.bitquery.io/](https://graphql.bitquery.io/)
- Our GraphQL APIs support more than 20 blockchains. Check out our [blog](https://bitquery.io/blog) to see more examples.
- You can also check DEX data on our [blockchain explorer](https://explorer.bitquery.io/), [here](https://explorer.bitquery.io/ethereum/dex), [here](https://explorer.bitquery.io/ethereum/dex_trades), and [here](https://explorer.bitquery.io/ethereum/dex_tokens). 

## Top DEX Protocols

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

<script src="https://gist.github.com/buddies2705/f2c416a8d32aaebc9ccf552a2dcd6e7b.js"></script><noscript><a href="https://gist.github.com/buddies2705/f2c416a8d32aaebc9ccf552a2dcd6e7b">View this gist on GitHub</a></noscript>

### 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
        },
        ...
        ...
        ...
```

## **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.

<script src="https://gist.github.com/buddies2705/15e393b561c3503315ee40b5d58c9e58.js"></script><noscript><a href="https://gist.github.com/buddies2705/15e393b561c3503315ee40b5d58c9e58">View this gist on GitHub</a></noscript>

### 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
        },
        ...
        ...
        ...
```

## 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.

<script src="https://gist.github.com/buddies2705/9c8cf66f6863b3d72f1ead0d70a75cd9.js"></script><noscript><a href="https://gist.github.com/buddies2705/9c8cf66f6863b3d72f1ead0d70a75cd9">View this gist on GitHub</a></noscript>

### 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"
          }
        },
       ...
       ...
       ...
```

## OHLC data for currency pair on DEX

[**Open-high-low-close**](https://en.wikipedia.org/wiki/Open-high-low-close_chart)(also **OHLC** ) data used to create an OHLC chart, which illustrates movements in the price of a [financial instrument](https://en.wikipedia.org/wiki/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)
}
```

- 1-day interval 

```
timeInterval {
        day(count: 1)
}
```

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

<script src="https://gist.github.com/buddies2705/0cfed972b7317f73e3ac58ac35a87801.js"></script><noscript><a href="https://gist.github.com/buddies2705/0cfed972b7317f73e3ac58ac35a87801">View this gist on GitHub</a></noscript>

### 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"
        },
        ...
        ...
        ...
```

## **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.

<script src="https://gist.github.com/buddies2705/7c2b6a293d80e83c1e11ff8e92efe4b6.js"></script><noscript><a href="https://gist.github.com/buddies2705/7c2b6a293d80e83c1e11ff8e92efe4b6">View this gist on GitHub</a></noscript>

### Result

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

If you have any questions or need help with your blockchain investigation, just hop on our [Telegram channel](https://t.me/Bloxy_info). Also, let us know if you are looking for blockchain data APIs.

You might also be interested in:

- [Create your first Blockchain GraphQL query](https://bitquery.io/blog/blockchain-graphql-query)
- [API to get Ethereum Smart Contract Events](https://bitquery.io/blog/ethereum-events-api)
- [Why GraphQL is better for blockchain data APIs](https://bitquery.io/blog/blockchain-graphql)
- [APIs to get Latest Uniswap Pair Listing](https://bitquery.io/blog/uniswap-pool-api)
- [Simple rest APIs to get Uniswap data (DEX Data APIs)](https://bitquery.io/blog/dex-data-apis)
- [API to Get Ethereum Token Balance](https://bitquery.io/blog/etheruem-token-api)
- [Simple API To Get Ethereum Supply And Data](https://bitquery.io/blog/get-ethereum-total-supply)
- [How to investigate an Ethereum address?](https://bitquery.io/blog/investigate-ethereum-address)
- [Who is actually using Ethereum?](https://bitquery.io/blog/who-is-actually-using-ethereum)
- [How to get newly created Ethereum Tokens?](https://bitquery.io/blog/newly-created-etheruem-token)
- [Querying Binance Smart Chain (BSC)](https://bitquery.io/blog/binance-smart-chain-api)

#### **About** Bitquery

[**Bitquery**](https://bitquery.io/?source=blog&utm_medium=about_coinpath) 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®](https://bitquery.io/products/coinpath?utm_source=blog) APIs** provide [blockchain money flow analysis](https://blog.bitquery.io/coinpath-blockchain-money-flow-apis) 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®](https://blog.bitquery.io/coinpath-api-get-start).

- **[Digital Assets API](https://bitquery.io/products/digital_assets?utm_source=blog&utm_medium=about)** provides index information related to all major cryptocurrencies, coins, and tokens. 

- **[DEX API](https://bitquery.io/products/dex?utm_source=blog&utm_medium=about)** 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](https://t.me/Bloxy_info) or email us at [hello@bitquery.io](mailto: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](https://bitquery.io/blog/ethereum-dex-graphql-api) appeared first on [Bitquery](https://bitquery.io).