diff --git a/sdks/binance/docs/guides/websockets.md b/sdks/binance/docs/guides/websockets.md index 0dd3b8f2..ca4f42ac 100644 --- a/sdks/binance/docs/guides/websockets.md +++ b/sdks/binance/docs/guides/websockets.md @@ -1,6 +1,6 @@ --- title: "Binance WebSocket streams in the SDK" -description: "Subscribe to Binance WebSocket streams in the SDK for live tickers, depth and trades. Reconnects are handled by the SDK. JavaScript examples." +description: "Subscribe to Binance WebSocket streams in the SDK for live Spot and USD-M futures tickers, klines, depth and trades. Reconnects and futures stream routes are handled by the SDK. JavaScript examples." --- # Binance WebSocket streams in the SDK {#websocket-subscriptions} @@ -13,6 +13,23 @@ Save this as `stream.ts` in a TypeScript project. It prints updates for 30 secon <<< @/../examples/stream.ts +## USD-M futures streams + +Pass the `usdm` key to subscribe to Binance Futures WebSocket streams. Binance serves USD-M market streams such as klines, mark price and liquidations on the `/market` route of `wss://fstream.binance.com`, and depth on the `/public` route. The SDK picks the route for each topic and opens the connections it needs: + +```ts +import { WebsocketClient } from 'binance'; + +const ws = new WebsocketClient({}); + +ws.on('message', (message) => console.log(message)); +ws.on('exception', (error) => console.error('WebSocket exception', error)); + +ws.subscribe(['btcusdt@markPrice', 'btcusdt@kline_1m', 'btcusdt@depth5'], 'usdm'); +``` + +Use `coinm` for COIN-M futures. If a raw socket on `wss://fstream.binance.com/ws` connects but kline or markPrice updates never arrive, see [troubleshooting](/guides/troubleshooting). + ## Optional: readable fields with the SDK beautifier For descriptive field names and parsed numeric values, enable the SDK beautifier. In the example above, replace the client constructor and raw `message` listener with: