Skip to main content

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:

AttemptDelay
1250 ms
2500 ms
31 s
42 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:

  1. Stop applying deltas when a gap is detected.
  2. Fetch a fresh REST snapshot.
  3. Re-subscribe to the stream.
  4. Apply only messages newer than the snapshot sequence.
  5. Resume normal processing after continuity is restored.

Private stream recovery

For account streams:

  1. Re-authenticate.
  2. Provide the last processed account sequence if supported by the credential tier.
  3. Fetch account state through HTTP as the source of truth.
  4. Reconcile fills, balances, positions, and open orders.
  5. 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.

See BSL for market makers.