Connection, Subscription & Heartbeat
Connection, Subscription & Heartbeat
Connect to 6MM WebSocket streams, subscribe to topics, keep connections alive, and process message envelopes safely.
Use WebSocket streams for market data and private user-state updates that must stay current without polling.
Connection URL
Private streams require authentication context such as a listenKey or access token as described in the private channel documentation.
Subscribe
Successful subscription acknowledgement:
Unsubscribe
Application ping
Message envelope
Public pushes use a consistent envelope:
Operational recommendations
- Generate a unique client-side
idfor every subscribe, unsubscribe, and ping request. - Treat reconnect as a new session and resubscribe to required topics.
- Validate that the returned
topicmatches 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
- Close or discard the previous socket and create a new connection.
- Re-authenticate private streams with a valid listenKey or access token.
- Resubscribe to every required topic and wait for successful acknowledgements.
- Replace local order-book state with a new snapshot before applying incremental updates.
- 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.
Related documentation
- Public Market Channels: topics, order-book continuity, trades, candles, and tickers.
- Private User Channel: listenKey lifecycle and authenticated events.
- Integration Recommendations: retries, idempotency, monitoring, and launch testing.