Basic Prerequisites: Market Microstructure & Order Types and Probability & Measure Theory (point processes, conditional expectation, martingales). (these are the folder-level prerequisites for pages 02–06; page 01 states its own, smaller, entry requirements)


1. Intuition & Practical Objective

The limit order book (LOB) is the state of the market. In an order-driven venue the price is not announced by a dealer - it emerges from a queue of resting commitments to buy and sell, and the matching engine is the deterministic machine that turns arriving orders into trades at that state. Everything a market maker does - quoting, cancelling, chasing queue position, hedging - is a move in a game whose board is the book.

This folder is the mechanics hub for Pillar 6. It is a hub: it (a) gives you the fast formula lookup below (the quantities a market-making or execution desk computes thousands of times a second), and (b) routes you to six sub-pages that walk you from raw intuition through the data model, the matching engine, the risks, and the stochastic extensions.

The one-sentence essence. “The order book is a state machine: orders arrive, rest, queue, and are matched under priority rules, so the price is a function of the book state - and every risk a liquidity provider faces (queue position, adverse selection, latency) is a property of that state machine, not a forecast about the future.”

Three ideas the whole folder rests on:

  1. Make vs take. A market order demands liquidity and pays the spread plus whatever it walks; a limit order supplies liquidity, earns the spread, and takes on queue-position and adverse-selection risk. Both are the same object - an order - with opposite priority.
  2. The book is a queueing system. Depth at a price is a queue; your position in it determines whether, and when, you trade.
  3. Priority is a rule, not a price. Price-time (FIFO) priority means two orders at the same price are ranked by arrival. That ranking is worth real money and is why latency is a first-class input to market making.

2. Mathematical Ground Truth & Derivations

Quick-Reference Lookup. All formulas are standard microstructure quantities, transcribed from Hasbrouck (2007) Ch 2, Foucault–Pagano–Röell (2013) Ch 2, and Cont–Kukanov–Stoikov (2014); the numbers in the check column were re-executed and reproduced exactly - the book totals from the §3 code on this page, the rest from the sub-pages cited (02 for VWAP half-level fills, 03 for OFI).

Notation: resting buy (bid) orders at prices with sizes ; best bid , best ask ; bid/ask sizes at the touch ; order arriving at time .

QuantityDefinitionVerified check
Best bid / best ask, ,
Quoted spread
Midquote
Depth at a pricetotal resting depth
Queue position (size ahead of a new order)
Market-order VWAP over the swept levels at (hub book)
Effective half-spread, buy sell at (page 02’s book, )
Order Flow Imbalance (see 03 page)
Microprice (size-weighted touch)falls between
Toxic-fill EV (half-spread , adverse move , informed share )break-even
Expected wait to fill ( = lots/s executed at the touch) s at

Price-time priority (formal). With FIFO, a resting order at price on side is matched before order iff

where "" ranks higher bids first for buys and lower asks first for sells. The best orders form the touch; the matching engine always consumes the lexicographic minimum of . Pro-rata venues replace the second criterion with a size-proportional split at each price level.


3. Computational Implementation - the state and its derived quantities

This runs on the standard library only. It builds an L2 book, computes the derived quantities above, and computes the OFI between two book states (Cont–Kukanov–Stoikov 2014).

A deeper bid adds depth but does not improve the touch, so it does not move the price; a cancellation at the touch withdraws the only thing that sets . OFI nets these to , the sign that forecast a down-tick. That asymmetry - depth far from the touch is nearly irrelevant, depth at the touch is everything - is the practical heart of the book.


4. Failure Modes & First-Principles Breakdowns

Hub signposts - each failure mode is dissected on 05 · Failure Modes & Practice. In one line each:

  1. Queue-position risk - you can be right about the price and still lose, because a passive order that never reaches the front captures nothing while paying the option value it wrote to everyone else.
  2. Adverse selection at the touch - passive fills are not random: they are concentrated exactly when the market is about to move against you. Expected P&L per fill is , which goes negative past a break-even informed share.
  3. Latency & state desync - the book you see is a stale copy of the venue’s book; a slower participant trades at yesterday’s state.
  4. Fragility of the state representation - the L3 book is reconstructed from a message stream; dropped, reordered, or mis-signed events silently corrupt it (see Limit Order Book Mechanics & L3 Data).

5. References

  • Hasbrouck, Joel: Empirical Market Microstructure (OUP, 2007)
  • Foucault, Pagano & Röell: Market Liquidity: Theory, Evidence, and Practice (OUP, 2013)
  • Cont, Stoikov & Talreja (2010), A stochastic model for order book dynamics, Operations Research 58(3), 549–563. *
  • Cont, Kukanov & Stoikov (2014), The price impact of order book events, Journal of Financial Econometrics 12(1), 47–88. OFI: the micro-price signal.
  • Gould, Porter, Williams, McDonald, Fenn & Howison (2013), Limit order books, Quantitative Finance 13(11), 1709–1742. Citation hub and orientation for the whole folder.

6. Connected Graph Bridges

Beginner: start at 01 · Practitioner: start at 05