Skip to main content
Keep an order-level (L4) book for Hyperliquid core, Spot, HIP-3, or HIP-4: start from a checkpoint, apply ordered diffs, and rebuild when a gap appears. Every L4 family supports live subscriptions and checkpoint-anchored WebSocket replay: l4_diffs and l4_orders on core, and the spot_, hip3_, and hip4_ prefixed channels on the other families. REST history and checkpoint routes serve the same records for bounded pulls. Lighter has L3 individual-order depth instead.
SnapshotStart from a checkpointPull an L4 snapshot for one family and symbol, or use the l4_snapshot that opens a subscription or replay.
DiffsApply updates in orderApply server-ordered diffs without dropping or reordering them, and keep each event’s block and order metadata.
Live bookHold current stateOn a gap event, mark the book unsafe and rebuild from a fresh checkpoint.

Subscribe to L4 diffs

An L4 subscription opens with an l4_snapshot of the full book, then sends ordered l4_batch messages. This script prints the snapshot size and the first few batches for SOL. It runs on any plan, including Free.
A BTC snapshot is several megabytes, so expect the first message on a busy market to take a moment.

Order events

Live l4_orders, hip3_l4_orders, spot_l4_orders, and hip4_l4_orders messages use the l4_batch type. Items are ordered by block number, then by their order within the block. Each item carries the fields below; optional fields are omitted when absent. Use cloid to match an event to an order your own system placed. Hyperliquid core and HIP-3 channels carry accepted orders only. Spot and HIP-4 channels also carry rejected orders, with the rejection reason in status.

Keep the book correct

  • Baseline: start every family from a REST snapshot or checkpoint route, or from the l4_snapshot that opens a subscription or replay.
  • Updates: use live diffs for current state, and WebSocket replay, REST history, or the SDK reconstruction helpers for historical work.
  • Ordering: apply L4 events in the order the server sends them and keep the block and order metadata. Never sort by timestamp alone. (Lighter L3 history orders by sequence instead.)
  • Queue placement: a new-order item in an l4_batch can carry an optional insert_before key. Insert the new order ahead of that order ID within its price level; when the key is absent, append it at the tail. The initial l4_snapshot lists each price level in queue priority.
  • Gaps: when a sequence or replay gap appears, mark the book unsafe, stop output, and rebuild from a snapshot or replay checkpoint, or rerun the bounded window.
  • Load: confirm one symbol keeps up before adding markets, and drop or throttle UI updates before you ever drop book events. Size the client against WebSocket limits, and check the symbol’s published coverage before requesting history.
  • Storage: label stored data as L2, L3, or L4, and as current, historical, replayed, or reconstructed. Do not collapse L4 into a generic “orderbook” label; the distinction matters for backtests, charts, alerts, and anything you publish.
A production L4 client often uses REST for the baseline and recovery, WebSocket for live state or replay, and the Data quality routes before trusting the output.

Next step

Replay an L4 window from a checkpoint with WebSocket replay.
Last modified on October 6, 2026