> ## Documentation Index
> Fetch the complete documentation index at: https://docs.0xarchive.io/llms.txt
> Use this file to discover all available pages before exploring further.

# WebSocket L4 Order Book

> Use 0xArchive WebSocket and REST history together for L4 order-book reconstruction and gap-aware state.

L4 order-book streams are about order-level reconstruction behavior, not a generic channels list.

L4 workflows are stricter than simple quote streams. They need a known venue family, symbol, baseline, ordered updates, gap policy, and recovery path. If the client cannot show those pieces, it should not claim to maintain a trustworthy local book.

## L4 Workflow

| Step          | Purpose                                                                     |
| ------------- | --------------------------------------------------------------------------- |
| Choose family | Keep Hyperliquid core, Hyperliquid Spot, HIP-3, HIP-4, and Lighter separate |
| Get baseline  | Start from a snapshot or route-specific history where available             |
| Apply updates | Process ordered diffs without dropping or reordering messages               |
| Detect gaps   | Mark local state unsafe when sequence or replay gap events appear           |
| Rebuild state | Refresh from a snapshot or replay checkpoint before trusting output         |
| Log metadata  | Store route, channel, symbol, timestamps, gap events, and request IDs       |

## Implementation Pattern

<Steps>
  <Step title="Confirm route support">
    Use the REST route family and OpenAPI before assuming L4 exists for a venue, symbol, or plan.
  </Step>

  <Step title="Start with one symbol">
    Confirm the local book can process a small stream before widening to more markets.
  </Step>

  <Step title="Separate UI from book state">
    Drop or throttle noncritical UI updates before dropping book events.
  </Step>

  <Step title="Stop on unsafe gaps">
    If the book misses ordered events, mark it unsafe and rebuild from a known baseline.
  </Step>
</Steps>

## L4 State Packet

Capture this packet before claiming a client maintains an L4 book.

| Field                   | Capture                                                                 |
| ----------------------- | ----------------------------------------------------------------------- |
| Venue family and symbol | Core, Spot, HIP-3, HIP-4, or Lighter-specific context                   |
| Baseline source         | REST snapshot, WebSocket snapshot, checkpoint route, or replay snapshot |
| Update source           | Live diffs, replay messages, REST history, or SDK iterator              |
| Ordering rule           | Sequence field, timestamp ordering, cursor, or replay order             |
| Gap response            | Mark unsafe, stop output, rebuild, or rerun the bounded window          |
| Storage label           | L2, L3, L4, current, historical, replayed, or reconstructed             |

## REST And WebSocket Together

Use REST when you need point snapshots or bounded historical L4 records. Use WebSocket for live updates or replay when event order matters. A robust L4 client often uses both: REST or replay for baseline and recovery, WebSocket for live state, and data-quality routes for trust decisions.

Do not collapse L4 into a generic "orderbook" label in storage. Store whether the data is L2, L3, L4, current, historical, replayed, or reconstructed. That distinction matters for backtests, visualizations, alerting, and customer-facing products.

## Next Step

Open [WebSocket Channels](/websocket/channels), [WebSocket Replay](/websocket/replay), [SDK Reconstruction](/sdks/reconstruction), and the relevant REST family before implementing a local book.
