Quant Memo
Advanced

Order Book Mechanics

How a limit order book actually works, the two-sided queue of resting orders, price-time priority, matching, and why your queue position is an asset with real option value.

Prerequisites: Expectation, Variance & Moments

Almost every modern equity, futures, and crypto market is a continuous double auction run through a limit order book (LOB). Before you can reason about spreads, impact, or execution algorithms, you have to know precisely what the book is and how the matching engine turns two streams of orders into trades. This is the plumbing that every later model idealizes.

The book as two priority queues

At any instant the LOB is a set of resting limit orders: offers to buy (bids) or sell (asks) a quantity at a stated price, which rest until they trade or are cancelled. Collect them by price level. The best bid bb is the highest price anyone will pay; the best ask aa is the lowest anyone will sell at. By construction a>ba > b; the difference

s=abs = a - b

is the quoted spread, and m=(a+b)/2m = (a+b)/2 is the mid-price. The total size resting at each price level is the depth; the shape of depth away from the mid is the book's liquidity profile, typically thin at the touch and thickening deeper in.

A trade happens only when an incoming order crosses the book, a marketable buy priced at or above aa, or an aggressive sell at or below bb. Resting orders provide liquidity (they are the standing options to trade); crossing orders take it. This provide/take distinction is the root of the maker–taker fee model and of every microstructure model that follows.

Price–time priority

When two resting orders could fill an incoming order, the matching engine needs a rule. The near-universal one is price–time priority (FIFO):

  1. Price first. Better-priced orders always fill before worse-priced ones, a bid at $100.01 is hit before a bid at $100.00.
  2. Time second. Among orders at the same price, the one that arrived earliest fills first.

So each price level is a FIFO queue. If you post a limit buy at the best bid and there are already Q0Q_0 shares ahead of you, you sit at queue position Q0Q_0. Incoming market sells consume the queue from the front; cancellations ahead of you also advance you. You only trade once every share in front of you is gone. (Some venues, many futures and options, use pro-rata matching instead, allocating an incoming fill proportional to displayed size; there the incentive is to over-display rather than to arrive early.)

Queue position has option value

Your position in the queue is not a bookkeeping detail, it is an asset. Let QQ be the number of shares ahead of you at the touch. Very roughly, your fill probability before the level's price moves is a decreasing function of QQ: you fill only if cumulative market-order arrivals plus queue depletion reach past QQ before the mid ticks. In the Cont–Stoikov–Talreja birth–death model, each price level's size evolves as market orders (which decrement the front), limit orders (which add to the back), and cancellations, so the probability that the bid queue empties before the ask queue does is a first-passage problem for a random walk of the queue imbalance.

The practical consequences are large:

  • Being early is worth money. A front-of-queue order fills against uninformed flow before the price moves; a back-of-queue order tends to fill only when the queue is being run over because the price is about to move against it, i.e., it is adversely selected. Queue position converts directly into realized spread capture. See Adverse Selection.
  • Cancels are strategic. Because time priority is lost forever once you cancel, re-pricing an order sends you to the back of the new level's queue. This makes "should I stay or reprice?" a genuine optimization and is a big part of why quoted books flicker.

Order flow and the imbalance signal

Define the order-flow imbalance at the touch, using bid depth QbQ^b and ask depth QaQ^a:

I=QbQaQb+Qa[1,1].I = \frac{Q^b - Q^a}{Q^b + Q^a} \in [-1, 1].

Empirically the very next mid-price move is strongly predictable from II: a heavily bid-skewed book (I+1I \to +1) tends to tick up, because the thin ask will be consumed first. This is one of the most robust high-frequency signals and a first-order input to the quoting logic in The Avellaneda-Stoikov Model and to short-horizon Latency & High-Frequency Trading strategies.

Worked example

The book on a stock reads:

SidePriceSize
Ask50.03800
Ask50.02500
Bid50.01300
Bid50.001200

Best bid $50.01, best ask $50.02, so s = \0.01(aonetickmarket)and(a one-tick market) andm = $50.015. A market buy for 700 shares first lifts all 500 at \50.02, then 200 of the 800 at $50.03; the volume-weighted fill is (500\cdot 50.02 + 200\cdot 50.03)/700 = \50.0229, about \0.008 above the mid, this is the effective half-spread plus walk-up the book, the cost of demanding immediacy for a size larger than the touch. The imbalance is I=(300500)/(300+500)=0.25I = (300 - 500)/(300+500) = -0.25, tilted to the ask side, consistent with the next tick being down. If instead you had posted a bid at $50.01 behind the existing 300 shares, you would rest at queue position 300 and earn the spread, if you fill before the mid moves against you.

Failure modes and real-world caveats

  • Hidden and iceberg liquidity. Displayed depth understates true depth; iceberg orders show only a slice, and dark pools hold size off-book entirely, so the visible LOB is a censored view. Impact models fit to displayed size mis-estimate real liquidity.
  • Fleeting quotes and spoofing. A large fraction of posted orders are cancelled within milliseconds. Some of that is legitimate risk management; some is manipulation (spoofing), displaying size you never intend to trade to move the imbalance signal.
  • Tick-size constraints. When the spread is pinned at one tick, price priority can't differentiate orders, so time priority dominates and queues grow enormous, the regime where queue-position modeling matters most.
  • Latency. The book you see is already stale by your round-trip time; acting on a mid you believe is current is the core risk of Latency & High-Frequency Trading.

In interviews

Be able to state price–time priority precisely and explain why a market buy for more than the top-of-book size fills at a volume-weighted price that walks up the book. Expect the queue-position question: "you post at the bid with 10,000 shares ahead of you, what determines whether you get filled, and is a fill good news or bad news?" The sophisticated answer is that a quick fill against uninformed flow is good (you captured the spread) but a fill precisely when the queue is being swept is Adverse Selection. A common follow-up asks how order-book imbalance predicts the next price move, sketch I=(QbQa)/(Qb+Qa)I = (Q^b - Q^a)/(Q^b + Q^a) and argue the thin side gets eaten first. See Market vs. Limit Orders for the decision of which order type to send in the first place.

Related concepts

Practice in interviews

Further reading

  • O'Hara, Market Microstructure Theory
  • Bouchaud, Bonart, Donier & Gould, Trades, Quotes and Prices
  • Cont, Stoikov & Talreja (2010), A Stochastic Model for Order Book Dynamics
ShareTwitterLinkedIn