Market Making and Liquidity Provision › Order Book Mechanics
Quantitative FinanceAll chapters Market Making and Liquidity Provision › Order Book MechanicsOne section · Sections in this chapter3 / 13 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
To understand market making, you need to understand the limit order book, the fundamental data structure that organizes trading in modern electronic markets. As we'll explore in more detail in the upcoming chapter on Market Microstructure, the order book aggregates all outstanding buy and sell orders at various price levels. Think of the order book as a ledger that records every participant's willingness to trade at specific prices, continuously updated as orders arrive, execute, or are cancelled.
A limit order book is an electronic record of all outstanding orders to buy or sell a security at specific prices. Buy orders (bids) are sorted from highest to lowest price, while sell orders (asks) are sorted from lowest to highest.
There are two primary order types that interact with this book structure:
- Limit orders specify a maximum price (for buys) or minimum price (for sells) and wait in the book until matched. You primarily use limit orders to post your quotes. These orders provide liquidity to the market: they sit passively in the book, waiting for someone else to trade against them. You don't know when or if your order will execute, but you do know the price you will receive if it does.
- Market orders execute immediately against the best available limit orders in the book. Traders demanding immediacy use market orders. These orders consume liquidity: they remove resting limit orders from the book. The market order submitter knows their order will execute immediately, but they don't control the exact price they will receive.
import numpy as np
import pandas as pd
# Simulate a simple order book snapshot
np.random.seed(42)
# Generate bid and ask levels around a mid price of 100
mid_price = 100.0
tick_size = 0.01
# Create price levels
bid_prices = np.arange(mid_price - 0.10, mid_price, tick_size)
ask_prices = np.arange(mid_price + 0.01, mid_price + 0.11, tick_size)
# Generate random quantities (typically more volume near the inside)
bid_quantities = np.random.exponential(scale=200, size=len(bid_prices))
bid_quantities = bid_quantities * np.linspace(
1.5, 0.5, len(bid_prices)
) # More at inside
ask_quantities = np.random.exponential(scale=200, size=len(ask_prices))
ask_quantities = ask_quantities * np.linspace(1.5, 0.5, len(ask_prices))
# Create order book DataFrame
order_book = pd.DataFrame(
{
"bid_price": np.round(bid_prices[::-1], 2),
"bid_qty": np.round(bid_quantities[::-1]).astype(int),
"ask_price": np.round(ask_prices, 2),
"ask_qty": np.round(ask_quantities).astype(int),
}
)
# Calculate best quotes and spread for display
best_bid = order_book["bid_price"].iloc[0]
best_ask = order_book["ask_price"].iloc[0]
spread = best_ask - best_bidOrder Book Snapshot
==================================================
Bid Qty Bid | Ask Ask Qty
--------------------------------------------------
123.0 99.99 | 100.01 6.0
112.0 99.98 | 100.02 973.0
291.0 99.97 | 100.03 457.0
10.0 99.96 | 100.04 56.0
32.0 99.95 | 100.05 42.0
--------------------------------------------------
Best Bid: 99.99
Best Ask: 100.01
Spread: 0.02The order book shows the best bid at $99.99 and the best ask at $100.01, creating a spread of $0.02. When you post at the inside (best bid and ask), your quote has priority over orders further from the mid price. This priority matters because orders at the same price typically execute in time priority, meaning the first order to arrive at a given price level executes first. When a market buy order arrives, it executes against the best ask; a market sell order executes against the best bid. This matching process continues until the incoming order is fully filled or the book is exhausted at that price level.

You must decide at which price levels to place your orders and how much size to offer. This decision involves a fundamental trade-off that shapes all market making strategies. Posting at the inside quote provides the highest probability of execution but the smallest profit per trade. Posting further from the mid price increases profit per trade but reduces execution probability. The optimal choice depends on many factors, including the volatility of the asset, the behavior of other market participants, and your current inventory position.