Getting token related data such as Marketcap, price, volume, price change

We will try to get the following data for a token -

Price
Marketcap
Volume
Volume 24h
Circulating supply
1H % Change
24H Change
7D Change
No. of Holders

Price
To get the price you need to get the latest trade for a given token. Following is the query example for that.

Marketcap
To get the market cap you need total supply and price. (Latest Price * Total Circulating Supply = Current market cap)

we can provide you with supply parameters through our APIs. however, circulating supply depends on many things and direct APIs can’t provide it.

API to get a supply of a token - Getting the total supply of a coin via Address API

Use the above query to get the latest price.

Total trading Volume

{
  ethereum(network: ethereum) {
    dexTrades(baseCurrency: {is: "0xf4d2888d29d722226fafa5d9b24f9164c092421e"}) {
      tradeAmount(in: USDT)
    }
  }
}

“Volume 24H”

check this post Volumn and count per hour, minute or days or week

{
  ethereum(network: ethereum) {
    dexTrades(baseCurrency: {is: "0xf4d2888d29d722226fafa5d9b24f9164c092421e"}
    time: {since: "2022-01-18T00:00:00" till: "2022-01-18T23:59:59"}
    ) {
      tradeAmount(in: USDT)
    }
  }
}

Price change 1 hour
To get the price change you need to know how to get the price at a certain time, use this query to accomplish that. (price at certain point)

Based on this you can use get a price change for 1hour, day or 7 days.

Here is the article that will help you further:

Hitting multiple queries using Aliasing.

You can use aliasing to query multiple data in one API call, read the following article for that.

No. of Holders

The number of holder APIs are not yet released at the time of writing this (19 Jan), it will be live soon.

You can ask more questions at our Telegram.

1 Like

Update

How to calculate the marketcap of a token ?

Market capitalization = Latest token price * Total supply

Above, we have already shown how to get the USD price of an asset; now, let’s get the supply.

Query to get supply

Total supply = Initial Supply + Minted supply - Burned supply

In the following query, we will get the initial supply from the contract attributed and then use transfer API to get mint and burns by checking how many tokens were sent or received from the dead address.

Open this query on IDE.

{
  ethereum(network: bsc) {
    address(address: {is: "0x20f663cea80face82acdfa3aae6862d246ce0333"}) {
      annotation
      address
      smartContract {
        attributes {
          name
          value
        }
        contractType
        currency {
          symbol
          name
          decimals
          tokenType
        }
      }
    }
    transfers(date: {since: null, till: null}, amount: {gt: 0}) {
      minted: amount(
        calculate: sum
        sender: {is: "0x0000000000000000000000000000000000000000"}
      )
      burned: amount(
        calculate: sum
        receiver: {is: "0x0000000000000000000000000000000000000000"}
      )
      currency(currency: {is: "0x20f663cea80face82acdfa3aae6862d246ce0333"}) {
        symbol
        name
      }
    }
  }
}

Note: In many cases token attributes shown as null in those cases you should find other ways to get supply of the token.

Read more in docs here Blockchain Streaming API (V2 Graphql Docs) | Streaming API (V2 API Docs)