← Back to blog

All You Need to Know About Order Books

Abstract

With the release of my recent project, I wanted to dive deep into how order books are used both by the discretionary trader on a dashboard and from a quantitative, algorithmic approach.

Order Book Composition

An asset's order book is the set of resting buy and sell orders that have not yet been matched. In short: for every buyer of an asset, someone has to sell them the same amount (and vice versa). When orders can't be matched directly in the same size, they remain on the order book until they're cancelled or eventually matched.

For instance, if John wants to sell 20 shares of a $20 asset, he puts up an "ask" order on the order book for others to match. From there, either a single buyer purchases all 20 of his shares, or several buyers match the shares incrementally (each fill leaving fewer shares for others).

When we construct an order book to be analyzed, we usually structure it with the asset it refers to, the side the order takes (bid or ask), the type of order (see Types of Orders), the price for which the buyer/seller wants to execute their deal, as well as the amount of shares present looking for that price (a total of all buyers and sellers).

As an example:

SidePriceQuantity / SizeOrder Type
Ask / Sell$101.0040Limit
Ask / Sell$100.7525Limit
Ask / Sell$100.5010Limit
Bid / Buy$100.0015Limit
Bid / Buy$99.7530Limit
Bid / Buy$99.5050Limit

This set of orders lingers on the order book until matched by a counterparty, and the size of each order shrinks over time as pieces of it get filled.

Types of Orders

As you notice in the above example, each order in the order book not only has a side, but also an order type. Optiver published a good overview of each type of order, some more abstract than others, but most commonly we have two types of orders: Market and Limit.

Market Orders

A market order is an order to buy or sell a stock at the best price currently available in the order book. Market orders are primarily used by investors who wish to execute trades immediately. Using a market order normally ensures execution, but it doesn't guarantee what price you'll get.

Source: Optiver, "Orders and the Order Book"

Here, "best price" means the best price currently available on the market for whichever side you're on. Since there are two sides, we flip the logic for each:

For someone buying an asset, the goal is the lowest price that can actually be filled. So we look for the lowest price currently resting on the order book for the buyer to "fill", branching based on the size of the order:

This same process repeats for someone putting in a sell order, except now we're looking for the highest price someone is willing to buy the asset for on the order book, since that's optimal for the seller.

A big problem with the above process is slippage. If we submit a very large order all at once, we risk artificially driving the market to an unfavorable purchase price. This usually happens when there aren't enough orders resting at a favorable price. For instance, if I want to purchase 50 shares of an asset with an order book that looks like this:

SidePriceQuantity / SizeOrder Type
Ask / Sell$20.0010Limit
Ask / Sell$23.0020Limit
Ask / Sell$29.0030Limit

We start by filling the $20 ask, but there are only 10 shares there, so we walk up the book to $23 and then to $29 (taking 20 of the 30 shares resting at $29) until all 50 are filled. Our average fill price works out to:

$$(10 \times 20) + (20 \times 23) + (20 \times 29) = 1240$$ $$\text{Average Fill Price} = \$1240 / 50 = \$24.80$$

In total, we paid $4.80 per share of slippage relative to the initial best ask of $20.

Limit Orders

A limit order is an order to buy or sell a stock that specifies a maximum price to be paid or a minimum price to be received. An investor will use a limit order when they want to avoid the risk of transacting at an unexpected price. Unlike a market order, execution isn't assured. Any limit orders that aren't executed immediately appear in the order book.

Source: Optiver, "Orders and the Order Book"

The order book is built out of unfilled limit orders, since any unmatched limit order stays on the book until it is later matched by an incoming market order or an already-resting counterparty. When we buy an asset and know the maximum price we are willing to pay, we use a limit order rather than a market order. This lets us avoid paying worse than our limit price: our bid/ask defines the price we are willing to accept, and any remaining quantity can wait on the book instead of filling immediately at a worse price.

Price-Time Priority and Order Matching

A buy order and a sell order match if the buy price meets or goes above the sell price. From there, the computerized order-matching systems of different exchanges use a variety of methods to prioritize orders for matching.

Source: Investopedia, "Matching Orders"

The primary work of an exchange is to match compatible buy and sell orders for an asset. While the exchange handles the matching, additional liquidity (order size) is provided by market makers, institutions, and high-frequency trading firms whose limit orders make trading smoother. In our earlier slippage example, an institution could add size near the best ask so that a large buy order doesn't have to walk as far up the book.

When we talk about computerized order matching, most exchanges use a concept known as "price-time priority". As the name suggests, orders are matched and filled on a "first in, first out" basis, where "the earliest active buy order at the highest price takes priority over any subsequent order at that price" (Investopedia, "Matching Orders"). So among parties resting orders at the same price, the earliest order must be fully matched before the next party gets its turn.

Alternatively, an exchange can use pro-rata matching. Rather than fully executing each order based on the time it was submitted, a portion of multiple orders is used to match an incoming order. Here, larger orders receive a larger fill because they represent more of the resting size, while smaller orders still get partially filled.

For example, if both a 200-share buy order and a 50-share buy order at the same price are active when a compatible 200-share sell order arrives, the system will match 160 shares to the 200-share buy order and 40 shares to the 50-share buy order.

Since the sell order is not large enough to fulfill both buy orders, the system will partially fill both. In this case, the pro-rata matching algorithm fills 80 percent of each order.

Source: Investopedia, "Matching Orders"

These are only two of the common ways exchanges match orders. In practice, different asset types and exchanges can use different matching methods, often a hybrid of multiple methods. If you'd like to look into some more, I recommend this resource, which gives a high-level overview of what each algorithm is and when it's used.

Obtaining Order Book Data

Order book data is usually divided by what "data level" it sits at, ranging from level 1 to level 3. The table below gives an overview of each level (source):

Data LevelDetailsTypical Usage
Level 1Best bid and ask (top of book)High-level price display
Level 2Aggregated depth across multiple price levels, with price and volumeModeling slippage / execution risk and detecting imbalance
Level 3A full order-by-order feed keyed by order_idHFT, market-making, order-flow models — the most granular view available

Out of these, level 1 and level 2 data is most commonly provided directly by brokerages and data vendors, with level 3 being the most expensive to source and store long term. From my research, level 3 data is mainly reserved to institutions that are willing to pay the premium, most retail quantitative trading can be assumed to be completed by level 2 data at most.

For real-time market data, the New York Stock Exchange and NASDAQ provide their own solutions for receiving market data. Both are paid but available to retail investors at a hefty price. Currently, these two institutions only provide level 1 and level 2 data.

For academic access, LOBSTER provides order book data reconstructed from NASDAQ; although it is paid, it is the best solution for those looking to study order books further.

For cryptocurrency, Binance provides level 2 order book data through their API, while Coinbase reserves market data to institutional investors.

For prediction markets, both Kalshi and Polymarket provide live level 2 order book data for all of their markets.

I recently built a tool for generating SQL data from Kalshi prediction markets for analyzing historical order books, you can try it out here.

Quantitative Strategies Using Order Book Data

While the order book is a great source of information for informed, discretionary trading, quantitative strategies built on order book analysis have gained traction among institutional investors. These strategies are especially popular with those who can afford the cost that comes with real-time order book data.

Order Book and Order Flow Imbalance

The discussion of order book imbalance draws on the findings of Cont et al., who use high-frequency trade and quote records to tie asset price movements to order book imbalances (Cont et al., p. 2).

While order book imbalance refers to the amount of resting bid and ask orders, order flow imbalance is the derivative: the change in the bid and ask queues over time. Cont et al. argue that order flow imbalance is the more useful lens for investigating the impact of order book events (Cont et al., p. 3).

The paper makes the following claim:

the order flow imbalance (OFI), which represents the net order flow at the bid and ask and tracks changes in the size of the bid and ask queues by 1) increasing every time the bid size increases, the ask size decreases or the bid/ask prices increase 2) decreases every time the bid size decreases, the ask size increases or the bid/ask prices decrease.

Source: Cont et al., "The Price Impact of Order Book Events", p. 3

This ties order book movements in bid and ask size to asset pricing: a positive order flow imbalance (net positive change in bid orders) is associated with upward price pressure, while a negative order flow imbalance (net positive change in ask orders) is associated with downward price pressure.

The order flow imbalance metric is useful for understanding order book movement because it folds all order types, limit, market, and cancelled orders, into a single model-able variable, OFI (Cont et al., p. 3).

For more in-depth analysis, I highly recommend the Cont paper, as well as this high-level overview from OSQuant.

Spread Capture / Market Making

To discuss market making and how spread is captured for profit, we'll walk through Marco Avellaneda and Sasha Stoikov's 2006 paper, High-frequency trading in a limit order book. The piece works through optimizing a market-making strategy, discussing the approach, its risks, and its profitability.

Both Cont and Avellaneda and Stoikov refer to a market maker as a "dealer". A dealer provides liquidity (what I've been referring to as orders) to a market by posting bid and ask quotes, hoping to earn the difference between the price they buy at and the price they sell at. This way, they set a price they are willing to buy at and a slightly higher price they are willing to sell at, creating a spread between the two.

These small gaps are known as the "spread" on the order book. As an example, if the market maker posts bid and ask quotes with the bid priced at $18 (buying price) and the ask priced at $20 (selling price), subsequent fills on both sides would allow the market maker to buy at $18, sell at $20, and capture a $2 gross spread. As more players come into the market to compete for these fills, the smaller the spreads get, and the field is generally a game of large numbers or well-developed infrastructure.

Avellaneda and Stoikov highlight two risks of this strategy:

  1. Inventory risk (the focus of the paper)
  2. Information risk from informed traders

Both risks stem from the fact that capturing spread requires the dealer to actually hold or short the asset, so the asset's price becomes a major risk. With inventory risk, if a dealer buys an asset and it suddenly becomes cheaper, the dealer loses money on the drop in value. With information risk, market makers get picked off by "informed traders," traders who know something about the asset's future value that the market maker doesn't yet. These informed traders trade against the market maker's stale or mispriced quotes before it can update them. Below is an example of each:

1) Inventory risk

The market maker posts these two levels on the order book:

SidePriceQuantity / SizeOrder Type
Ask / Sell$20.0015Limit
Bid / Buy$18.0020Limit

Say the market maker's bid gets filled and it acquires 15 shares at $18 to later sell back to the market. If the asset then moves down to a $16 market price, the market maker loses $2 per share (unrealized) on everything it currently holds: \((18 - 16) \times 15 = 30\).

2) Information risk

The market maker posts these two levels on the order book:

SidePriceQuantity / SizeOrder Type
Ask / Sell$20.0015Limit
Bid / Buy$18.0020Limit

This is an identical order book to the previous example, but now the informed seller knows the price will move even lower than $18 soon after filling the market maker's quotes. To take advantage of this, the informed trader sells into the highest available bid (in this case the market maker's) just before the price falls to $16.

In these two scenarios, the outcome may be the same, but one focuses on the price moving against the dealer and the other focuses on someone purposefully filling orders to make the dealer hold more of the asset right before the price moves.

Most recently, Susquehanna International Group's prediction-market trading desk lost over $20 million mismanaging inventory risk on the 2026 NBA Championships. A heavy upset left the desk holding expensive contracts that became cheap in moments. Read more on Yahoo Finance.

Conclusion

The order book is a central piece of financial markets for analysis, order execution, and understanding how price is formed. While the data can be difficult to obtain for systematic, quantitative use, many brokerages provide a live view of the book for each asset on an exchange. Understanding the order book lets us quickly read market movement during times of high liquidity and action, even at a surface level.

Past the surface, quantitative analysis and trading rely on the order book both for informed strategy creation and for sustainable high-frequency order execution. As programmatic and quantitative investment continues to develop, market efficiency has improved in the order book thanks to the liquidity and competition it drives in the market-making space.

Healthy markets need order books with deep volume and order size to maintain optimal execution for investors. For many developing markets (such as prediction markets), the arrival of market makers and institutional investors greatly improves accessibility and the incentive for others to enter into new investments.

Thank you for reading this short piece on order books.