Skip to content
LeetQuant
F8 Financial Markets Fundamentals

F8 · Financial Markets Fundamentals · Lesson 4 of 7

Order Books, Bids, Asks and Spreads

Limit and market orders, price-time priority, book depth, mid and microprice, the spread as a trading cost, and walking the book.

15 min

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 QQ at no more than PP" (or sell at no less than PP). If it cannot trade immediately it rests in the book and waits. Resting orders provide liquidity.
  • A market order says "buy QQ 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 sizeBidAskAsk size
400100.00100.02300
60099.99100.03500
80099.97100.051,000
  • Best bid PbP_b = 100.00: the highest price someone will pay. Best ask (offer) PaP_a = 100.02: the lowest price someone will sell at. "100.00 bid, at 100.02, 400 by 300."
  • Spread Pa−PbP_a - P_b = 0.02. Mid (Pa+Pb)/2(P_a + P_b)/2 = 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:

spread (bps)=Pa−Pbmid×104.\text{spread (bps)} = \frac{P_a - P_b}{\text{mid}} \times 10^4 .

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 solution

Fill level by level from the best ask:

PriceSharesCost
100.0230030,006
100.0350050,015
100.0520020,010
Total1,000100,031

Average price =100,031/1,000=100.031= 100{,}031 / 1{,}000 = 100.031. Against the mid of 100.01 that is 2.1 cents a share, or $21 in total, about 0.021/100.01×104≈2.10.021/100.01 \times 10^4 \approx 2.1 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:

Pmicro=Pb Qa+Pa QbQa+Qb=Pb+(Pa−Pb) QbQa+Qb.P_{\text{micro}} = \frac{P_b\,Q_a + P_a\,Q_b}{Q_a + Q_b} = P_b + (P_a - P_b)\,\frac{Q_b}{Q_a + Q_b} .

The ratio I=Qb/(Qa+Qb)I = Q_b/(Q_a + Q_b) is the order-book imbalance. With I=1/2I = 1/2 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 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) I=400/(400+300)=4/7I = 400/(400 + 300) = 4/7, so

Pmicro=100.00+0.02×47≈100.0114,P_{\text{micro}} = 100.00 + 0.02 \times \tfrac{4}{7} \approx 100.0114 ,

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 =Pb+(Pa−Pb) Qb/(Qa+Qb)= P_b + (P_a - P_b)\,Q_b/(Q_a + Q_b) 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).