Get BNB price in USD

Hey.

Is it possible to get the BNB price in USD with Moralis?

All I can find is how to get a specific token price, but not the chain asset price (BNB).

this code will get that price using wbnb (wrapped BNB token)

 x = await Moralis.Web3API.token.getTokenPrice({address: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c", chain: "bsc"})
1 Like

Great. Thanks a lot.

Hi,

getTokenPrice has some kind of delay when it returns data compared to the real time price ?

Thanks,
Regards,

it gets the price from latest block, what you you mean by real time price?

I mean if i call: await Moralis.Web3API.token.getTokenPrice({address: “0x68e374f856bf25468d365e539b700b648bf94b67”, chain: “bsc” }), i get a price token that it doesn’t match with value in poocoin or coingecko:
https://poocoin.app/tokens/0x68e374f856bf25468d365e539b700b648bf94b67
That’s why i asked if there is a delay or there is a way to obtain latest price …

Thanks,

you get that price based on a liquidity pool on bsc, the price will change every few seconds, and other services may get prices from different places

Be aware that the price in coin tracking sites such as CMC or Coingecko are not the same as the one got from DEX’s Liquidity Pools :raised_hands:

I’m afraid i’m losing something… if i use Pancakeswap as exchange to get a price token:

await Moralis.Web3API.token.getTokenPrice({address: “0x68e374f856bf25468d365e539b700b648bf94b67”, chain: “bsc”, exchange: “pancakeswap-v2” })

, should not i get same price by its page? https://pancakeswap.finance/swap
Where does it take price the nMoralis function?
Is it same source that OneInch plugin ?(Moralis.Plugins.oneInch.swap)
I’m a bit confused…

Thanks,

the price could change fast from block to block, pancakes swap also has multiple versions, there can also be multiple liquidity pools for same token

what is the difference that you see?

In this case (and other tokens as well) price never changed along hours when i called getTokenPrice function (in Pancake.com did), so it mades me ask myself if it was working correctly or there was another way to get price…
Moralis.Plugins.oneInch.swap uses same tokens prices than Moralis.Web3API.token.getTokenPrice ?

Thanks,

That price should change frequently if there is a well known token that gets transactions frequently. 1Inch may get the price differently.

You can look at that liquidity pair on pancake swap to see how frequently is makes transactions.