---
title: "BitMart WebSocket Futures Private Example | Siebly"
description: "BitMart websocket futures private JavaScript example for the Siebly BitMart SDK, covering exchange REST API and WebSocket integration, setup, and production SDK docs."
canonical: "https://siebly.io/examples/Bitmart/Websocket/ws-futures-private"
robots: "index,follow"
---

# BitMart WebSocket Futures Private Example

BitMart websocket futures private JavaScript example for the Siebly BitMart SDK, covering exchange REST API and WebSocket integration, setup, and production SDK docs.

**Path:** [Home](/) / [Examples](/examples) / [Bitmart](/examples/Bitmart) / [Websocket](/examples/Bitmart/Websocket) / [ws-futures-private.ts](/examples/Bitmart/Websocket/ws-futures-private)

[View source on GitHub](https://github.com/sieblyio/crypto-api-examples/blob/master/examples/Bitmart/Websocket/ws-futures-private.ts)

[Open the BitMart JavaScript SDK guide](/sdk/bitmart/javascript)

## ws-futures-private.ts

```typescript
import { DefaultLogger, LogParams, WebsocketClient } from 'bitmart-api';

const account = {
  key: process.env.API_KEY || 'apiKeyHere',
  secret: process.env.API_SECRET || 'apiSecretHere',
  memo: process.env.API_MEMO || 'apiMemoHere',
};

DefaultLogger.trace = (...params: LogParams): void => {
  console.log('silly', ...params);
};

async function start() {
  const client = new WebsocketClient({
    apiKey: account.key,
    apiSecret: account.secret,
    apiMemo: account.memo,
  });

  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 reconnect
  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);
  });

  client.on('authenticated', (data) => {
    console.error('authenticated: ', data);
  });

  try {
    // Assets Channel
    client.subscribe(
      ['futures/asset:USDT', 'futures/asset:BTC', 'futures/asset:ETH'],
      'futures',
    );

    // Position Channel
    // client.subscribe('futures/position', 'futures');

    // Order Channel
    // client.subscribe('futures/order', 'futures');
  } catch (e) {
    console.error('Req error: ', e);
  }
}

start();
```
