# Binance futures WebSocket streams in Node.js: mark price, candles and trades on the /market path

Binance serves USD-M futures market streams under a dedicated `/market` path. A raw connection to the older path still opens, but it carries no market data. As of 2 December 2026, `wss://fstream.binance.com/ws/btcusdt@markPrice@1s` delivered 0 messages in 8 seconds, while `wss://fstream.binance.com/market/ws/btcusdt@markPrice@1s` delivered 7. A futures bot that connects cleanly and then prints nothing is usually still on the old URL.

The script below subscribes to the BTCUSDT mark price, 1 minute candles and aggregated trades from Node.js with the [binance](https://github.com/sieblyio/binance) package, an open-source (MIT) Node.js and TypeScript SDK for the Binance REST APIs, WebSocket streams and WebSocket API.

## Install

```bash
npm install binance
```

Version 3.6.15 is current. Public market streams need no API key.

## Mark price, candles and aggregated trades

Save this as `stream.mjs`:

```js
import { WebsocketClient } from 'binance';

const ws = new WebsocketClient({ beautify: true });

ws.on('open', ({ wsKey }) => console.log('connected', wsKey));
ws.on('reconnected', ({ wsKey }) => console.log('reconnected', wsKey));
ws.on('exception', (err) => console.error('error', err));

ws.on('formattedMessage', (event) => {
  switch (event.eventType) {
    case 'markPriceUpdate':
      console.log('mark', event.symbol, event.markPrice, 'funding', event.fundingRate);
      break;
    case 'kline':
      console.log('kline', event.symbol, event.kline.interval, event.kline.close, 'final', event.kline.final);
      break;
    case 'aggTrade':
      console.log('aggTrade', event.symbol, event.price, event.quantity);
      break;
  }
});

ws.subscribe(
  ['btcusdt@markPrice@1s', 'btcusdt@kline_1m', 'btcusdt@aggTrade'],
  'usdm',
);
```

Run it with `node stream.mjs`. The first lines look like this:

```
connected usdmMarket
mark BTCUSDT 59176.94935507 funding 0.00008707
kline BTCUSDT 1m 59172.2 final false
aggTrade BTCUSDT 59172.2 0.002
```

Over 15 seconds, this subscription received 14 mark price updates, 33 candle updates and 220 aggregated trades for BTCUSDT. Trade counts depend on market activity.

## What each part does

- **Routing.** `'usdm'` is a product alias. The client sends market topics such as mark price, candles and aggregated trades to the `/market` connection, which is why the log line shows `usdmMarket`.
- **Typed fields.** With `beautify: true`, single letter keys become readable names (`p` becomes `markPrice`, `r` becomes `fundingRate`) and numeric strings become numbers. A mark price event also carries `indexPrice`, `settlePriceEstimate` and `nextFundingTime`.
- **Reconnects.** Binance closes every futures WebSocket connection after 24 hours. The client sends heartbeats, reconnects when a connection drops, resubscribes your topics and emits `reconnected`. Use that event to refetch recent candles or positions over REST, so you pick up anything that changed during the gap.
- **Closed candles.** `event.kline.final` is `true` only on the last update of each candle. Indicators that run on final candles match the exchange chart.

## More symbols and markets

- Add symbols by adding topics, for example `ethusdt@markPrice@1s` or `solusdt@kline_5m`.
- COIN-M futures use `'coinm'` as the second argument, with topics such as `btcusd_perp@markPrice@1s`.
- Spot streams use `'main'`, for example `btcusdt@trade`.
- Private account updates (orders, positions and balances) use the same client with an API key.

The Binance JavaScript tutorial covers REST calls, user data streams and the WebSocket API: https://siebly.io/sdk/binance/javascript/tutorial

The WebSocket guide in the docs lists every stream helper: https://sieblyio.github.io/docs/binance/guides/websockets.html

I help maintain the binance package (Siebly). Questions are welcome in the comments.

