Order Book Microstructure: The Mechanics of Liquidity and Matching

A deep dive into the Limit Order Book (LOB). Learn how matching engines process orders and how to model market impact at the microsecond level.

The Limit Order Book is where abstract trading strategies meet the physical reality of electronic execution. In electronic markets, the Limit Order Book (LOB) is the centralized record of all outstanding buy and sell interests for a specific security.

The book is divided into two sides: the Bids (buy orders) and the Asks (sell orders). The gap between the best bid ($P_b$) and the best ask ($P_a$) is the bid-ask spread. For an HFT market maker, the goal is to capture this spread while managing the risk of being picked off by more informed traders. We define the mid-price as: $P_{mid} = \frac{P_a + P_b}{2}$.

Most global exchanges, including the NSE, NYSE, and NASDAQ, operate on a Price-Time Priority (FIFO) basis. This means that an order at a better price is always executed before an order at a worse price. If two orders have the same price, the one that arrived first at the matching engine takes precedence.

This priority queue is why latency is non-negotiable. If you are 10 nanoseconds slower than a competitor, you will be behind them in the queue, reducing your fill probability for passive orders. Check our previous note on HFT physics and microsecond competition.

To achieve microsecond-level latency, we avoid dynamic memory allocation during the trading loop. We use a combination of doubly-linked lists for price levels and hash maps for O(1) order lookups.