Objective
Read a limit order book: know what each number means, how an incoming order is filled, what it costs to trade, and what the book says about where the price is going next.
Two kinds of order
- A limit order says "buy up to at no more than " (or sell at no less than ). If it cannot trade immediately it rests in the book and waits. Resting orders provide liquidity.
- A market order says "buy now at whatever prices are available". It trades against resting orders and takes liquidity. A limit order priced through the opposite side (a buy above the best ask) is marketable and behaves like a market order with a price cap.
The book
The book is two sorted queues of resting limit orders:
| Bid size | Bid | Ask | Ask size |
|---|---|---|---|
| 400 | 100.00 | 100.02 | 300 |
| 600 | 99.99 | 100.03 | 500 |
| 800 | 99.97 | 100.05 | 1,000 |
- Best bid = 100.00: the highest price someone will pay. Best ask (offer) = 100.02: the lowest price someone will sell at. "100.00 bid, at 100.02, 400 by 300."
- Spread = 0.02. Mid = 100.01.
- Depth: the sizes behind the best prices. The top row is the top of book; the whole table is market-by-price data.
The smallest price increment is the tick (here 0.01). The spread can never be smaller than one tick, and in liquid names it is often exactly one tick.
Who gets filled: price-time priority
Most exchanges match by price, then time. A better price always trades first. Among orders at the same price, the one that arrived first trades first (FIFO). Cancelling and re-entering an order sends it to the back of its queue, which is why queue position is valuable to market makers.
Some markets (certain futures contracts) use pro-rata matching at a price level instead, splitting a fill in proportion to resting size; this rewards size rather than speed.
The spread is a cost
If you buy at the ask and immediately sell at the bid, you lose the spread. Relative to the mid, each aggressive trade costs half the spread. Traders quote this in basis points of the mid:
The spread is what liquidity providers earn for standing ready to trade. They need it to cover the risk of trading with better-informed counterparties (adverse selection), inventory risk and fees. Spreads widen when volatility or information asymmetry rises.
Large orders walk the book
An order bigger than the top-of-book size consumes successive levels. The average price gets worse with size: this is market impact (or slippage). Measuring it against the mid at the time of the order is called implementation shortfall.
Worked example
walking the book
Using the book above, you send a market order to buy 1,000 shares. What is your average price, and what does the trade cost you relative to the mid?
Show solutionHide solution
Fill level by level from the best ask:
| Price | Shares | Cost |
|---|---|---|
| 100.02 | 300 | 30,006 |
| 100.03 | 500 | 50,015 |
| 100.05 | 200 | 20,010 |
| Total | 1,000 | 100,031 |
Average price . Against the mid of 100.01 that is 2.1 cents a share, or $21 in total, about bps. Half the spread alone would have cost 1 cent a share; the other 1.1 cents is impact from walking the book. After the trade the best ask is 100.05 with 800 left, so the spread has widened to 5 cents.
A sketch of the same computation:
def walk_book(levels, qty):
"""Fill a market order of size qty against price levels [(price, size), ...], best first."""
filled, cost = 0, 0.0
for price, size in levels:
take = min(size, qty - filled)
cost += take * price
filled += take
if filled == qty:
break
if filled < qty:
raise ValueError("not enough depth")
return cost / qty
asks = [(100.02, 300), (100.03, 500), (100.05, 1000)]
print(round(walk_book(asks, 1000), 4)) # 100.031
Mid versus microprice
The mid ignores sizes. But if 400 shares are bid and only 300 are offered, the ask is more likely to be cleared first and the price more likely to tick up. The microprice (size-weighted mid) weights each side's price by the opposite side's size:
The ratio is the order-book imbalance. With the microprice equals the mid; as the bid queue grows relative to the ask, it moves towards the ask. Market makers use estimates like this as a short-horizon fair value.
Worked example
queue priority and microprice
At the 100.00 bid the queue, in arrival order, is A (200 shares), B (500), C (300). (a) A market sell for 600 arrives. Who is filled? (b) Separately, using the original top of book (400 bid at 100.00, 300 offered at 100.02), what is the microprice?
Show solutionHide solution
(a) FIFO at a single price: A is filled in full (200), then B for the remaining 400 of its 500. C, who arrived last, gets nothing. B keeps its place at the front with 100 shares left.
(b) , so
slightly above the mid of 100.01, because buyers outnumber sellers at the touch.
Knowledge check
Using the same book (bids 400 at 100.00, 600 at 99.99, 800 at 99.97), you market-sell 700 shares. What is your average price, to four decimals?
Knowledge check
A stock is quoted 49.98 bid, 50.02 offered. What is the spread in basis points of the mid?
Knowledge check
The best bid has 5,000 shares and the best ask has 500 shares. Where is the microprice relative to the mid?
Key takeaways
- Limit orders rest and provide liquidity; market orders take it and pay the spread.
- Matching is usually price, then time (FIFO); queue position matters.
- Spread = ask − bid; each aggressive trade costs half the spread relative to the mid, plus impact if it walks the book.
- Microprice leans towards the side with less size.
- Spreads compensate liquidity providers for adverse selection and inventory risk.
Practice problems
Finished reading?
Answer the 3 knowledge checks to complete this lesson (0 done).