BitMart TypeScript SDK example: ws-futures-public.ts
BitMart WebSocket websocket futures public example for the Siebly BitMart SDK, with TypeScript source for exchange REST API and WebSocket integration, setup, and production SDK docs.
What This Example Covers
- BitMart WebSocket stream example in TypeScript.
- Uses the Siebly BitMart SDK package
bitmart-apiinstead of hand-written WebSocket plumbing. - Source path:
Bitmart/Websocket/ws-futures-public.ts. - Example category: WebSocket.
- Imports SDK symbols including
WebsocketClient. - Calls SDK methods such as
on(),subscribe().
How To Use This Example
- Start here for the specific request or stream pattern, then check the matching SDK guide for install, credentials, and operational notes.
- For WebSocket examples, keep reconnect, resubscribe, heartbeat, and event-handler behavior explicit in your service.
- Open the repository source when you need the latest committed version: GitHub source file.
Example Path
Bitmart/Websocket/ws-futures-public.ts
Source Link
Repository source: https://github.com/sieblyio/crypto-api-examples/blob/master/examples/Bitmart/Websocket/ws-futures-public.ts
Related SDK Docs
Example Source
import { WebsocketClient } from 'bitmart-api';
async function start() {
const client = new WebsocketClient();
client.on('open', (data) => {
console.log('connected ', data?.wsKey);
});
// Data received
client.on('update', (data) => {
console.info('data received: ', JSON.stringify(data));
});
// Something happened, attempting to reconenct
client.on('reconnect', (data) => {
console.log('reconnect: ', data);
});
// Reconnect successful
client.on('reconnected', (data) => {
console.log('reconnected: ', data);
});
// Connection closed. If unexpected, expect reconnect -> reconnected.
client.on('close', (data) => {
console.error('close: ', data);
});
// Reply to a request, e.g. "subscribe"/"unsubscribe"/"authenticate"
client.on('response', (data) => {
console.info('response: ', data);
});
client.on('exception', (data) => {
console.error('exception: ', data);
});
try {
// Ticker Channel
// client.subscribe('futures/ticker', 'futures');
// Depth Channel
// client.subscribe('futures/depth20:BTCUSDT', 'futures');
// Trade Channel
// client.subscribe('futures/trade:BTCUSDT', 'futures');
// KlineBin Channel
// client.subscribe('futures/klineBin1m:BTCUSDT', 'futures');
// Or have multiple topics in one array:
client.subscribe(
[
'futures/klineBin1m:BTCUSDT',
'futures/klineBin1m:ETHUSDT',
'futures/klineBin1m:XRPUSDT',
'futures/klineBin1m:BMXUSDT',
'futures/klineBin1m:SOLUSDT',
],
'futures',
);
} catch (e) {
console.error('Req error: ', e);
}
}
start();