Reconnect Strategy
WebSocket clients must assume that disconnects happen. Correct recovery is more important than a long-lived connection.
Reconnect loop
Use exponential backoff with jitter:
| Attempt | Delay |
|---|---|
| 1 | 250 ms |
| 2 | 500 ms |
| 3 | 1 s |
| 4 | 2 s |
| 5+ | Cap at 5 s with jitter |
Respect server-provided retry guidance on rate limits or maintenance windows.
Public stream recovery
For market data:
- Stop applying deltas when a gap is detected.
- Fetch a fresh REST snapshot.
- Re-subscribe to the stream.
- Apply only messages newer than the snapshot sequence.
- Resume normal processing after continuity is restored.
Private stream recovery
For account streams:
- Re-authenticate.
- Provide the last processed account sequence if supported by the credential tier.
- Fetch account state through HTTP as the source of truth.
- Reconcile fills, balances, positions, and open orders.
- Resume stream processing only after reconciliation.
Replay on resume
When you resume from a saved account sequence, the server attempts to backfill
missed events from an in-memory, per-account replay buffer (ring-first). That
buffer is bounded by both an event count and a retention window
(max_events / retention_ms), so it holds only the most recent events per
account.
- If your last processed sequence is still within the buffer, the gap is replayed directly from memory.
- If you reconnect after a longer outage, or request a range older than the retention window, the server transparently falls back to a SQL read to backfill the gap, then resumes from the ring.
Either way, sequence numbers and ordering are identical: events are committed to the database and have their identifier derived from the database sequence before being pushed to the replay buffer (the produce path is DB-write-first; the ring only removes the database read from consumer fan-out, not the database write from the projection pipeline). Continue to deduplicate against the last processed account sequence so a replayed range is never applied twice.
BSL cancel-on-disconnect
Liquidity providers and HFT quote engines can configure cancel-on-disconnect through the BSL Business Line API. That flow is separate from normal WebSocket reconnect and is designed to remove stale quotes when a strategy loses liveness.