What is an order book? Bids, asks and depth, explained with code

The order book is the beating heart of every market — the live, two-sided list of every resting buy and sell order at every price. It is what your bot’s order actually trades against, so understanding it is the difference between a backtest that assumes clean fills and a live bot that gets eaten alive by slippage. This guide explains exactly what bids, asks and depth are, how the book sets the price you fill at, how to read it with ccxt, and why book depth — not your signal — often decides whether a strategy survives.

On this page
  1. What the order book is
  2. Bids, asks and the spread
  3. Depth and the price ladder
  4. How your order fills
  5. Reading it with ccxt
  6. Why it matters for bots
  7. FAQ

What the order book is

An order book is the complete, real-time list of resting limit orders for a market: everyone who wants to buy below the current price, and everyone who wants to sell above it. The exchange’s matching engine pairs incoming orders against this book. When you place a market order, you are not trading against “the price” — you are trading against the orders sitting in the book.

Bids, asks and the spread

The bid side lists buyers; the ask side lists sellers. The highest bid and lowest ask are the best prices, and the gap between them is the bid-ask spread — a cost you pay every time you cross it with a market order.

ask 100.4 ask 100.3 ask 100.2 spread bid 100.1 bid 100.0 bid 99.9
Asks sit above the spread, bids below it; bar width is the size resting at each price — that is depth.

Depth and the price ladder

Each price level holds a quantity. Summed, those quantities are depth. A deep book has lots of size at each level, so a big order barely moves the price; a thin book has little, so the same order sweeps through several levels. Depth is liquidity, the topic of market liquidity.

How your order fills

A market buy takes the lowest ask, then the next, then the next, until it is filled — paying a worse price at each step. That walk up the book is slippage. A limit order, by contrast, joins the book and waits, paying no spread but risking no fill. The choice between them is covered in order types.

Reading the order book with ccxt

python · order_book.pyimport ccxt
ex = ccxt.binance()
book = ex.fetch_order_book('BTC/USDT', limit=10)

best_bid = book['bids'][0][0]
best_ask = book['asks'][0][0]
spread = best_ask - best_bid
print(f'spread: {spread:.2f}')

# total size on the first 10 ask levels = available depth
ask_depth = sum(qty for price, qty in book['asks'])
print(f'ask depth: {ask_depth}')

Why the order book matters for bots

A backtest usually assumes you fill at the close. The real order book decides whether that is true. On a deep BTC book it nearly is; on a thin altcoin it is a fantasy. Always check depth before sizing — a smart market-making or large-order bot lives entirely inside the book.

Not financial advice. This content is educational. Automated and algorithmic trading carries a real risk of financial loss. Never trade money you cannot afford to lose. Review the SEC investor.gov and CFTC resources before trading.

Frequently asked questions

What is an order book in trading?

An order book is the real-time, two-sided list of all resting limit orders for a market — every buyer below the current price (bids) and every seller above it (asks). The exchange matches incoming orders against this book. When you place a market order, you trade against the orders resting in the book, not against an abstract single price.

What is the difference between bids and asks?

Bids are resting buy orders, listed below the current price; asks are resting sell orders, listed above it. The highest bid and lowest ask are the best available prices, and the gap between them is the bid-ask spread. A market buy lifts asks; a market sell hits bids, each paying the spread to trade immediately.

What is order book depth?

Depth is the total quantity of orders resting at each price level, summed across the book. A deep book holds large size at each level, so a big order barely moves the price; a thin book holds little, so the same order sweeps through several levels and suffers slippage. Depth is effectively the market’s liquidity.

How do I read an order book with code?

Use ccxt: call fetch_order_book(symbol) to get bids and asks as price-quantity pairs sorted from best to worst. The first bid and first ask give you the best prices and the spread, and summing the quantities across levels gives you available depth — essential for checking whether your order size will cause slippage before you trade.

MB

Mustafa Bilgic

Algorithmic trading practitioner · Founder, AITradingBot.us

Mustafa builds and backtests automated trading systems and writes about them without the hype. Every tool on this site is free and runs entirely in your browser.