AnyLearn
All lessons
AIadvanced

What Is Actually in an Order Book, and What a Model Can See

Before choosing an architecture you have to decide what the input is, and an order book offers several incompatible representations that are not equally informative. This lesson covers what each data level contains, why raw prices are the wrong features, and the representation choices that decide more than the model does.

Updated · AI-authored, review-gated · how lessons are made

Not signed in: your progress and quiz score won't be saved.
Progress1 / 10

The object being modelled

A limit order book is the set of resting buy and sell orders at each price, maintained by the exchange's matching engine. Its mechanics, how a price forms, why a spread exists, how information reaches the price, are the subject of the catalogue's Market Microstructure course, and this course assumes them.

What this course is about is the modelling question. The book is one of the richest data sources in finance: complete, high-frequency, and a direct record of every participant's revealed intentions. It has also produced a long run of published results that do not survive contact with a trading desk.

Key idea: Almost every failure in this area traces back to a decision made before the model: what the input representation is, what the label means, or what the evaluation measures. The architecture is the part people write about and the part that matters least.

Full lesson text

All 10 steps on one page, for reading, reference, and search.

Show

1. The object being modelled

A limit order book is the set of resting buy and sell orders at each price, maintained by the exchange's matching engine. Its mechanics, how a price forms, why a spread exists, how information reaches the price, are the subject of the catalogue's Market Microstructure course, and this course assumes them.

What this course is about is the modelling question. The book is one of the richest data sources in finance: complete, high-frequency, and a direct record of every participant's revealed intentions. It has also produced a long run of published results that do not survive contact with a trading desk.

Key idea: Almost every failure in this area traces back to a decision made before the model: what the input representation is, what the label means, or what the evaluation measures. The architecture is the part people write about and the part that matters least.

2. What each data level actually gives you

Market data comes in tiers, and the tier decides which questions are answerable at all.

LevelContainsWhat it cannot answer
Level 1best bid and ask, sizes, last tradeanything about depth beyond the touch
Level 2aggregated size at each price levelhow many orders make up a level, or their order
Level 3every individual order, with add, cancel and execute eventslittle; this is the full record

Level 2 is what most research uses and it is aggregated: a level showing 5,000 shares might be one order or fifty, and the difference matters because one large order can be pulled instantly while fifty small ones cannot.

Gotcha: Only Level 3 supports queue-position reasoning, and queue position is what determines whether your own passive order fills. A model trained on Level 2 can predict price movement and cannot support any strategy whose profitability depends on getting filled passively, which is most of them at this frequency.

3. Snapshots or events

The same underlying data can be presented two ways, and the choice propagates through everything downstream.

  • Snapshots. The state of the book at fixed intervals or after every change. Fixed-size, rectangular, and directly consumable by a convolutional or recurrent network. Discards what happened between snapshots.
  • Event streams. The sequence of messages: order added at this price, cancelled, executed. Variable-rate, irregular, and carries the causal detail that snapshots lose.

The distinction is not cosmetic. Whether a level shrank because orders were cancelled or because they were executed is a completely different signal, and a snapshot shows only that the level is smaller.

Key idea: Cancellations and executions look identical in a snapshot and mean opposite things. An execution means someone paid to take liquidity, which is informative about direction. A cancellation means someone withdrew, which is informative about intent to not trade. Any representation that cannot distinguish them has discarded one of the book's strongest signals before modelling begins.

4. Why raw prices are the wrong input

The obvious representation is a matrix of the top nn levels: price and size on each side. Feeding it raw is a mistake for reasons the financial machine learning course establishes in general and which bite unusually hard here.

Prices are non-stationary: a model trained when a stock was at 40 has never seen 400, and the absolute level carries no information about what happens next. Sizes are not stationary either, since liquidity varies by name, by time of day and by regime.

The standard fixes convert everything to quantities that mean the same thing on every day and in every name.

# raw:      [[bid_px_1, bid_sz_1, ask_px_1, ask_sz_1], ...]
mid    = (ask_px[0] + bid_px[0]) / 2
spread =  ask_px[0] - bid_px[0]

# relative price: distance from mid, in ticks
rel_bid_px = (mid - bid_px) / tick_size
rel_ask_px = (ask_px - mid) / tick_size

# relative size: share of visible depth
total_sz   = bid_sz.sum() + ask_sz.sum()
rel_bid_sz = bid_sz / total_sz

# the single most-used derived feature
imbalance  = (bid_sz[0] - ask_sz[0]) / (bid_sz[0] + ask_sz[0])

In practice: Order book imbalance, the last line, is the feature that appears in nearly every study, and it has an intuitive reading: more resting size on the bid than the ask means buying pressure exceeds selling pressure at the touch. It is also the feature most likely to be already priced in, precisely because everyone computes it.

5. The mid-price is a poor summary

Almost every study predicts the mid-price, and the mid is a worse statistic than it looks.

It is the unweighted average of the best bid and ask, which means it ignores how much size sits on each side. A book with 10,000 shares bid and 100 offered has the same mid as one with 100 bid and 10,000 offered, and those two books are about to do very different things.

The microprice weights by the opposite side's size, which is the correct direction:

pmicro=pbidsask+pasksbidsbid+saskp_{\text{micro}} = \frac{p_{\text{bid}} \cdot s_{\text{ask}} + p_{\text{ask}} \cdot s_{\text{bid}}}{s_{\text{bid}} + s_{\text{ask}}}

Heavy bid size pulls the microprice toward the ask, reflecting that the next trade is more likely to be a buy.

Gotcha: Predicting mid-price changes and predicting microprice changes are different problems, and the mid version contains a mechanical component that the microprice partly removes. A model that appears to predict the mid may be predicting the arrival of the tick bounce rather than anything about value, which is the subject of the third lesson.

6. Clock time is the wrong axis

Market activity is wildly non-uniform. A minute at the open contains hundreds of times the events of a minute at midday, so a model reading fixed time intervals sees a sequence whose information density varies by orders of magnitude within a session.

SamplingNew observation whenProperty
Timea fixed interval elapsesinformation density varies enormously
Eventa message arrivesuniform in activity, irregular in time
Tradea trade occursfocused on liquidity-taking
Volumefixed volume tradesclosest to constant information

Event-based sampling is the usual choice here and has a matching drawback: latency budgets are in microseconds of wall-clock time, so a model whose input is indexed by events must still answer within a time budget it does not control.

In practice: Both axes matter and they measure different things. Include elapsed time as a feature even when sampling on events, since the same twenty messages arriving in one millisecond and in one minute describe very different markets, and a purely event-indexed model cannot tell them apart.

7. How deep to look

Books can be hundreds of levels deep. Nearly all research uses the top 10 on each side, and the reason is not arbitrary.

  • Depth near the touch is real. The first few levels are where trading happens and where liquidity is genuinely committed.
  • Depth far from the touch is cheap talk. An order 50 ticks away costs nothing to post and can be cancelled before it is ever at risk. It is a statement of intent that carries no commitment.
  • Deep levels are unstable. They are added and pulled constantly, so features built from them are noisy without being informative.

Key idea: The informativeness of a resting order is roughly proportional to how exposed it is. An order at the touch may execute on the next message, so posting it is a real decision. An order far away is nearly free, and free signals are not signals. This is why adding levels beyond the top handful reliably fails to improve models, and it is a structural fact about the data rather than a limitation of the architecture.

8. The signals that are actually there

It is worth separating what the book demonstrably contains from what people hope it contains.

SignalWhat it reflects
Order book imbalancepressure at the touch; the most widely used feature
Trade sign autocorrelationlarge orders being worked in slices, so flow persists
Queue dynamics at the touchhow quickly liquidity refills after being taken
Spread and depth regimehow willing liquidity providers currently are to quote
Cancellation burstsproviders withdrawing, often just before a move

Every one of these is short-horizon. The book describes the immediate supply and demand for immediacy, not the value of the asset, and its predictive content decays over seconds rather than minutes.

Gotcha: These signals are known to everyone with the same data, which is a large number of well-capitalised firms. Anything a straightforward model extracts from Level 2 data is very likely already reflected in the price by the time you could act on it. The competitive question is not whether the signal exists but whether you can act on it faster than the people who already found it.

9. The engineering constraints are part of the model

Unusually for machine learning, the deployment environment constrains the model design directly rather than being an afterthought.

  • Latency. A signal decaying over seconds is worthless if inference takes seconds. The budget is typically microseconds to low milliseconds, which rules out large models regardless of their accuracy.
  • Determinism. The same book state must produce the same action. Nondeterministic inference in a live trading path is an operational hazard, not a curiosity.
  • Throughput. Message rates spike by orders of magnitude at the open, on news and at the close. The system must survive the peak, not the average.
  • Failure behaviour. What the model does when data is late, out of order or missing has to be specified, because at this frequency it will happen daily.

Key idea: A more accurate model that is slower can easily be worth less than a less accurate one that is faster, because the signal decays while you compute. This inverts the usual accuracy-latency trade-off, where latency is a cost and accuracy is the objective. Here latency destroys the objective itself.

10. The decisions that come before the model

Everything in this lesson is a choice made before any architecture is selected, and each one bounds what the model can possibly achieve.

  1. Which data level? Level 2 cannot support queue reasoning; if your strategy needs passive fills, you need Level 3.
  2. Snapshots or events? Snapshots cannot distinguish cancellations from executions, which are opposite signals.
  3. What is stationary? Relative prices in ticks, sizes as shares of depth. Never raw levels.
  4. Mid or microprice? They are different targets and the mid carries a mechanical component.
  5. What is the time axis? Event-sampled, with elapsed time retained as a feature.
  6. How deep? Around ten levels; beyond that the orders are not committed to anything.
  7. What is the latency budget? It constrains model size before accuracy is even measured.

In practice: A team that gets these seven right with logistic regression will beat a team that gets them wrong with a transformer. The next lesson covers the architectures anyway, because they are worth knowing, and because knowing why they help less than expected is itself the useful part.

Check your understanding

The lesson ends with a 5-question quiz. Take it in the player above to see your score.

  1. Why can a model trained on Level 2 data not support a passive-fill strategy?
    • Level 2 lacks trade prices
    • Level 2 aggregates size per price level, so it cannot represent queue position
    • Level 2 updates too slowly for high-frequency trading
    • Level 2 omits the best bid and ask
  2. What critical distinction do book snapshots lose relative to event streams?
    • Whether a level shrank because orders were cancelled or executed
    • The absolute price level of each rung
    • The identity of the exchange venue
    • The total depth on each side
  3. Two books have identical mids but one has 10,000 bid against 100 offered. What does this show?
    • That the spread must differ between them
    • That mid-price is non-stationary
    • That the mid ignores size, which is why the microprice weights by the opposite side's depth
    • That Level 2 data is insufficient to compute the mid
  4. Why does adding order book levels beyond the top ten rarely improve models?
    • Exchanges do not publish deeper levels reliably
    • Deeper levels change too slowly to carry information
    • The additional features cause numerical instability
    • Orders far from the touch cost nothing to post and can be cancelled, so they carry no commitment
  5. Why does latency constrain model choice differently here than in most ML applications?
    • Because the signal decays over seconds, so a slow accurate model can be worth less than a fast inaccurate one
    • Because exchanges impose a maximum model size
    • Because training time dominates the project schedule
    • Because latency affects only the backtest, not live trading

Related lessons

AI
advanced

Evaluating a Book Model Honestly

If your cost per round trip equals the move you are trying to capture, you need 100 percent directional accuracy to break even. This lesson computes that hurdle, replaces accuracy with metrics tied to a tradeable decision, and covers the capacity and latency limits that decide whether a real edge is worth anything.

10 steps·~15 min
AI
advanced

Why Reported Order Book Results Do Not Replicate

At a one-event horizon, 92 percent of mid-price labels are exactly no-change, so a model that always predicts flat scores 92 percent accuracy. This lesson computes that baseline across horizons and works through the four mechanisms that turn a genuine measurement into a number nobody can reproduce.

10 steps·~15 min
AI
advanced

Architectures for Order Book Data, and Why They Help Less Than Expected

Convolutional and recurrent networks have been applied to order book data with published success, and the architectures encode real assumptions about the book's structure. This lesson explains what each one assumes, why the gains over simple baselines are smaller than headline numbers suggest, and where the modelling effort is better spent.

10 steps·~15 min
AI
advanced

Features: Stationarity Without Erasing the Memory

Prices are non-stationary and returns are stationary but forget everything, so the standard fix throws away the level information a model needed. This lesson builds fractional differentiation, which makes the choice a dial rather than a switch, and shows by computation that most of the memory can be kept while still passing a stationarity test.

10 steps·~15 min