# Order Book Feeds: Snapshots and Incremental Updates

> How exchanges publish order book data as snapshots and incremental updates, and how to build and maintain an accurate local order book in code without errors.

Source: https://learn.tradelabsai.com/programming/order-book-feeds/  
Track: Programming and Data · Level: Advanced · Updated: 2026-10-03  
Publisher: TradeLabs AI (https://tradelabsai.com). Education, not financial advice.  
Cite as: TradeLabs Learn, "Order Book Feeds: Snapshots and Incremental Updates", https://learn.tradelabsai.com/programming/order-book-feeds/

An order book feed tells your program how the queue of buy and sell orders changes over time. Rather than sending the whole book on every change, which would be enormous, venues send a starting snapshot and then a stream of small updates called deltas. Your program combines them to keep a local copy of the book. Done correctly, the local book matches the exchange's view within milliseconds. Done carelessly, it drifts into a fictional market with prices and sizes that no longer exist.

## Feed styles

| Style | Content | Typical source |
|---|---|---|
| Market by price (MBP) | Total size at each price level | Most crypto exchanges, many futures feeds |
| Market by order (MBO) | Every individual order with an ID | Professional exchange feeds |
| Top of book | Best bid and ask only | Lightweight feeds |
| Periodic snapshots | Full book every N milliseconds | Some retail APIs |

See [Market Data Levels: Level 1, 2 and 3](https://learn.tradelabsai.com/programming/level-2-data/).

## Snapshot plus deltas

1. **Subscribe** to the delta stream and start buffering messages.
2. **Request a snapshot** of the book, which includes an update ID or sequence number.
3. **Discard buffered deltas** older than the snapshot.
4. **Apply remaining deltas** in order.
5. **Check continuity:** each delta's ID must follow the previous one; if not, start again from step 2.

A delta in a market by price feed usually says "price level X on the bid side now has size Y". A size of zero means remove the level.

```python
def apply_delta(book_side, price, size):
    if size == 0:
        book_side.pop(price, None)
    else:
        book_side[price] = size
```

## Keeping the book sorted

The best bid is the highest bid price and the best ask is the lowest ask price. A sorted structure, such as a sorted dictionary or a balanced tree, makes reading the top levels fast. For many retail uses, a plain dictionary plus sorting the top few levels when needed is fast enough.

**Example: Applying deltas**
A snapshot shows bids at 100.00 (5) and 99.99 (8), and asks at 100.01 (4) and 100.02 (6). Three deltas arrive: ask 100.01 size 0, bid 100.00 size 7 and ask 100.03 size 10. After applying them, the ask at 100.01 is gone, so the best ask is now 100.02 (6); the best bid is still 100.00 but with size 7; and a new ask level appears at 100.03. The spread widened from 1 cent to 2 cents. See [Bid-Ask Spread](https://learn.tradelabsai.com/markets/bid-ask-spread/).

## Sanity checks

| Check | Problem it reveals |
|---|---|
| Best bid below best ask | A crossed book usually means missed updates |
| Sequence continuity | Lost messages. See [Sequence Numbers, Dropped Packets and Out-of-Order Messages](https://learn.tradelabsai.com/programming/sequence-numbers/) |
| Checksums | Some exchanges publish a checksum of the top levels to compare against |
| Book age | Stale book when updates stop |
| Level count | Unbounded growth from never removed levels |

If any check fails, rebuild from a fresh snapshot rather than trying to patch the book.

## Market by order books

MBO feeds send add, modify, cancel and execute messages for individual orders. Your program tracks each order ID and its price and size, and aggregates them into price levels. This allows queue position estimates, useful for market making and execution research. See [Fill Probability and Queue Position](https://learn.tradelabsai.com/orders/queue-position/).

## Performance

Busy books can produce thousands of updates per second. Keep update handling minimal, avoid recalculating everything on each message and move analytics to a separate process if needed. See [Exchange vs Receive Timestamps and Latency Measurement](https://learn.tradelabsai.com/programming/latency-measurement/) and [Message Queues](https://learn.tradelabsai.com/infrastructure/message-queues/).

## Recording books

Storing every delta allows exact replay later, for backtesting execution strategies and debugging. Store snapshots periodically too, so replay can start from any point without processing the whole day. See [Market Data Replay](https://learn.tradelabsai.com/programming/market-data-replay/).

## Frequently asked questions

### What is an order book snapshot?

A full picture of the bids and asks at a moment in time, usually with an ID that lets later updates be applied correctly.

### Why is my local order book crossed?

Most often because updates were missed or applied out of order. Rebuild the book from a new snapshot.

### What is the difference between market by price and market by order?

Market by price gives total size at each price level; market by order shows every individual order and its changes.

Next, learn how systems normalise feeds from many venues in [Feed Handlers and Normalization](https://learn.tradelabsai.com/programming/feed-handlers-and-normalization/).

## Continue learning

- Next lesson: [Feed Handlers and Normalization](https://learn.tradelabsai.com/programming/feed-handlers-and-normalization/)
- Previous lesson: [Data Storage, Compression and Caching](https://learn.tradelabsai.com/programming/data-storage/)
- Related: [Data Storage, Compression and Caching](https://learn.tradelabsai.com/programming/data-storage/): Compare ways to store market data: CSV, Parquet, HDF5, PostgreSQL, time series and columnar databases. Learn compression, partitioning and how to choose.
- Related: [Market Data Levels: Level 1, 2 and 3](https://learn.tradelabsai.com/programming/level-2-data/): Level 2 data shows bids and offers at multiple prices beyond the best quote. Learn level 1, 2 and 3 data, how to read depth, its limits and how traders use it.
- Related: [The Order Book and Market Depth](https://learn.tradelabsai.com/market-structure/the-order-book-and-market-depth/): The order book lists every waiting buy and sell order by price. Learn to read market depth, what imbalances show, spoofing risks and how depth affects fills.
- Related: [Sequence Numbers, Dropped Packets and Out-of-Order Messages](https://learn.tradelabsai.com/programming/sequence-numbers/): Sequence numbers let trading systems detect lost, duplicated or out of order messages. Learn how gap detection, recovery and duplicate handling work in practice.
- Related: [WebSocket Market Data Streams](https://learn.tradelabsai.com/programming/websocket-market-data-streams/): How WebSocket streams deliver live trades, quotes and order book updates. Learn subscriptions, heartbeats, reconnecting safely and handling gaps in Python.
- Related: [Feed Handlers and Normalization](https://learn.tradelabsai.com/programming/feed-handlers-and-normalization/): Feed handlers connect to exchange data feeds and convert each venue's format into one standard internal format. Learn the design, symbol mapping and common pitfalls.
