Sub topic 1
How Order Books Work
Prerequisites
This chapter assumes that you know what a cryptocurrency exchange is, can read simple price and percentage values, and understand the difference between buying and selling an asset. The examples use a BTC/USDT market, where BTC is the base asset and USDT is the quote asset.
An order book is a live list of buy and sell orders for one trading pair. Buy orders are called bids. Sell orders are called asks, or offers. Each order states a price and an amount.
The highest bid is the most a buyer currently offers. The lowest ask is the least a seller currently accepts. If the highest bid is lower than the lowest ask, the difference is the spread.
| Side | Price | Amount |
|---|---|---|
| Ask | 60,010 USDT | 0.40 BTC |
| Ask | 60,005 USDT | 0.25 BTC |
| Bid | 60,000 USDT | 0.30 BTC |
| Bid | 59,995 USDT | 0.80 BTC |
In this example, the best bid is 60,000 USDT and the best ask is 60,005 USDT. The spread is 5 USDT. A trade happens when a buy order matches a sell order.
How the matching engine works
An exchange uses a matching engine, which is software that pairs compatible orders. A buy order can match an ask at the same price or a lower price. A sell order can match a bid at the same price or a higher price.
Most exchanges use price-time priority:
- The best price is considered first.
- If several orders have the same price, the oldest order is considered first.
- If the incoming order is larger than the available amount, it fills across multiple price levels.
Suppose you submit a market buy for 0.50 BTC using the order book above. The order consumes:
- 0.25 BTC at 60,005 USDT
- 0.25 BTC at 60,010 USDT
The order receives a weighted average execution price of 60,007.50 USDT. It does not buy the entire amount at the first displayed ask.
A limit order includes the worst price you will accept. A limit buy at 60,000 USDT can execute at 60,000 USDT or less. If no seller accepts that price, the order rests in the bid side of the book.
A market order accepts the best available prices until its amount is filled or the available liquidity runs out. The amount of price movement caused by consuming several levels is called slippage.
Reading the book correctly
The order book shows current resting orders, not a guarantee of future liquidity. Traders can cancel orders, and some venues support hidden or partially displayed orders. Large displayed orders can also be filled before you reach them.
The most recent trade price is different from the midpoint. The mid-price is:
\[ \text{mid-price} = \frac{\text{best bid}+\text{best ask}}{2} \]
For the example above, the mid-price is 60,002.50 USDT. It is a reference between the two executable prices. It is not necessarily a price at which you can immediately trade.
Exercise
The best bid is 2,000 USDT for 1 ETH, and the best ask is 2,005 USDT for 0.4 ETH. What happens when a market buy for 0.6 ETH arrives?
Show answer
It buys 0.4 ETH at 2,005 USDT, then consumes 0.2 ETH from the next ask level. Its average execution price depends on that next ask.