# Queries Related to a Token

**URL:** <https://community.bitquery.io/t/queries-related-to-a-token/357>\
**Category:** GraphQL Tutorials\
**Tags:** token\
**Created:** [July 29, 2021, 10:58am UTC](https://community.bitquery.io/t/queries-related-to-a-token/357 "2021-07-29T10:58:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sayon](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@sayon](https://community.bitquery.io/u/sayon)\
**Post date:** [July 29, 2021, 10:58am UTC](https://community.bitquery.io/t/queries-related-to-a-token/357/1 "2021-07-29T10:58:50Z")

</div>

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

```auto
{
  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 Price of a Token pair - Blockchain Data API](https://ide.bitquery.io/m2VnLTBlnY)**
>
> Bitquery is analytical engine for blockchains

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

```auto
{
  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:

> **[Latest Trades of a Token pair - Blockchain Data API](https://ide.bitquery.io/aMQkt5IaUV)**
>
> Bitquery is analytical engine for blockchains

# Exchanges on which the Token is Available

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

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

```

source:

> **[Exchanges on which a token is available - Blockchain Data API](https://ide.bitquery.io/3kLOoCdaow)**
>
> Bitquery is analytical engine for blockchains

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

```auto
{
  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:

> **[Trade Volume and Count month on month - Blockchain Data API](https://ide.bitquery.io/LLSD4mpZHX)**
>
> Bitquery is analytical engine for blockchains

# Token Price in USD

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

```auto
{
  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:

> **[Price of a Token in USD - Blockchain Data API](https://ide.bitquery.io/iu2GJrjXDC)**
>
> Bitquery is analytical engine for blockchains

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

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

```

source:

> **[Getting the total supply of a coin via Address API - Blockchain Data API](https://ide.bitquery.io/HDFuI26Lnw)**
>
> Bitquery is analytical engine for blockchains

> Step-2: **Getting the latest price**

```auto
{
  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:

> **[Getting Latest Price - Blockchain Data API](https://ide.bitquery.io/97Q84GKtpZ)**
>
> Bitquery is analytical engine for blockchains

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

```auto
{
  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:

> **[Different Pools for a token on a given exchange - Blockchain Data API](https://ide.bitquery.io/OjvNdfoTqK)**
>
> Bitquery is analytical engine for blockchains

# Token’s Top 10 Trades based on Amount

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

```auto
{
  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:

> **[Top-10 Token Trades based on Amount - Blockchain Data API](https://ide.bitquery.io/pG0Fry2rUo)**
>
> Bitquery is analytical engine for blockchains

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

```auto
{
  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:

> **[Top-10 Token Transfers based on Amount - Blockchain Data API](https://ide.bitquery.io/D44bPS2h8y)**
>
> Bitquery is analytical engine for blockchains

# Token’s Basic Attributes

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

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

```

source:

> **[Token's basic info - Blockchain Data API](https://ide.bitquery.io/UNhMy654UN)**
>
> Bitquery is analytical engine for blockchains
