Token Price in USD for Binance Smart Chain

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.

1 Like

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.

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
      
    }
  }
}
2 Likes

It worked. Thanks!!!

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

Explain how you calculated the price

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

Price is not wrong to check -14 notation

Screenshot 2021-05-20 at 9.37.00 PM

Have you have taken this into account?

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

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

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

Method of calculating and conversion in USD price

How do I calculate/convert in USD price?

From where you are comparing our data?

I calculated it manually based on Pancakeswap price.

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

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://poocoin.app/tokens/0xb6d053e260d410eac02ea28755696f90a8ecca2b

Both are our customers. They use our data.

1 Like

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

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.

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!

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.

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