Phase 16 - Lesson 16.1

Market Microstructure and the Limit Order Book

How modern electronic markets actually match trades, and the data structure every execution algorithm reasons about.

⏱ 50 min● Advanced🔗 Prereqs: Phase 6 (probability); Phase 9 helpful
↖ Phase 16 hub

Leads to: 16.2 explains how the spread forms; 16.3–16.4 use the book to model impact and execution.

Learning Objectives

Click a status chip to cycle: Not started → In progress → Studied → Practiced → Needs review → Mastered.

Key Vocabulary

Limit order
An order to buy/sell a quantity at a stated price or better; rests in the book providing liquidity.
Market order
An order to trade immediately against the best available prices; consumes liquidity.
Limit order book (LOB)
The set of all resting limit orders, organized by price level and time priority on each side.
Best bid / best ask
The highest resting buy price and lowest resting sell price; their gap is the spread.
Price–time priority
Matching rule: best price first, and within a price, earliest order first (FIFO queue).
Depth
The quantity available at each price level; how much you can trade before moving the price.
Micro-price
A depth-weighted mid \((P_a Q_b+P_b Q_a)/(Q_a+Q_b)\) that leans toward the heavier side.

Intuition & Motivation

Intuition
An electronic market is a giant sorted ledger of promises. On the bid side sit buyers’ limit orders (highest price on top); on the ask side sellers’ (lowest price on top). A market order is impatient: it crosses the spread and eats resting liquidity from the top down, paying worse prices as it consumes each level - that walking-the-book cost is slippage. A limit order is patient: it joins a FIFO queue at its price and waits, earning the spread if filled but risking non-execution. Almost everything in algo trading - spread, impact, execution, market making - is a statement about this queueing system and how fast (latency) you can add, cancel, or hit orders in it.

The order book and order types

Each side of the book is a price-sorted collection of resting limit orders. Two order types drive it: a limit order adds liquidity (rests until matched or cancelled); a market order removes liquidity (executes immediately against the best prices). A cancel removes a resting order. The exchange matches by price–time priority: better prices first, and ties broken by arrival time (first in, first out).

OrderLiquidityPrice controlExecution
LimitProvides (maker)You set the priceUncertain (may not fill)
MarketRemoves (taker)No price controlImmediate, at book prices
Cancel - - Removes your resting order

Prices you can read off the book

Let the best bid be \(P_b\) with size \(Q_b\) and best ask \(P_a\) with size \(Q_a\). Then:

\[\text{mid}=\tfrac12(P_a+P_b),\qquad \text{spread}=P_a-P_b,\qquad \text{micro}=\frac{P_aQ_b+P_bQ_a}{Q_a+Q_b}.\] (16.1)

The micro-price weights toward the side with more size on the opposite queue - heavy bid depth predicts an up-move - and is a better short-horizon predictor of the next mid than the plain mid. Depth is the size available at each level; total depth to a price bounds how much you can trade cheaply.

Walking the book: execution price and slippage

A market buy for \(Q\) shares fills against ask levels \((P_1,q_1),(P_2,q_2),\dots\) from the top until \(Q\) is filled. The average execution price is

\[\bar P=\frac{1}{Q}\sum_i P_i\,\min\!\big(q_i,\ Q-\textstyle\sum_{j\lt i}q_j\big),\qquad \text{slippage}=\bar P-\text{mid}.\] (16.2)
Worked Example - Slippage of a market buy that clears two levels
1
Book asks: \(100.00\times 200\), then \(100.01\times 300\), then \(100.02\times 500\). Best bid \(99.99\), so mid \(=99.995\).
2
Buy \(400\) shares: take all \(200\) at \(100.00\), then \(200\) of the \(300\) at \(100.01\).
3
Average price \(\bar P=(200\times100.00+200\times100.01)/400=100.005\).
4
Slippage \(=\bar P-\text{mid}=100.005-99.995=0.010\) per share - the cost of demanding immediacy for size beyond the top level.

The book as a queue, and latency

Each price level is a FIFO queue; your limit order’s fill probability depends on your position in queue and the flow of cancels/executions ahead of you. Latency - the time to send/modify/cancel - determines whether you reach the front, avoid adverse fills, and cancel stale quotes before they are picked off. This is why HFT is partly an engineering race: microstructure alpha is often about queue position and reaction time, not just a signal.

Interactive: execution simulator

Trade a parent order into a simulated book and watch how splitting it changes the average price and slippage relative to the arrival mid.

Interactive: compute average price and slippage

Common Mistakes to Avoid
  • Assuming you always trade at the mid: market orders pay the spread and walk the book; only patient limit orders can earn it.
  • Ignoring queue position: two limit orders at the same price are not equal - the earlier one fills first.
  • Treating displayed depth as guaranteed: it can be cancelled in microseconds before your order arrives (fleeting liquidity).
  • Forgetting fees: maker/taker rebates and fees shift the true cost of providing vs taking liquidity.
Quant Practitioner Tips
  • Use the micro-price, not the mid, as a short-horizon fair-value estimate when depth is imbalanced.
  • Size relative to top-of-book depth: crossing multiple levels signals your order is large for the market.
  • For passive fills, model your queue position explicitly; it dominates fill probability at the touch.
  • Measure execution against a clear benchmark (arrival mid, VWAP) - slippage is meaningless without one.

Knowledge Check

Q1 Easy
Under price–time priority, a new limit buy order at the current best bid price will:
Execute immediately at the mid
Jump ahead of existing orders at that price
Join the back of the FIFO queue at that price and wait
Cross the spread and pay the ask
Q2 Medium
A market buy order for size larger than the best-ask depth will execute at an average price that is:
Equal to the best ask
Equal to the mid
Worse than the best ask, because it walks up through deeper levels
Better than the best ask due to rebates
Q3 Medium
The micro-price \((P_aQ_b+P_bQ_a)/(Q_a+Q_b)\) improves on the plain mid because it:
Ignores order sizes
Leans toward the side with heavier opposing depth, predicting the next move
Always equals the last trade
Removes the spread entirely

Practical Exercise

A stock’s book shows bids \(49.98\times400,\ 49.97\times600\) and asks \(50.00\times300,\ 50.01\times500,\ 50.02\times1000\). (a) Compute the mid, spread, and micro-price. (b) You send a market buy for \(600\) shares - find the average fill price and slippage vs the mid. (c) Would resting a limit buy at \(49.99\) have been better, and what is the risk?

▶ Show full solution

(a) Mid \(=(50.00+49.98)/2=49.99\); spread \(=0.02\). Micro-price uses best sizes \(Q_b=400,Q_a=300\): \((P_aQ_b+P_bQ_a)/(Q_a+Q_b)=(50.00\times400+49.98\times300)/700=49.9914\), leaning up toward the ask because bid depth exceeds ask depth.

(b) Buy 600: take 300 at 50.00 and 300 at 50.01. \(\bar P=(300\times50.00+300\times50.01)/600=50.005\). Slippage \(=50.005-49.99=0.015\) per share (\(\$9\) total).

(c) A limit buy at 49.99 (inside the spread) would, if filled, beat the market-order price by \(0.015\) and even improve on the old mid. The risk is non-execution: the price may run away (fill never happens, opportunity cost) or you get filled only when the market moves against you (adverse selection - the topic of 16.5). Patience trades a better price for fill uncertainty.

After the reveal, answer for yourself: How would your answer to (c) change if you needed the full 600 shares within one second?

Lesson Summary

The limit order book is a price-time-priority queue of resting limit orders; market orders take liquidity and walk the book, paying slippage, while limit orders provide liquidity and wait in a FIFO queue. From book state you read the mid, spread, depth, and the depth-weighted micro-price. Execution price and slippage follow directly from walking the levels, and latency/queue-position govern passive fills - the foundations for spread, impact, and execution modeling that follow.

Formula Sheet Additions

Book observables
\[\text{mid}=\tfrac12(P_a+P_b),\ \ \text{micro}=\frac{P_aQ_b+P_bQ_a}{Q_a+Q_b}\]
The micro-price leans toward the heavier-depth side and better predicts the next mid.
Average execution price
\[\bar P=\tfrac1Q\sum_i P_i\min(q_i,\,Q-\textstyle\sum_{j\lt i}q_j)\]
Walking the book; slippage \(=\bar P-\text{mid}\).
Error Log Checklist
  • Did I account for walking multiple levels, not just the touch?
  • Did I pick an explicit benchmark for slippage (mid/VWAP)?
  • Did I consider queue position for any passive order?
  • Did I include fees/rebates in the true cost?

Retrieval Practice

Close the lesson and answer from memory before checking. This is deliberate, effortful recall - the single highest-yield study action.

▶ Show retrieval prompts & answers
Q: State the price–time priority rule and what happens to a new order at the best bid.
A: Best price matches first; within a price, earliest arrival first (FIFO). A new limit order at the best bid joins the back of that queue and waits.
Q: Write the average execution price of a market order and define slippage.
A: \(\bar P=\tfrac1Q\sum_i P_i\min(q_i,Q-\sum_{j\lt i}q_j)\) over consumed levels; slippage \(=\bar P-\text{mid}\), the cost of walking the book.
Q: Why is the micro-price a better short-horizon fair value than the mid?
A: It depth-weights the two touches, tilting toward the heavier side, which predicts the direction of the next mid move that the unweighted mid ignores.

Flashcards

Click to flip. These feed the site-wide spaced-repetition queue.

Limit vs market order
Limit provides liquidity, waits in a FIFO queue; market takes liquidity, executes now and walks the book.
Book observables
mid \(=\tfrac12(P_a+P_b)\); spread \(=P_a-P_b\); micro-price depth-weights the touches.
Slippage
\(\bar P-\text{mid}\): the extra cost of a market order consuming deeper, worse-priced levels.

Completion Checklist

Confidence / mastery rating
Personal notes

Source References

This lesson synthesizes and paraphrases concepts from the sources below. No copyrighted text, problem sets, or solutions are reproduced. Return to the originals for full depth.