Connection, Subscription & Heartbeat

Connect to 6MM WebSocket streams, subscribe to topics, keep connections alive, and process message envelopes safely.
View as Markdown

Use WebSocket streams for market data and private user-state updates that must stay current without polling.

Connection URL

wss://ws.6mm.com/ws

Private streams require authentication context such as a listenKey or access token as described in the private channel documentation.

Subscribe

1{ "id": "1772007814666", "op": "subscribe", "args": ["market.depth.BTCUSDT"] }

Successful subscription acknowledgement:

1{
2 "id": "1772007814666",
3 "event": "subscribe",
4 "success": true,
5 "data": ["market.depth.BTCUSDT"]
6}

Unsubscribe

1{ "id": "1772007814667", "op": "unsubscribe", "args": ["market.depth.BTCUSDT"] }

Application ping

1{ "id": "1772007814668", "op": "ping", "args": [] }

Message envelope

Public pushes use a consistent envelope:

1{
2 "topic": "market.depth.BTCUSDT",
3 "event": "data",
4 "ts": 1772007815000,
5 "data": {}
6}

Operational recommendations

  • Generate a unique client-side id for every subscribe, unsubscribe, and ping request.
  • Treat reconnect as a new session and resubscribe to required topics.
  • Validate that the returned topic matches the channel your service expects.
  • Keep message processing idempotent where private order or account events are involved.
  • Log connection state changes, subscription acknowledgements, and abnormal disconnects.

Reconnect workflow

  1. Close or discard the previous socket and create a new connection.
  2. Re-authenticate private streams with a valid listenKey or access token.
  3. Resubscribe to every required topic and wait for successful acknowledgements.
  4. Replace local order-book state with a new snapshot before applying incremental updates.
  5. Reconcile open orders, positions, and balances through REST if private events may have been missed.

Use bounded exponential backoff with jitter for reconnect attempts. A continuously reconnecting client should alert operators instead of retrying indefinitely without visibility.

Heartbeat and stale connections

  • Track the most recent inbound message and successful ping acknowledgement.
  • Use the heartbeat interval and idle threshold approved for the production environment.
  • Treat a connection as stale when the configured threshold is exceeded, even if the TCP socket still appears open.
  • Do not reuse subscriptions from an old socket; resubscribe explicitly after every reconnect.