Introducing Uniswap V3 Protocol on ETH and BSC

We are now supporting the Uniswap V3 protocol on Etheruem and BSC.

On Ethereum we already have Uniswap v3, however, if any clone will be deployed on BSC, we will be able to parse them too and provide APIs for them.

Here are some of the sample GraphQL queries which would get you started with Uniswap V3 protocol.

Total Trade Volume with Uniswap V3 Protocol

The following query shows the total trade volume of the Uniswap V3 protocol

{
  ethereum(network: ethereum){
    dexTrades (protocol: {is: "Uniswap v3"}){
      count
      protocol
      tradeAmount(in: USD)
    }
  }
}

Monthly Total Trade Volume of Uniswap V3

{
  ethereum(network: ethereum){
    dexTrades(
      options: {asc: "date.month"}
      protocol: {is: "Uniswap v3"}
    ){
      count
      tradeAmount(in: USDT)
      protocol
      date{
        year 
        month
      }
    }
  }
}

Latest Trades on Uniswap V3 Protocol

The following query shows the latest trades for the Uniswap V3 protocol.

{
  ethereum(network: ethereum) {
    dexTrades(protocol: {is: "Uniswap v3"}, options: {limit: 5}) {
      protocol
      buyCurrency {
        symbol
        address
      }
      buyAmount
      sellCurrency {
        address
        symbol
      }
      sellAmount
      count
    }
  }
}

Latest Trades of a specific currency pair on Uniswap V3 Protocol

To get the latest trades of a specific currency pair for Uniswap V3 Protocol. Use the following query. Here, we are getting the latest trades for $BOOK-WETH currency pair on Uniswap V3 in this query.

Here we are passing 0x764d2866f0f77076e46c58fca07ca8a4200adac3 for buyCurrency which is the Bookie ($BOOK) token’s address. And, 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 for sellCurrency which is the Wrapped Ether (WETH) token’s address.

{
  ethereum(network: ethereum) {
    dexTrades(
      options: {limit: 3, desc: "block.height"}
      protocol: {is: "Uniswap v3"}
      buyCurrency: {is: "0x764d2866f0f77076e46c58fca07ca8a4200adac3"}
      sellCurrency: {is: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"}
    ) {
      block {
        height
        timestamp {
          iso8601
        }
      }
      transaction {
        hash
      }
      buyCurrency {
        address
        symbol
        name
      }
      buyAmount
      sellCurrency {
        address
        symbol
        name
      }
      sellAmount
      maker {
        address
        annotation
      }
      taker {
        address
        annotation
      }
      protocol
      tradeIndex
    }
  }
}

OHLC data for a currency pair on Uniswap V3 Protocol

Open-High-Low-Close data is used to create an OHLC chart, which illustrates movements in the price of an asset over time.

Using the following query, you can get the OHLC data for any currency pair for the Uniswap V3 protocol. In this query, we are getting the $DG-WETH currency pair’s OHLC data for a time interval of 5 minutes.

Here, we are passing 0xee06a81a695750e71a662b51066f2c74cf4478a0 for buyCurrency, which is a decentral.games ($DG) token’s address and 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 for sellCurrency, which is a Wrapped Ether (WETH) token’s address.

{
  ethereum(network: ethereum) {
    dexTrades(
      options: {limit: 5, asc: "timeInterval.minute"}
      protocol: {is: "Uniswap v3"}
      date: {is: "2021-07-01"}
      buyCurrency: {is: "0xee06a81a695750e71a662b51066f2c74cf4478a0"}
      sellCurrency: {is: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"}
    ) {
      timeInterval {
        minute(count: 5)
      }
      buyCurrency {
        address
        symbol
      }
      buyAmount
      sellAmount
      sellCurrency {
        address
        symbol
      }
      maximum_price: price(calculate: maximum)
      minimum_price: price(calculate: minimum)
      open_price: minimum(of: block, get: price)
      close_price: maximum(of: block, get: price)
    }
  }
}

Getting the baseAmount, quoteAmount & quotePrice of a Uniswap v3 Protocol token pair

Here, 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 is kept as the baseCurrency for WETH token address and 0xcae72a7a0fd9046cf6b165ca54c9e3a3872109e0 as the quoteCurrency for $ANRX token address. The following query returns the baseAmount and quoteAmount along with the quotePrice of that particular token pair in the Uniswap V3 protocol.

{
  ethereum(network: ethereum) {
    dexTrades(
      protocol: {is: "Uniswap v3"}
      baseCurrency: {is: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"}
      quoteCurrency: {is: "0xcae72a7a0fd9046cf6b165ca54c9e3a3872109e0"}
    ) {
      baseAmount(calculate: maximum)
      quoteAmount(calculate: maximum)
      protocol
      quotePrice(calculate: maximum)
      baseCurrency {
        symbol
        name
      }
      quoteCurrency {
        symbol
        name
      }
    }
  }
}