Exova Academy

Module 1 — Advanced Market Structure · 35 min

Microstructure: Order Book, Liquidity and Market Makers

Video version of the lesson · the full text, code and solution are below.

Inès has been trading for two years. She reads charts correctly, knows her support and resistance levels, and yet her real results are consistently worse than what she records in her screenshots. When she buys "at market" during an announcement, her fill price is higher than expected. When she sets a tight stop on a small altcoin, it gets triggered and then the price bounces right back. The chart isn't the problem: what she can't see is the order book, the raw material every candle is made of.

Inès practices with a 10,000 USDT account, in paper trading and on testnet. Step one: understand how a price is formed.

The order book: what the candle doesn't show

On a centralized exchange, the price isn't a single value. It's where two queues meet:

  • the bids: limit buy orders, ranked from highest to lowest;
  • the asks (or offers): limit sell orders, ranked from lowest to highest.

The best bid and the best ask form the top of the book. The gap between them is the spread, and the midpoint is the mid price. The "last price" shown on the chart is simply the price of the most recent trade: it jumps between the bid and the ask depending on whether a buyer or a seller took the initiative.

Two families of orders face off:

  • a limit order waits in the book. It provides liquidity. It's called a maker order;
  • a market order executes immediately against resting orders. It consumes liquidity. It's a taker order.

Makers generally pay lower fees than takers. On a perpetual, a common fee schedule is around 0.02% maker and 0.05% taker; check the one that applies to your account.

%% titre: How a market order gets filled
%% narration: This diagram shows that a market order doesn't create a price: it consumes the limit orders already resting in the book, level after level, until it is completely filled.
flowchart LR
  A["Market buy order"] --> B{"Best ask large enough?"}
  B -- "yes" --> C["Filled at the best ask"]
  B -- "no" --> D["Consumes the next level"]
  D --> B
  C --> E["Average fill price"]
  D --> E
How a market order gets filled

Measuring liquidity: spread, depth and slippage

A liquid market is one where you can execute a given size without moving the price. Three measures are enough.

Relative spread: (ask − bid) / mid. On BTC/USDT at a major exchange, it's often below 0.01%. On a small cap, it can exceed 0.5%, which means a round trip already costs 0.5% before fees.

Depth: the cumulative quantity available within ±0.5% or ±1% of the mid. This is what tells you whether your size is "small" or "large" for that market.

Slippage: the difference between the reference price at the moment you decide and the average price you actually get.

Here's the hypothetical BTC/USDT book Inès is looking at:

Side Price (USDT) Quantity (BTC)
Ask 60,050 1.2
Ask 60,020 0.8
Ask 60,010 0.5
Bid 60,000 0.6
Bid 59,990 1.0

The spread is 10 USDT and the mid is 60,005 USDT. If Inès buys 1.5 BTC at market, she takes 0.5 BTC at 60,010, then 0.8 BTC at 60,020, then the remaining 0.2 BTC at 60,050. Total cost: 30,005 + 48,016 + 12,010 = 90,031 USDT, an average price of 60,020.67 USDT. Slippage versus the mid is 15.67 USDT, about 0.026%. On top of that come taker fees: 0.05% of 90,031, or 45.02 USDT. So the real execution cost is higher than the slippage alone.

The calculation takes just a few lines of code, which lets you apply it to a real order book fetched through an API:

def average_buy_price(asks, quantity):
    """asks: list of (price, quantity) sorted from best to worst."""
    remaining, cost = quantity, 0.0
    for price, qty in asks:
        taken = min(remaining, qty)
        cost += taken * price
        remaining -= taken
        if remaining <= 1e-12:
            return cost / quantity
    raise ValueError("Not enough depth for this size")

asks = [(60010, 0.5), (60020, 0.8), (60050, 1.2)]
avg = average_buy_price(asks, 1.5)
mid = (60000 + 60010) / 2
print(round(avg, 2), round((avg - mid) / mid * 100, 4))  # 60020.67 0.0261

With ccxt, exchange.fetch_order_book("BTC/USDT", limit=50) returns bids and asks lists of [price, quantity] that you can use directly.

Market makers: who provides liquidity and why

Most limit orders close to the price don't come from retail traders but from market makers. Their business model: buy at the bid, sell at the ask, pocket the spread and the maker rebates, while keeping their inventory as neutral as possible.

Three practical consequences for Inès:

  1. Displayed liquidity is conditional. A market maker pulls its orders as soon as risk rises (an announcement, a sharp move, liquidations). A book that's deep at 2:29 p.m. can be empty at 2:30 p.m.: slippage explodes right when you want to get out.
  2. Not everything displayed is meant to be executed. Large orders can be placed and then canceled to influence perception (spoofing). A big line in the book isn't a reliable "wall."
  3. Aggressive flow matters more than passive stock. Market orders are what move the price, which is why delta (aggressive buy volume minus aggressive sell volume) is useful.
%% titre: A market maker's cycle
%% narration: This diagram shows a market maker's logic: it quotes both sides, captures the spread, monitors its inventory and pulls its orders when the risk gets too high.
flowchart TD
  A["Quotes bid and ask"] --> B["Filled on one side"]
  B --> C["Unbalanced inventory"]
  C --> D{"Risk acceptable?"}
  D -- "yes" --> E["Adjusts its prices"]
  E --> A
  D -- "no" --> F["Pulls its orders"]
  F --> G["Thinner order book"]
A market maker's cycle

Common pitfalls

  • Judging liquidity by 24h volume. Part of the volume reported by some exchanges is artificial (wash trading). Depth within ±1% is a far more honest indicator.
  • Using a market stop on a thin asset. A triggered stop becomes a market order: in a thin book, it can fill very far from the intended level. Prefer sizes suited to the depth, or stop-limit orders while accepting the risk of not getting filled.
  • Ignoring the cost of a round trip. Slippage and fees on both sides can eat half the profit of a strategy that targets 0.3% per trade.

Hands-on practice

Goal: measure the real execution cost of a given size on two very different markets.

  1. Using ccxt (no API key needed, order book data is public), fetch the BTC/USDT order book and that of a small cap of your choice on the same exchange.
  2. For each one, calculate: the relative spread, the cumulative ask-side depth up to +0.5% from the mid, and the slippage of a market buy worth 5,000 USDT.
  3. Add taker fees of 0.1% (a typical spot fee schedule) and give the total cost of a round trip as a percentage.

Deliverable: a small two-row table (market, spread %, depth at +0.5%, slippage %, round-trip cost %) and two sentences of conclusion on the maximum reasonable size for Inès on the small cap.

Show solution

Reference script:

import ccxt

ex = ccxt.binance()  # public data, no key needed

def analyze(symbol, amount_usdt=5000, fees=0.001):
    ob = ex.fetch_order_book(symbol, limit=100)
    bid, ask = ob["bids"][0][0], ob["asks"][0][0]
    mid = (bid + ask) / 2
    spread = (ask - bid) / mid * 100
    depth = sum(p * q for p, q in ob["asks"] if p <= mid * 1.005)
    remaining, cost, qty = amount_usdt, 0.0, 0.0
    for p, q in ob["asks"]:
        value = min(remaining, p * q)
        cost += value
        qty += value / p
        remaining -= value
        if remaining <= 1e-9:
            break
    if remaining > 1e-9:
        return symbol, "not enough depth"
    slippage = (cost / qty - mid) / mid * 100
    # slippage measured from the mid already includes half the spread
    round_trip = 2 * slippage + 2 * fees * 100
    return symbol, round(spread, 4), round(depth), round(slippage, 4), round(round_trip, 3)

for s in ["BTC/USDT", "SMALL/USDT"]:  # replace with a real pair
    print(analyze(s))

The round-trip cost assumes the exit suffers the same slippage as the entry, which is optimistic in times of stress.

Typical results: on BTC/USDT, a spread of about 0.0002%, near-zero slippage, and a round-trip cost dominated by fees (about 0.2%). On a small cap, a spread of 0.1% to 0.5%, depth at +0.5% sometimes below 5,000 USDT, and a round-trip cost that can exceed 1%.

Expected conclusion: keep size below 10–20% of the depth at +0.5%. With 8,000 USDT of depth, Inès caps her entries at 1,000–1,500 USDT or splits them up with limit orders.

Key takeaways

  • The displayed price is the output of an order book: bids, asks, spread and depth determine what you'll actually pay.
  • A market order consumes liquidity level by level; its real cost = slippage + taker fees.
  • Liquidity provided by market makers disappears when risk rises, exactly when you need it.
  • Measure depth within ±0.5% or ±1% rather than 24h volume to judge a market.
  • Size your orders to the depth, especially stops on illiquid assets.

Enjoyed this lesson?

Unlock all 40 lessons, the quizzes and the certificate.

Buy — $297