Cover Image for Price Index for DEX Tokens

Price Index for DEX Tokens

Dex

One of the major problems we see in DEX space is that many of the DEX assets do not have trading pairs with some popular DEX currencies such as USDT, WETH(Wrapped Ether), USDC, WBNB (Wrapped BNB), etc.

Or if they have pairs with WETH or WBNB, they do not have pairs with stablecoins such as USDT or USDC.

Besides, most of these pairs don’t have much trade data. Therefore calculating USD price against these unpopular assets is challenging, and if you are trying to create TradingView like charts, then life becomes hell.

Working with DEXs

We have seen this problem faced by many businesses trying to build DEX-related tools.

Today, we will show you how you can use our DEX APIs to get an asset price against any other asset, based on DEX trading data. After that, we will discuss how this same technique can be used to build DEX index pricing.

DEX Asset pricing based on intermediate Currency

In the following query, we will try to get the 1inch token’s price in USDT using WETH as an intermediary currency. In other words, we will use 1inch/WETH and WETH/USDT pair and calculate 1inch/USDT value for a given timeframe.

Once you run the query, you will see OHLC (Open, High, Low, Close) for both pairs (1inch/WETH and WETH/USDT) for a given timeframe. Now, if you multiply OHLC or 1inch/WETH pair and OHLC of WETH/USDT pair, you will get 1inch/USDT price for that timeframe. (Note: Multiply Open with Open price, Low with Low price, and so on).

To make this more interesting, you can avoid specific trades, use trade volume or average quote price, add weight based on currency pair or trade count, etc. Basically, to get a more stable price, you can build your own algorithm. Another way to through more intermediate currencies in the mix, as shown in this example.

query ($baseAddress: String!, 
  $quoteAddress: String!, $connector1: String!, $connector2: String!, 
  $from: ISO8601DateTime!, $interval: Int) {
  ethereum(network: ethereum) {
    dexTrades(
      any: [
      			{	
              baseCurrency: {is: $baseAddress}
      				quoteCurrency: {is: $quoteAddress}
            },
            {	
              baseCurrency: {is: $baseAddress}
      				quoteCurrency: {is: $connector1}
            },
            {	
              baseCurrency: {is: $baseAddress}
      				quoteCurrency: {is: $connector2}
            },
            {	
              baseCurrency: {is: $connector1}
      				quoteCurrency: {is: $quoteAddress}
            },
            {	
              baseCurrency: {is: $connector2}
      				quoteCurrency: {is: $quoteAddress}
            },
    		]
      
      date: {since: $from}
      tradeAmountUsd: {gt: 10}
    ) {
      timeInterval {
        minute(format: "%FT%TZ", count: $interval)
      }
      buyCurrency: baseCurrency {
        symbol
        address
      }
      buyAmount: baseAmount
      buyAmountInUsd: baseAmount(in: USD)
      sellCurrency: quoteCurrency {
        symbol
        address
      }
      sellAmountInUsd: quoteAmount(in: USD)
      tradeAmount(in: USD)
      volume: quoteAmount
      trades: count
      high: quotePrice(calculate: maximum)
      low: quotePrice(calculate: minimum)
      open: minimum(of: block, get: quote_price)
      close: maximum(of: block, get: quote_price)
    }
  }
}
{
  "from": "2021-02-25T18:05:00.000Z",
  "interval": 30,
  "baseAddress": "0x111111111117dc0aa78b770fa6a738034120c302",
  "quoteAddress": "0xdac17f958d2ee523a2206206994597c13d831ec7",
  "connector1": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
  "connector2": "ETH",
  "minAmount": 1000
}

DEX Price Index

As we mentioned above, there are many tokens with are not listed on centralized exchanges. Therefore price discovery for those coins is still a huge problem in the DEX space. Using the above method, you can drive the price index. For example, in the following query, we are using the average quote price to get the price of 1inch/USDT pair using WETH as an intermediary asset.

In the following query results, if we multiply averageQuotePrice of 1inch/WETH pair with averageQuotePrice of WETH/1inch pair, we will get the 1inch/USDT pair price.

As mentioned above, to make this price index more robust, you can build your algorithm by using extra data we are giving, such as multiplying averageQuotePrice with trading volume or quote volume to normalize the data. You can avoid trades less than a specific size etc. ​

We are in the process of building a DEX price index, and if you are interested in it, please contact us at sales@bitquery.io or join our Telegram channel.

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 sales@bitquery.io. Also, subscribe to our newsletter below, we will keep you updated with the latest in the cryptocurrency world.

Subscribe to our newsletter

Subscribe and never miss any updates related to our APIs, new developments & latest news etc. Our newsletter is sent once a week on Monday.