How to fetch real-time cryptocurrency price from Binance API in Node.js using WebSocket?
06:27 25 Mar 2026

I'm building a crypto exchange platform in Node.js and I want to fetch real-time BTC/USDT price using Binance WebSocket API.

I tried the REST API but it doesn't give live updates. I want the price to update automatically every second without polling.

**My current REST API approach (not real-time):**
```javascript
const axios = require('axios');

async function getBTCPrice() {
const response = await axios.get(
'https://api.binance.com/api/v3/ticker/price?symbol=BTCUSDT'
);
console.log('BTC Price:', response.data.price);
}

getBTCPrice();
```

**What I want:**
- Real-time price updates via WebSocket
- Reconnect automatically if connection drops
- Handle errors properly

**Environment:**
- Node.js v18
- axios 1.4.0
- ws package installed

What is the correct way to implement this?

node.js websocket cryptocurrency binance-api-client