How to display token price quote when charting?

Hi there,

Let’s say I’ve run the following query to get a quote (in WBNB) for a token;

{
  ethereum(network: bsc) {
    dexTrades(
      options: {desc: ["block.height", "tradeIndex"], limit: 1}
      exchangeName: {in: ["Pancake v2"]}
      baseCurrency: {is: "0x2eba09fb8063aedba27424de9bf0dcb41567a943"}
      quoteCurrency: {is: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"}
      height: {is: 9942312}
    ) {
      transaction {
        hash
      }
      tradeIndex
      smartContract {
        address {
          address
        }
        contractType
        currency {
          name
        }
      }
      tradeIndex
      block {
        timestamp {
          time(format: "%Y-%m-%d %H:%M:%S")
          unixtime
        }
        height
      }
      baseCurrency {
        symbol
        address
      }
      quoteCurrency {
        symbol
        address
      }
      quotePrice
    }
  }
}

The quote result is "quotePrice": 4.726269578406308e-16

How would I go about formatting this response to display properly when charting?

eg.

Bonus question: How can I convert that result into a BigNumber to work with in web3 or ethers given it would throw an underflow error?

Many thanks

Were you following this tutorial?

If yes, then in the ./components/api/index.js file, you must have seen that a query like this is used to find the baseCurrency value which is injected into the symbol object and later, in the getBars method (which is responsible for the loading of the chart).

Thanks @sayon, I may have jumped the gun a bit as i didn’t understand how the charts were formatting the numbers. I’m not using Tradingview just yet so was curious how to format the amount using vanilla JS. I was able to write a function that parses the amount from Bitquery and returns it in the same format as the charts. Thanks again

1 Like