Resources/Both venues·Realtime data

Prediction Market WebSocket API: Reconstruct Live Books Safely

A socket connection is easy. Maintaining a correct book through seeds, deltas, reconnects and venue-specific cadence is the actual engineering work.

By DepthFeed··9 min read

A prediction market WebSocket client needs a complete initial book, deterministic update ordering, source and receive timestamps, heartbeat handling and a recovery path after any gap. Polymarket can be captured from event-driven CLOB updates; Kalshi data may arrive through a different venue mechanism. A normalized downstream frame is useful only when it preserves those source differences instead of pretending every venue has the same transport.

The minimum correct state machine

  • Resolve the stable market and outcome identifiers before subscribing.
  • Load or receive a complete book seed before applying incremental changes.
  • Apply updates in the documented source order and reject stale state.
  • Track heartbeat or last-message time independently for every connection.
  • On a sequence gap or uncertain reconnect, discard the local book and reseed.
  • Publish source time, receive time and a clear snapshot-versus-delta flag downstream.

Snapshot and delta are not interchangeable

A snapshot replaces state; a delta mutates it. Treating one as the other produces a book that can look plausible while retaining deleted levels or dropping unchanged size. Write explicit tests for level insertion, size replacement, deletion and crossed-book rejection.

Downstream consumers should not need to guess whether they received a complete ladder. Include a message type or serve normalized complete-book frames when simplicity is worth the additional bandwidth.

Venue-aware normalization

DepthFeed captures Polymarket from the CLOB stream and records normalized observations. Kalshi sports and crypto books follow documented venue-specific collection paths, including adaptive public REST where applicable. The downstream schema can remain consistent while metadata identifies how and when each source was observed.

For paid plans, DepthFeed's WebSocket serves normalized live book channels with plan-specific connection and subscription limits. Historical REST queries use the same price-size shape, which makes it possible to reuse parsing and fill logic across live monitoring and replay.

Production failure tests

FailureExpected behaviorUnsafe behavior
Connection dropsReconnect, reseed, resume from known stateContinue mutating the stale local book
Duplicate updateIdempotent handling or source-order checkDouble the resting size
Out-of-order updateReject or rebuildApply by arrival order without evidence
Slow consumerBackpressure, coalescing or disconnect policyUnbounded memory growth
No recent updateExpose freshness by marketReport the last price as live

Key takeaways

  • 01A complete seed must exist before deltas can form a trustworthy book.
  • 02Reconnect uncertainty should trigger a reseed, not optimistic continuation.
  • 03Source time and receive time answer different latency questions.
  • 04Normalization should preserve venue-specific capture metadata.
  • 05The safest live and historical APIs share one explicit ladder shape.

Use one normalized live frame while keeping source method and timestamps auditable. Free Explorer tier, no card.

View WebSocket channelsView pricing

Questions, answered.

Polymarket publishes live CLOB market-data interfaces. Use the current official documentation for channel and message details, and reseed after any update gap.

Start backtesting Polymarket & Kalshi on real depth.

Free to start, no card. Upgrade when your strategy is ready for the full book.

Start free