Sub topic 4
Order Book, Depth and Liquidity
Prerequisites
Assume you understand shares, tickers, bid, ask, and spread. You should also know that a market order prioritizes getting filled, while a limit order sets a price boundary. This chapter explains what happens behind those quotes.
What an order book shows
An order book is a live list of unfilled orders for one security. It has two sides:
- Bids are buy orders. The highest bid is the best available buying price.
- Asks, also called offers, are sell orders. The lowest ask is the best available selling price.
The book usually ranks bids from highest to lowest and asks from lowest to highest. The gap between the best bid and best ask is the spread.
| Side | Price | Shares available |
|---|---|---|
| Ask | $50.10 | 500 |
| Ask | $50.05 | 200 |
| Ask | $50.02 | 100 |
| Bid | $49.98 | 150 |
| Bid | $49.95 | 300 |
| Bid | $49.90 | 600 |
In this example, the best ask is $50.02 and the best bid is $49.98. A market buy begins at the lowest ask. A market sell begins at the highest bid.
Depth and liquidity
Depth is the quantity available at different prices in the order book. A book with many shares close to the best bid and ask has more visible depth.
Liquidity describes how easily you can buy or sell without moving the price much. Depth is one sign of liquidity, but it is not a guarantee. Orders can be canceled, new orders can arrive, and trading activity can change quickly.
A market order larger than the shares at the best price consumes several price levels. This process is sometimes called walking the book. The resulting average price can be worse than the quote you saw.
Estimating a market buy
The following simulation shows why order size matters:
def fill_buy(asks, qty, limit=None):
filled, cost = 0, 0.0
for price, size in sorted(asks):
if limit is not None and price > limit:
break
take = min(size, qty - filled)
filled += take
cost += take * price
if filled == qty:
break
average = cost / filled if filled else None
return filled, average
asks = [(50.02, 100), (50.05, 200), (50.10, 500)]
print(fill_buy(asks, 400))
print(fill_buy(asks, 400, limit=50.05))The market order fills all 400 shares at an average near $50.055. The limit order fills only 300 shares because it refuses prices above $50.05.
Practical decision
For a small order in a highly liquid security, visible depth may be sufficient for a rough estimate. For a larger order or a thinly traded security, inspect several price levels and consider a limit order. A limit order controls the worst acceptable price, but it may remain partly or entirely unfilled.
Exercise
The asks are 100 shares at $20.00 and 300 shares at $20.10. What happens to a market buy for 250 shares?
Show answer
It fills 100 shares at $20.00 and 150 shares at $20.10. Its average price is $20.06.