Use this file to discover all available pages before exploring further.
The BitMart SDK routes all spot WebSocket subscriptions through a single WebsocketClient. Public topics — tickers, depth, klines, and trades — connect automatically without credentials. Private topics (orders and balances) require your API key, secret, and memo and are authenticated at connection time. All spot topics use the 'spot' market identifier in the subscribe() call, and data arrives on the 'update' event.
The WebsocketClient automatically manages connection lifecycle: reconnections, heartbeats, and re-subscriptions after a disconnect are all handled transparently. You do not need to re-call subscribe() after a network interruption.
Real-time best bid/ask and 24 h statistics for a symbol
spot/depth5:{symbol}
Order book snapshot — top 5 bid and ask levels
spot/depth20:{symbol}
Order book snapshot — top 20 bid and ask levels
spot/depth50:{symbol}
Order book snapshot — top 50 bid and ask levels
spot/kline1m:{symbol}
1-minute candlestick (OHLCV)
spot/kline3m:{symbol}
3-minute candlestick
spot/kline5m:{symbol}
5-minute candlestick
spot/kline15m:{symbol}
15-minute candlestick
spot/kline30m:{symbol}
30-minute candlestick
spot/kline1H:{symbol}
1-hour candlestick
spot/kline2H:{symbol}
2-hour candlestick
spot/kline4H:{symbol}
4-hour candlestick
spot/kline1D:{symbol}
1-day candlestick
spot/kline1W:{symbol}
1-week candlestick
spot/trade:{symbol}
Real-time trade feed
The {symbol} placeholder uses the underscore format, e.g. BTC_USDT, ETH_USDT. This differs from the futures market, which uses no separator (e.g. BTCUSDT).
Choose the depth level that suits your use case — depth5 is suitable for most simple strategies, while depth50 gives a fuller picture of market liquidity.
Private topics deliver account-specific events. The WebsocketClient automatically authenticates the private WebSocket connection when credentials are provided during instantiation — you do not need to call any login method manually.
Private topics will silently fail to deliver data if the WebsocketClient was not instantiated with apiKey, apiSecret, and apiMemo. Check the authenticated event to confirm the connection is authenticated before assuming data will flow.
All incoming WebSocket messages emit on the 'update' event. The data.table field identifies which topic the message belongs to, allowing you to fan out events in a single handler.
import { WebsocketClient } from 'bitmart-api';const client = new WebsocketClient({ apiKey: process.env.API_KEY!, apiSecret: process.env.API_SECRET!, apiMemo: process.env.API_MEMO!,});client.on('update', (data) => { switch (data.table) { case 'spot/ticker': console.log('Ticker update:', data.data); break; case 'spot/depth5': console.log('Depth update:', data.data); break; case 'spot/trade': console.log('Trade update:', data.data); break; case 'spot/user/order': console.log('Order update:', data.data); break; case 'spot/user/balance': console.log('Balance update:', data.data); break; default: console.log('Unknown topic:', data.table, data.data); }});// Subscribe to a mix of public and private topicsclient.subscribe( [ 'spot/ticker:BTC_USDT', 'spot/depth5:BTC_USDT', 'spot/trade:BTC_USDT', ], 'spot',);client.subscribe('spot/user/order:BTC_USDT', 'spot');client.subscribe('spot/user/balance:BALANCE_UPDATE', 'spot');
Use unsubscribe() with the same topic strings and market to remove a subscription. The topic is removed from the internal cache and will not be re-subscribed after a reconnect.
// Unsubscribe from a single topicclient.unsubscribe('spot/ticker:BTC_USDT', 'spot');// Unsubscribe from multiple topics at onceclient.unsubscribe( ['spot/kline1m:BTC_USDT', 'spot/depth5:BTC_USDT'], 'spot',);