# Token Price in USD for Binance Smart Chain

**URL:** <https://community.bitquery.io/t/token-price-in-usd-for-binance-smart-chain/44>\
**Category:** GraphQL API\
**Tags:** closed\
**Created:** [May 19, 2021, 5:36am UTC](https://community.bitquery.io/t/token-price-in-usd-for-binance-smart-chain/44 "2021-05-19T05:36:03Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![shikoku.exchange](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@shikoku.exchange](https://community.bitquery.io/u/shikoku.exchange)\
**Post date:** [May 19, 2021, 5:36am UTC](https://community.bitquery.io/t/token-price-in-usd-for-binance-smart-chain/44/1 "2021-05-19T05:36:03Z")

</div>

Hi

I am trying to get the USDT price of my BEP20 token and it returns null.  
This is the query I used to get the USDT value of my coin (SHIKO).  
So this is done as SHIKO - BNB - USDT(BinancePegged).

query ($baseAddress: String!,  
$quoteAddress: String!, $connector1: String!,  
$from: ISO8601DateTime!, $interval: Int){  
ethereum(network: bsc){  
dexTrades(  
any: [  
{  
baseCurrency: {is: $baseAddress}  
quoteCurrency: {is: $quoteAddress}},  
{  
baseCurrency: {is: $baseAddress}  
quoteCurrency: {is: $connector1}},  
{  
baseCurrency: {is: $connector1}  
quoteCurrency: {is: $quoteAddress}}  
]  
date: {since: $from}  
tradeAmountUsd: {gt: 10}  
){  
timeInterval {  
minute(format: “%FT%TZ”, count: $interval)  
}  
buyCurrency: baseCurrency {  
symbol  
address  
}  
buyAmount: baseAmount  
buyAmountInUsd: baseAmount  
sellCurrency: quoteCurrency {  
symbol  
address  
}  
sellAmountInUsd: quoteAmount  
tradeAmount(in: USD)  
volume: quoteAmount  
trades: count  
averageQuotePrice: quotePrice(calculate: average)  
}}  
}

This is the query variable I used.  
{“from”: “2021-02-25T18:05:00.000Z”,“interval”: 30,“baseAddress”:“0xb6d053e260d410eac02ea28755696f90a8ecca2b”,“quoteAddress”:“0x55d398326f99059ff775485246999027b3197955”,“connector1”:“0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c”,“minAmount”: 1000}

And here’s one item of the result array.

{  
“timeInterval”: {  
“minute”: “2021-02-25T00:00:00Z”  
},  
“buyCurrency”: {  
“symbol”: “WBNB”,  
“address”: “0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c”  
},  
“buyAmount”: 5317.599217978192,  
“buyAmountInUsd”: 5317.599217978192,  
“sellCurrency”: {  
“symbol”: “USDT”,  
“address”: “0x55d398326f99059ff775485246999027b3197955”  
},  
“sellAmountInUsd”: 1354400.9408832863,  
“tradeAmount”: 1312590.8162438706,  
“volume”: 1354400.9408832863,  
“trades”: 588,  
“averageQuotePrice”: 254.51960368421868  
},

As you can see, there’s no information about my token in the result. Only about the WBNB/USDT pair.  
Would you kindly let me know what I did wrong here?  
I’d really appreciate it.

---

<div class="post-metadata">

**Author:** ![gaurav](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@gaurav](https://community.bitquery.io/u/gaurav)\
**Post date:** [May 19, 2021, 6:33am UTC](https://community.bitquery.io/t/token-price-in-usd-for-binance-smart-chain/44/2 "2021-05-19T06:33:57Z")

</div>

This can be done in two ways,

1- Execute two API calls to get the latest trade of SHIKO/WBNB and WBNB/USDT pair and then calculate SHIKO’s USDT price.

2- Execute one API call to get the latest trade of SHIKO/WBNB and WBNB/USDT pairs latest trade

Now there are two ways to get this data, get the **median price of the latest trades**.

> **[Token's Price in USDT using WBNB as mediator](https://graphql.bitquery.io/ide/qjxA7GSlde)**
>
> Token's Price in USDT using WBNB as mediator

**Or get the latest trade itself**

```
{
  ethereum(network: bsc) {
    dexTrades(
      any: [{baseCurrency: {is: "0xb6d053e260d410eac02ea28755696f90a8ecca2b"}, quoteCurrency: {is: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"}}, {baseCurrency: {is: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"}, quoteCurrency: {is: "0xe9e7cea3dedca5984780bafc599bd69add087d56"}}]
      date: {since: "2021-05-19T18:05:00.000Z"}
      options: {desc: ["tradeIndex", "block.timestamp.time"], limitBy: {each: "baseCurrency.symbol", limit: 1}}
    ) {
      baseCurrency {
        symbol
        address
      }
      block {
        timestamp {
          time(format: "%Y-%m-%d %H:%M:%S")
        }
        height
      }
      tradeIndex
      buyAmount: baseAmount
      buyAmountInUsd: baseAmount
      quoteCurrency {
        symbol
        address
      }
      sellAmountInUsd: quoteAmount
      
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![shikoku.exchange](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@shikoku.exchange](https://community.bitquery.io/u/shikoku.exchange)\
**Post date:** [May 19, 2021, 12:10pm UTC](https://community.bitquery.io/t/token-price-in-usd-for-binance-smart-chain/44/3 "2021-05-19T12:10:15Z")

</div>

It worked. Thanks!!!

---

<div class="post-metadata">

**Author:** ![shikoku.exchange](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@shikoku.exchange](https://community.bitquery.io/u/shikoku.exchange)\
**Post date:** [May 19, 2021, 5:23pm UTC](https://community.bitquery.io/t/token-price-in-usd-for-binance-smart-chain/44/4 "2021-05-19T17:23:00Z")

</div>

Hi @gaurav

I compared the price (0.0000000000171671) I got from query (SHIKO-WBNB \* WBNB-USDT) with the manually calculated price from pancakeswap ($0.0000000000201663) during swap and those two are different a lot.

Would you let me know why this happens?

Thanks,

Shiko

---

<div class="post-metadata">

**Author:** ![gaurav](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@gaurav](https://community.bitquery.io/u/gaurav)\
**Post date:** [May 20, 2021, 2:12am UTC](https://community.bitquery.io/t/token-price-in-usd-for-binance-smart-chain/44/5 "2021-05-20T02:12:26Z")

</div>

Explain how you calculated the price

---

<div class="post-metadata">

**Author:** ![shikoku.exchange](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@shikoku.exchange](https://community.bitquery.io/u/shikoku.exchange)\
**Post date:** [May 20, 2021, 2:47am UTC](https://community.bitquery.io/t/token-price-in-usd-for-binance-smart-chain/44/6 "2021-05-20T02:47:36Z")

</div>

```
{
  ethereum(network: bsc) {
    dexTrades(
      any: [{baseCurrency: {is: "0xb6d053e260d410eac02ea28755696f90a8ecca2b"}, quoteCurrency: {is: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"}}, {baseCurrency: {is: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"}, quoteCurrency: {is: "0xe9e7cea3dedca5984780bafc599bd69add087d56"}}]
      date: {since: "2021-05-19T18:05:00.000Z"}
      options: {desc: ["tradeIndex", "block.timestamp.time"], limitBy: {each: "baseCurrency.symbol", limit: 1}}
    ) {
      timeInterval{
        second(count: 1)
      }
      baseCurrency {
        symbol
        address
      }
      block {
        timestamp {
          time(format: "%Y-%m-%d %H:%M:%S")
        }
        height
      }
      tradeIndex
      buyAmount: baseAmount
      buyAmountInUsd: baseAmount
      quoteCurrency {
        symbol
        address
      }
      sellAmountInUsd: quoteAmount
      tradeAmount(in: USD)
      volume: quoteAmount
      trades: count
      median: quotePrice (calculate: median)
      high: quotePrice(calculate: maximum)
      low: quotePrice(calculate: minimum)
      open: minimum(of: block, get: quote_price)
      close: maximum(of: block, get: quote_price)
    }
  }
}

```

I queried this and got two price pairs.  
SHIKO - WBNB and WBNB - BUSD.  
I multiplied two median values and got the result.

---

<div class="post-metadata">

**Author:** ![gaurav](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@gaurav](https://community.bitquery.io/u/gaurav)\
**Post date:** [May 20, 2021, 4:08pm UTC](https://community.bitquery.io/t/token-price-in-usd-for-binance-smart-chain/44/7 "2021-05-20T16:08:19Z")

</div>

Price is not wrong to check -14 notation

![Screenshot 2021-05-20 at 9.37.00 PM](https://us1.discourse-cdn.com/flex016/uploads/bitquery/original/1X/f9903f2934a9f54c918ca7d3fa38ce8e7eb07162.png)

Have you have taken this into account?

---

<div class="post-metadata">

**Author:** ![shikoku.exchange](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@shikoku.exchange](https://community.bitquery.io/u/shikoku.exchange)\
**Post date:** [May 20, 2021, 4:31pm UTC](https://community.bitquery.io/t/token-price-in-usd-for-binance-smart-chain/44/8 "2021-05-20T16:31:01Z")

</div>

Yes, that is of course considered. The difference is not 10^X big.  
From query calculation: 0.0000000000182926  
Actual current price is: 0.0000000000155745

---

<div class="post-metadata">

**Author:** ![gaurav](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@gaurav](https://community.bitquery.io/u/gaurav)\
**Post date:** [May 20, 2021, 4:57pm UTC](https://community.bitquery.io/t/token-price-in-usd-for-binance-smart-chain/44/9 "2021-05-20T16:57:15Z")

</div>

0.0000000000182926 - ia it USD? and where you are seeing this price?

There might be several reasons for this difference

We have a little delay in data check here - [https://bloxy.info/status](https://bloxy.info/status)

Additionally, WBNB and BUSD price is also a little different when we convert into USD.

Method of calculating and conversion in USD price

---

<div class="post-metadata">

**Author:** ![shikoku.exchange](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@shikoku.exchange](https://community.bitquery.io/u/shikoku.exchange)\
**Post date:** [May 20, 2021, 4:58pm UTC](https://community.bitquery.io/t/token-price-in-usd-for-binance-smart-chain/44/10 "2021-05-20T16:58:53Z")

</div>

How do I calculate/convert in USD price?

---

<div class="post-metadata">

**Author:** ![gaurav](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@gaurav](https://community.bitquery.io/u/gaurav)\
**Post date:** [May 20, 2021, 5:02pm UTC](https://community.bitquery.io/t/token-price-in-usd-for-binance-smart-chain/44/11 "2021-05-20T17:02:02Z")

</div>

From where you are comparing our data?

---

<div class="post-metadata">

**Author:** ![shikoku.exchange](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@shikoku.exchange](https://community.bitquery.io/u/shikoku.exchange)\
**Post date:** [May 20, 2021, 5:07pm UTC](https://community.bitquery.io/t/token-price-in-usd-for-binance-smart-chain/44/12 "2021-05-20T17:07:12Z")

</div>

I calculated it manually based on Pancakeswap price.

---

<div class="post-metadata">

**Author:** ![gaurav](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@gaurav](https://community.bitquery.io/u/gaurav)\
**Post date:** [May 20, 2021, 5:08pm UTC](https://community.bitquery.io/t/token-price-in-usd-for-binance-smart-chain/44/13 "2021-05-20T17:08:23Z")

</div>

Ok, let me check it with the dev team and come back to you.

---

<div class="post-metadata">

**Author:** ![shikoku.exchange](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@shikoku.exchange](https://community.bitquery.io/u/shikoku.exchange)\
**Post date:** [May 20, 2021, 5:12pm UTC](https://community.bitquery.io/t/token-price-in-usd-for-binance-smart-chain/44/14 "2021-05-20T17:12:57Z")

</div>

I also checked these two websites and those seems to be more close to pancakeswap price.  
[https://www.dextools.io/app/pancakeswap/pair-explorer/0xee78e0aa04a07a3a948b0ebc4c8966f6c1e748c7](https://www.dextools.io/app/pancakeswap/pair-explorer/0xee78e0aa04a07a3a948b0ebc4c8966f6c1e748c7)  
[https://poocoin.app/tokens/0xb6d053e260d410eac02ea28755696f90a8ecca2b](https://poocoin.app/tokens/0xb6d053e260d410eac02ea28755696f90a8ecca2b)

---

<div class="post-metadata">

**Author:** ![gaurav](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@gaurav](https://community.bitquery.io/u/gaurav)\
**Post date:** [May 21, 2021, 2:51am UTC](https://community.bitquery.io/t/token-price-in-usd-for-binance-smart-chain/44/15 "2021-05-21T02:51:44Z")

</div>

Both are our customers. They use our data.

---

<div class="post-metadata">

**Author:** ![shikoku.exchange](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@shikoku.exchange](https://community.bitquery.io/u/shikoku.exchange)\
**Post date:** [May 21, 2021, 3:04am UTC](https://community.bitquery.io/t/token-price-in-usd-for-binance-smart-chain/44/16 "2021-05-21T03:04:01Z")

</div>

Then what query do they use to get the actual price?  
I cannot get the same price they are showing up.

---

<div class="post-metadata">

**Author:** ![gaurav](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@gaurav](https://community.bitquery.io/u/gaurav)\
**Post date:** [May 21, 2021, 4:14am UTC](https://community.bitquery.io/t/token-price-in-usd-for-binance-smart-chain/44/17 "2021-05-21T04:14:41Z")

</div>

1- Both run their own node to get the latest data to cope up with our delay problem. So I believe you are checking real-time price and we are giving you a 1-3 mint delayed price, that’s why the difference.

For now, you have to use that, meanwhile, we are building a new real-time system which will be live next quarter, then this problem will be solved.

Also, i asked the tech team to look into this thread, I will let you know as soon as I get the answer.

---

<div class="post-metadata">

**Author:** ![shikoku.exchange](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@shikoku.exchange](https://community.bitquery.io/u/shikoku.exchange)\
**Post date:** [May 21, 2021, 4:47am UTC](https://community.bitquery.io/t/token-price-in-usd-for-binance-smart-chain/44/18 "2021-05-21T04:47:21Z")

</div>

Thank you so much!  
How do I run my own node? Any documentation?

That would be great to have a realtime system.  
Expecting to use it soon!

I look forward to your next reply!

---

<div class="post-metadata">

**Author:** ![sal05m4](https://avatars.discourse-cdn.com/v4/letter/s/b3f665/32.png) [@sal05m4](https://community.bitquery.io/u/sal05m4)\
**Post date:** [May 27, 2021, 11:55am UTC](https://community.bitquery.io/t/token-price-in-usd-for-binance-smart-chain/44/19 "2021-05-27T11:55:56Z")

</div>

Hey Gaurav. This code gives false values or maybe I am misunderstanding them

{  
ethereum(network: bsc) {  
dexTrades(  
any: [{baseCurrency: {is: “0x8076c74c5e3f5852037f31ff0093eeb8c8add8d3”}, quoteCurrency: {is: “0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c”}}, {baseCurrency: {is: “0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c”}, quoteCurrency: {is: “0xe9e7cea3dedca5984780bafc599bd69add087d56”}}]  
date: {since: “2021-05-19T18:05:00.000Z”}  
options: {desc: [“tradeIndex”, “block.timestamp.time”], limitBy: {each: “baseCurrency.symbol”, limit: 1}}  
) {  
timeInterval{  
second(count: 1)  
}  
baseCurrency {  
symbol  
address  
}  
block {  
timestamp {  
time(format: “%Y-%m-%d %H:%M:%S”)  
}  
height  
}  
tradeIndex  
buyAmount: baseAmount  
buyAmountInUsd: baseAmount  
quoteCurrency {  
symbol  
address  
}  
sellAmountInUsd: quoteAmount  
tradeAmount(in: USD)  
volume: quoteAmount  
trades: count  
median: quotePrice (calculate: median)  
high: quotePrice(calculate: maximum)  
low: quotePrice(calculate: minimum)  
open: minimum(of: block, get: quote\_price)  
close: maximum(of: block, get: quote\_price)  
}  
}  
}

\*\*“median”: 1.36874154598438e-8, \*\*  
**but on pancake the price is 0.00000498438**

**The median value is too far from actual price of token in poocoin and pancake.**

---

<div class="post-metadata">

**Author:** ![gaurav](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@gaurav](https://community.bitquery.io/u/gaurav)\
**Post date:** [May 27, 2021, 6:06pm UTC](https://community.bitquery.io/t/token-price-in-usd-for-binance-smart-chain/44/20 "2021-05-27T18:06:14Z")

</div>

can you tell me which token you are checking the price for?

[Next page](https://community.bitquery.io/t/token-price-in-usd-for-binance-smart-chain/44.md?page=2)
