Use SDK WebSocket helpers when you want reconnection handling, message typing, and subscription state in application code.Documentation Index
Fetch the complete documentation index at: https://docs.0xarchive.io/llms.txt
Use this file to discover all available pages before exploring further.
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 treatingconnect() as the whole workflow.
Replay And Gap Callbacks
Historical replay data arrives through replay-specific callbacks, not through the same live subscription callbacks.SDK Event Packet
SDK helpers may wrap raw WebSocket messages, but the underlying event model still matters.| Event class | What to preserve |
|---|---|
| Connection | open time, close code, close reason, retry count, and active subscriptions |
| Live data | channel, symbol, venue family, timestamp, and latest applied state |
| Replay start | channel or channels, symbol, start, end, speed, and output destination |
| Replay snapshots | replay_snapshot baseline before historical_data messages |
| Replay data | timestamp, channel, symbol, and emitted order |
| Gaps | gap_detected interval, duration, affected output, and rebuild decision |
| Terminal state | replay_completed, replay_stopped, retry budget exhausted, or consumer stopped |
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.| Workflow | Example helper |
|---|---|
| Hyperliquid core order book | ws.subscribeOrderbook("BTC") |
| Live trades | ws.subscribeTrades("ETH") |
| HIP-4 outcome market | ws.subscribeHip4("hip4_orderbook", "0") |
| Spot pair | ws.subscribeSpot("orderbook", "HYPE-USDC") |
| Replay | ws.replay("orderbook", "BTC", { start, end, speed }) |
Review Rule
WebSocket helper examples should never end atconsole.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.