Sub topic 1
Reading the Order Book
Prerequisites
This chapter assumes you have already bought and sold crypto on an exchange. You should know what a trading pair such as BTC/USDT is: BTC is the base asset being bought or sold, and USDT is the quote asset used to price it. You should also be able to read short Python programs. No other background is needed.
What the order book is
An order book is the live list of all unfilled limit orders for one trading pair on one exchange. Each entry says "I will buy (or sell) this much at this price or better." The exchange keeps a separate book for every pair, so BTC/USDT and ETH/USDT have different books.
The book has two sides:
- Bids are buy orders. Bidders want the lowest price they can get, so the highest bid is the most competitive one.
- Asks (also called offers) are sell orders. Sellers want the highest price, so the lowest ask is the most competitive one.
Orders in the book are called resting orders, because they sit and wait for someone to trade against them. Every price level shows the total size of all resting orders at that price. A level is one price and the combined quantity waiting there.
A small example book
Here is a simplified BTC/USDT book. Sizes are in BTC and prices are in USDT.
| Side | Price | Size | Cumulative size |
|---|---|---|---|
| Ask | 101.0 | 5.0 | 10.0 |
| Ask | 100.5 | 3.0 | 5.0 |
| Ask | 100.0 | 2.0 | 2.0 |
| Bid | 99.5 | 4.0 | 4.0 |
| Bid | 99.0 | 6.0 | 10.0 |
| Bid | 98.5 | 8.0 | 18.0 |
Most exchanges draw the asks above the bids, with the asks sorted so the cheapest is at the bottom, next to the bids. The gap in the middle is where trading happens. Cumulative size is the running total of size as you move away from the middle. It tells you how much quantity you can trade before reaching a given price.
Best bid, best ask, and the mid price
Three numbers summarize the top of the book:
- The best bid is the highest price any buyer currently offers. In the example it is 99.5.
- The best ask is the lowest price any seller currently accepts. In the example it is 100.0.
- The spread is the best ask minus the best bid: 100.0 − 99.5 = 0.5.
The best bid is always below the best ask. If a bid ever reached or exceeded the best ask, the two orders would match and trade immediately, so the book would no longer show them. That rule is why the book always has a gap, even if it is tiny.
The mid price is the average of the best bid and best ask, here 99.75. Many charts and "last price" displays are based on actual trades, not on the mid, so the two can differ. When you want to know what the market is worth right now, the mid price is a fair reference. When you want to know what you would actually pay or receive, look at the best ask (to buy) and the best bid (to sell).
Depth
Depth is how much quantity is resting at and near the top of the book. A deep book can absorb a large order without the price moving much. A thin book cannot.
Two books can have the same best bid and best ask and still behave very differently:
- Book A has 2 BTC at the best ask, then 3 BTC at the next price, then 5 BTC after that.
- Book B has 200 BTC at the best ask.
A buyer of 4 BTC pays more than the best ask in Book A. In Book B the same buyer pays exactly the best ask. The top-of-book prices are identical, but the depth is not. This is why you should look beyond the first line of the book before sending a large order.
Reading the book in code
The example below turns the book into numbers you can compute with. It assumes each side is a list of (price, size) tuples sorted from the best price outward.
bids = [(99.5, 4.0), (99.0, 6.0), (98.5, 8.0)] # best (highest) first
asks = [(100.0, 2.0), (100.5, 3.0), (101.0, 5.0)] # best (lowest) first
best_bid = bids[0][0]
best_ask = asks[0][0]
spread = best_ask - best_bid
mid = (best_ask + best_bid) / 2
spread_pct = spread / mid * 100
print(best_bid, best_ask) # 99.5 100.0
print(spread) # 0.5
print(mid) # 99.75
print(round(spread_pct, 3)) # 0.501
def cumulative_depth(levels):
"""Return (price, cumulative_size) pairs, moving away from the top of the book."""
total = 0.0
out = []
for price, size in levels:
total += size
out.append((price, total))
return out
print(cumulative_depth(asks)) # [(100.0, 2.0), (100.5, 5.0), (101.0, 10.0)]
print(cumulative_depth(bids)) # [(99.5, 4.0), (99.0, 10.0), (98.5, 18.0)]The spread as a percentage of the mid price is more useful than the raw spread. A spread of 0.5 is huge for an asset priced at 1.00 and negligible for one priced at 60,000.
Depth within a price band
A common way to measure depth is to add up the size within a fixed percentage of the mid price, for example 1%. This lets you compare liquidity across assets and exchanges.
bids = [(99.5, 4.0), (99.0, 6.0), (98.5, 8.0)]
asks = [(100.0, 2.0), (100.5, 3.0), (101.0, 5.0)]
mid = (bids[0][0] + asks[0][0]) / 2
def depth_within(levels, mid, pct, side):
"""Sum the size on one side within pct percent of the mid price."""
limit = pct / 100
total = 0.0
for price, size in levels:
distance = abs(price - mid) / mid
if distance <= limit:
total += size
return total
print(depth_within(bids, mid, 1.0, "bid")) # 10.0
print(depth_within(asks, mid, 1.0, "ask")) # 5.0At 1% around a mid of 99.75, bids down to about 98.75 and asks up to about 100.75 count. That includes the bids at 99.5 and 99.0, and the asks at 100.0 and 100.5. Those sums are 10.0 and 5.0. The levels at 98.5 and 101.0 fall outside the band.
If bid depth is much larger than ask depth within the band, buying pressure is resting on the book. Do not treat that as a reliable forecast. Resting orders can be cancelled at any moment.
What the book does not show
The order book is useful, but it is a partial picture. Keep these limits in mind:
- It shows intent, not commitment. Anyone can cancel a resting order before it fills. Large orders are sometimes placed to look like support or resistance and then pulled. This is called spoofing, and it is illegal on regulated markets, but it happens on crypto venues too.
- It hides some size. Some exchanges allow iceberg orders, where only part of the order is visible. Real depth can be larger than displayed.
- It is one exchange only. The same pair trades on many venues. Prices can differ by a small amount, and liquidity on another exchange does not help you here.
- It is a snapshot. A book on a busy pair can change many times per second. By the time you read a number and click, it may be different.
- Displayed levels may be grouped. Many interfaces let you aggregate prices into wider buckets, such as steps of 1.0 instead of 0.1. Aggregation makes the display cleaner but hides the exact best bid and ask.
Common mistakes when reading the book
- Confusing the last traded price with the price you will get. The last trade may have happened at the bid or the ask. A buyer who sees "last price 99.5" can still be asked to pay 100.0.
- Looking only at the best level. A market order larger than the size at the best level moves to the next level, and so on. The best ask is only the price for the first units.
- Mixing up which side you hit. A buy order matches against asks. A sell order matches against bids. Beginners often expect to buy at the bid.
- Ignoring units. Sizes may be in the base asset (BTC) or the quote asset (USDT), depending on the exchange and the view. Check the column header before doing arithmetic.
- Treating a thin book as a fair price. On a pair with little depth, a single order can move the best price by several percent.
How this connects to later chapters
The numbers you computed here feed directly into what follows. The spread is the first cost of trading immediately. The depth determines how far a large market order walks through the book. Limit orders place new entries into the book, and the matching engine decides which resting orders fill first. Each of those topics builds on the picture of bids, asks, and levels you now have.
Exercises
Exercise
Given asks of (50.0, 1.5), (50.2, 4.0), (50.5, 10.0) and bids of (49.8, 2.0), (49.5, 6.0), (49.0, 9.0), what are the best bid, best ask, spread, and mid price? How much can you buy before the price rises above 50.2?
Show answer
The best bid is 49.8 and the best ask is 50.0. The spread is 50.0 − 49.8 = 0.2. The mid price is (50.0 + 49.8) / 2 = 49.9. Buying against asks, you can take 1.5 at 50.0 and 4.0 at 50.2, so 5.5 units in total before reaching the 50.5 level.
Exercise
Two books for the same pair both show best bid 200.0 and best ask 200.2. Book X has 1 unit at each of the next three ask levels. Book Y has 100 units at the best ask. Which book is deeper, and why does the best ask alone not tell you this?
Show answer
Book Y is deeper at the top. The best bid and ask are the same in both books, so the spread is identical, but the best ask only gives the price of the first unit. Depth is the quantity available at each price. A buyer of 50 units pays about 200.2 in Book Y, while the same buyer in Book X would exhaust the three small levels and reach much worse prices.
Exercise
Write a Python function spread_pct(bids, asks) that returns the spread as a percentage of the mid price, assuming both lists are sorted best first. What does it return for bids = [(99.5, 4.0)] and asks = [(100.0, 2.0)]?
Show answer
def spreadpct(bids, asks): bestbid = bids[0][0] bestask = asks[0][0] mid = (bestbid + bestask) / 2 return (bestask - best_bid) / mid * 100 For the given inputs the spread is 0.5 and the mid is 99.75, so the function returns about 0.501.