Use this file to discover all available pages before exploring further.
Private WebSocket streams give your application real-time visibility into account-level events: order status changes, position updates, and asset balance changes. These channels require API credentials (apiKey, apiSecret, and apiMemo) because the library must authenticate the connection before the server will accept topic subscriptions.
Pass your API credentials to the WebsocketClient constructor. The library detects private topics automatically (topics containing user/, asset/, order, or position path components) and routes them to the correct authenticated connection.
Store credentials in environment variables, not in source code. The apiMemo is the memo you set when creating the API key on BitMart — it is part of the HMAC signature and is required for all private WebSocket operations.
Listen for authenticated to confirm the connection is ready to receive private data. This is especially useful for debugging or for triggering subsequent actions that depend on a confirmed authenticated session.
The authenticated event fires once per private WebSocket connection. Because connections are reused across all private topics for the same market, it fires at most once for spot private and once for futures private per session (or after each reconnect).
BitMart provides a simulated (paper) trading environment for futures v2. Enable it by adding demoTrading: true to the client options. The library will connect to the demo endpoints automatically:
Demo public v2: wss://openapi-wsdemo-v2.bitmart.com/api?protocol=1.1
Demo mode only affects v2 futures WebSocket connections. Spot private connections always use the live endpoint regardless of the demoTrading setting. API keys are the same across live and demo environments.
By default, the WebsocketClient uses its built-in logger which suppresses trace-level output. You can inject a custom logger as the second constructor argument to control log verbosity — for example to integrate with your application’s logging framework or to enable detailed trace output during development.
Enabling trace-level logging is the fastest way to diagnose connection or authentication issues. The library logs the raw outbound auth request (without the secret), the server’s response, and every topic subscription confirmation at the trace level.