Queries Related to a Token

Latest Price of a Token

The following is a GraphQL query to get the latest price of a token pair with 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c as the baseCurrency and 0xe9e7cea3dedca5984780bafc599bd69add087d56 as the quoteCurrency.

{
  ethereum(network: bsc) {
    dexTrades(
      baseCurrency: {is: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"}
      quoteCurrency: {is: "0xe9e7cea3dedca5984780bafc599bd69add087d56"}
      date: {since: "2021-07-29"}
    ) {
      date{
        date(format: "%Y-%m-%d")
      }
      baseCurrency {
        symbol

      }
      quoteCurrency {
        symbol

      }
      quotePrice
    }
  }
}

source:

Latest Trades of a Token

The following GraphQL query generates the latest trade details of a Token pair. In our query, 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c has been set as the baseCurrency and 0xe9e7cea3dedca5984780bafc599bd69add087d56 as the quoteCurrency.
Trade details include the tradeIndex, the protocol in which the trade takes place, the transaction hash and the buyAmount & sellAmount along with their respective currencies.

{
  ethereum(network: bsc) {
    dexTrades(
      options: {limit: 100, desc: ["block.timestamp.time"]}
      baseCurrency: {is: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"}
      quoteCurrency: {is: "0xe9e7cea3dedca5984780bafc599bd69add087d56"}
      date: {since: "2021-07-29"}
    ) {
      block{
        height
        timestamp{
          time(format: "%Y-%m-%d %H:%M:%S")
        }
      }
      tradeIndex
      protocol
      buyAmount
      buyCurrency {
        address
        symbol
      }
      sellAmount
      sellCurrency {
        address
        symbol
      }
      transaction {
        hash
      }
    }
  }
}

source:

Exchanges on which the Token is Available

The following query generates the names of various exchanges the token pair is available in.

{
  ethereum(network: bsc) {
    dexTrades(
      baseCurrency: {is: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"}
      quoteCurrency: {is: "0xe9e7cea3dedca5984780bafc599bd69add087d56"}
    ) {
      exchange {
        fullName
      }
      count
    }
  }
}

source:

Trade Volume and count, month on month

In the following GraphQL query, the trade volume and count has been queried since the beginning of 2021, month-wise. 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c is kept as the baseCurrency while 0xe9e7cea3dedca5984780bafc599bd69add087d56 as the quoteCurrency. The quoteAmount along with the unique smart contract count has been queried.

{
  ethereum(network: bsc) {
    dexTrades(
      options: {asc: "date.month"}
      baseCurrency: {is: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"}
      quoteCurrency: {is: "0xe9e7cea3dedca5984780bafc599bd69add087d56"}
      date: {since: "2021-01-01"}
    ) {
      date {
        month
        year
      }
      trades_count: count
      baseCurrency {
        symbol
      }
      tradeAmount
      smartcontracts_count: count(uniq: smart_contracts)
    }
  }
}

source:

Token Price in USD

In the following query, we are generating the quoteAmount and tradeAmount of a token pair in USD.

{
  ethereum(network: bsc) {
    dexTrades(
      baseCurrency: {is: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"} 
      quoteCurrency: {is: "0xe9e7cea3dedca5984780bafc599bd69add087d56"}
      date: {since: "2021-01-01"}
    ) {
      baseCurrency {
        symbol
      }
      quoteCurrency {
        symbol
      }
      quoteAmount_USD: quoteAmount(in: USD)
      tradeAmount_USD: tradeAmount(in: USD)
    }
  }
}

source:

Last 24 hour Volume of Token’s Market Cap

Obtaining the Market Cap of a token is a 2 step process.

Step-1: Getting the Total Supply of the coin

To get the total supply, you can use our Address APIs to get the smart contract attributes as shown below.

{
  ethereum {
    address(address: {is: "0x514910771af9ca656af840dff83e8264ecf986ca"}) {
      annotation
      address
      smartContract {
        contractType
        attributes {
          name
          value
        }
        currency {
          symbol
          name
          decimals
          tokenType
        }
      }
      balance
    }
  }
}

source:

Step-2: Getting the latest price

{
  ethereum(network: bsc) {
    dexTrades(
      options: {desc: ["block.height","tradeIndex"], limit: 10}
      exchangeName: {in: ["Pancake", "Pancake v2"]}
      baseCurrency: {is: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"}
      quoteCurrency: {is: "0xe9e7cea3dedca5984780bafc599bd69add087d56"}
      date: {after: "2021-07-28"}
    ) {
      transaction {
        hash
      }
      tradeIndex
      smartContract {
        address {
          address
        }
        contractType
        currency {
          name
        }
      }
      tradeIndex
      block {
        height
      }
      baseCurrency {
        symbol
        address
      }
      quoteCurrency {
        symbol
        address
      }
      quotePrice
   
    }
  }
}

source:

Considering the fact that this article was written on 29/07/2021, so accordingly in the above query, the results generated, refer to the one’s after 28/07/2021 and hence meets the 24-hour criteria.

Different Pools for a token on a given exchange

In the following GraphQL query, we will be generating the different pools for a token based on its trades & tradeAmount.

{
  ethereum(network: bsc) {
    dexTrades(
      quoteCurrency: {is: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"}
      options: {desc: ["tradeAmount","trades"] limit: 100}
      date: {after: "2021-06-01"}
    ) {
      poolToken: smartContract {
        address {
          address
        }
      }
      exchange {
        fullName
      }
      pair:baseCurrency {
        symbol
        address
        name
      }
      trades: count
      tradeAmount(in: USD)
    }
  }
}

source:

Token’s Top 10 Trades based on Amount

The following query generates the Top-10 trades of a token pair based on the amount.

{
  ethereum(network: bsc) {
    dexTrades(
      options: {limit: 10, desc: ["sellAmount", "buyAmount"]}
      baseCurrency: {is: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"}
      quoteCurrency: {is: "0xe9e7cea3dedca5984780bafc599bd69add087d56"}
      date: {since: "2021-07-28"}
    ) {
      block{
        height
        timestamp{
          time(format: "%Y-%m-%d %H:%M:%S")
        }
      }
      tradeIndex
      protocol
      buyAmount
      buyCurrency {
        address
        symbol
      }
      sellAmount
      sellCurrency {
        address
        symbol
      }
      transaction {
        hash
      }
    }
  }
}

source:

Token’s Top 10 Transfers by Amount

In the following query, we are generating the top-10 transfers of a token by the amount. The transfer details include the sender address, receiver address, transaction hash & the amount.

{
  ethereum(network: bsc) {
    transfers(options: {desc: "amount", limit: 10}, date: {since: "2021-07-29", till: null}, currency: {is: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"}) {
      sender {
        address
      }
      receiver {
        address
      }
      transaction {
        hash
      }
      amount
      currency {
        symbol
      }
      external
    }
  }
}

source:

Token’s Basic Attributes

In the following query, the basic attributes like the token name, symbol, token id, etc. are being queried.

{
  ethereum(network: bsc) {
    address(address: {is: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"}) {
      annotation
      address
      smartContract {
        contractType
        currency {
          symbol
          name
          decimals
          tokenType
        }
      }
      balance
    }
  }
}

source: