Search code examples
cryptoapicryptocurrencybinancebinance-api-client

How to get market-price using binance api


I'm not sure how to call this number in red-circle. I want to get it. I try to read restful api document & web-socket api from binance but response value doesn't contain this or maybe I miss somethings.

So how to get this number ? thank you.

enter image description here


Solution

  • The USD price of an asset is not part of the official Binance API, and it's based on a proprietary algorithm.

    If an approximate number is sufficient for you, you can:

    • Look for a USD stablecoin quote pair - ETH_BUSD, ETH_USDT (links to API endpoints). The exchangeInfo endpoint shows all active pairs so that you can filter ETH and search for other pairs manually.
    • For base assets that do not have pairs with USD stablecoins (for example EZ at the moment), you can find their price in BTC using the EZ_BTC param, and then convert this price to USD stablecoin using the BTC_USDT param.

    Mind that the price of USD stablecoins is not always exactly $1.00 and is usually fluctuating up to 0.5% around this number (so sometimes 1 USDT costs $0.995 and sometimes $1.005). That's why I'm highlighting the "approximate number" above.


    If you need more precise number and really get the USD (not the USD stablecoin) price, I'd recommend searching for unofficial APIs in the Network section of your browser devtools bar while browsing Binance. They might have an (unofficial) endpoint that shows the current price of USD stablecoins in USD, or even the current USD (not stablecoin) price of an asset such as ETH.

    Also the Coinmarketcap API offers USD price computed using a proprietary algorithm. But then these numbers from CMC might differ from the numbers displayed on Binance because they might be calculated using a different algorithm or from different inputs (including more exchanges, aggregated from a different time period, ...).