How to get current BTC price in USD using the websocket?

Hi, I am new to Binance API.

What I am trying is that to make my React.js web application display the real-time BTC price in USD.

const ws = new WebSocket('wss://');

I was using the line of code to open the WebSocket, and want to get the BTC price in USD, not USDT. But when I tried it with ‘btcusd’, it does not return any information at all. I have been Googling for this for a long time and could not find anything helpful.

My current code returns something like 0.089 as a ‘p’ value, which represents ‘price’ as shown in the official documentation: link, while the Binance website says that the BTC price is around 48,000 USD now.

I tried to get the Ethereum price by using the following line of code for a test:

const ws = new WebSocket('wss://');

And it returns the right information.

How can I get the BTC price in USD?

And, can anyone help me where I can find information regarding symbols I can use for the Binance API, especially for the WebSocket? I could not find it even I read the official documentation.

Thank you!

BTCUSD is not a valid trading pair (symbol), so you can’t rely on websocket to return updates on it.
There’s no direct way to get an asset’s price in USD, you’ll need to get in USDT or BUSD first and then locally find their price in USD equivalent.

Note: BTCEUR exists, you can check all symbols by querying /api/v3/exchangeInfo

1 Like

Hi, thank you so much for your help.

So, I will need to use another API for the exchange rate and calculate with the info that the Binance API provides, right?

@Auclown Not sure what you mean by “exchange rate” but if it’s BUST to USD using some API found online that ables you to do it, then sounds right. :slight_smile:

1 Like

@aisling Yes, that’s what I meant! Thank you so much!