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

# Order Book

> Maintaining a local order book

## Maintaining Order Book via WebSocket

To maintain a local copy of the order book with minimal latency, use the [WebSocket](/latest/perps/websocket-api/overview) API to receive both snapshots and delta updates. This enables your trading logic to react to real-time market changes efficiently.

**Steps to Maintain a Local Order Book:**

1. Connect to the WebSocket and subscribe to the [Order Book Stream](/latest/perps/websocket-api/order-book-stream) to receive real-time updates.
2. Initialize your local order book by sending an `emitPublicOrderBook` request to obtain a full snapshot.
3. Apply each subsequent `publicOrderBookDelta` update in the order received to keep your local copy synchronized.

> **Note:** For `publicOrderBookDelta` messages, the `quantity` field represents the absolute value at the specified price level. A value of `0` indicates that the price level should be removed from your local order book.

### Refreshing via REST

To refresh your local order book snapshot without disconnecting, use the [Get Order Book](/latest/perps/rest-api/get-order-book) REST endpoint as needed.
