Skip to main content
The orderbook WebSocket is separate from the settlement stream. It emits full snapshots, absolute depth updates, price changes, and last-trade metadata for selected outcome token IDs. Use one of three levels: For most applications, start with OrderbookEngine.

Managed local book

Set TOKEN_ID to a Polymarket outcome token ID. You can obtain token IDs from V3 market data or the clobTokenIds / clob_token_ids field on a short-form rotation.
subscribe() resolves after the server acknowledges the requested identifiers. The local book becomes readable after its initial snapshot arrives. TypeScript and Python emit ready when every acknowledged token has a valid baseline.

Book update rules

Apply raw messages with these rules: Prices and sizes are decimal strings. Keep them as strings or use a decimal library for exact calculations. Converting them to binary floating point can change level identity and is incompatible with PN1 checksum verification.

Enable PN1 integrity

PN1 lets the SDK detect a missing or out-of-order depth message instead of continuing with a book that merely looks plausible. It validates:
  • a trusted anchor snapshot for each token
  • sequence continuity across depth changes
  • the checksum after every verified mutation
PN1 mode requires explicit market identifiers. A wildcard/firehose orderbook subscription is not available with integrity enabled.

Fail-closed lifecycle

With allowStaleReads / allow_stale_reads left at its default false, the local book moves through these states: On a sequence or checksum failure, the engine gates only the affected token and requests a fresh anchor. It does not serve the last book as verified state. Set stale reads to true only when your application deliberately prefers availability over verified depth. Surface that choice to downstream consumers; a stale book should not be mistaken for current market state.

Reconnects

Orderbook reconnect is automatic by default. The SDK replays the active token set and waits for fresh snapshots. Sequence state from the old connection is never reused as if it belonged to the replacement connection. Application handlers remain attached across reconnects. You do not need to register them again.

Filtered views

Views share the engine’s connection and state but receive updates only for their token set.
Use views when several application components need different slices of one shared book connection.

Raw stream

Choose the raw client when you need protocol messages or maintain state elsewhere:
  • TypeScript: pn.orderbook.subscribe(tokenIds) and pn.orderbook.on(...)
  • Python: await pn.orderbook.subscribe(token_ids) and pn.orderbook.on(...)
  • Rust: client.orderbook_stream(ObStreamOptions::default()).await?
In raw mode, your code is responsible for applying snapshots and deltas correctly. LocalOrderbook provides the same deterministic update logic without the higher-level engine.

Cleanup

See the orderbook protocol, message reference, and PN1 integrity reference for wire-level details.