Skip to main content
Use SDK WebSocket helpers when you want reconnection handling, message typing, and subscription state in application code.
Python

Connection

Raw WebSocket connection pattern.

Replay

Historical playback commands and gap handling.

SDK Responsibilities

An SDK WebSocket helper should reduce boilerplate without hiding stream risk. The caller still needs to know when the socket opened, which channels are active, whether a replay is running, and whether a gap or reconnect made local state unsafe. Use helpers for connection setup, subscription state, typed messages, and reconnection. Keep application-level policy in your code: whether to pause, resync, rebuild a book, retry a replay window, or mark output incomplete. That separation keeps market-data correctness visible in code review.

Connection Contract

Use connection callbacks to record stream state instead of treating connect() as the whole workflow.
Track active subscriptions, latest message time, reconnect count, and unsafe symbols in application state. SDK reconnect behavior can restore transport, but the app still decides whether a local book, alert, or replay output is safe after a close or gap.

Replay And Gap Callbacks

Historical replay data arrives through replay-specific callbacks, not through the same live subscription callbacks.
Store replay channel, symbol, start, end, speed, gap callbacks, and output destination with the result. Use WebSocket replay when the event sequence is the product requirement.

SDK Event Checklist

SDK helpers may wrap raw WebSocket messages, but the underlying event model still matters. If the SDK only exposes higher-level callbacks, attach this checklist in the application logs or result manifest.

Testing A Stream

Test with one channel and one symbol before widening. Confirm open, message, close, reconnect, unsubscribe, and gap paths. For replay, store the input window and speed with the output. For live streams, store the first snapshot timestamp and the latest applied update timestamp.

Subscription Methods

Keep helper names tied to venue family. If a helper does not cover a route family, fall back to the raw WebSocket docs or REST/OpenAPI until the package exposes that route family.

Review Rule

WebSocket helper examples should never end at console.log. They should explain what happens after the message arrives: update UI state, append to a replay output, apply a book diff, mark a gap, or trigger a resync. Pair helpers with tests that simulate close, reconnect, replay snapshots, historical data, gap messages, and terminal replay events. A stream helper should show how the application behaves when history is incomplete, a socket closes, a replay pauses, or a resync starts.
Last modified on August 13, 2026