Limit Order Book (LOB)
A limit order book (LOB) is a dynamic data structure that maintains and organizes all outstanding limit orders in a market. It records buy orders (bids) and sell orders (asks) at specific price levels, providing a real-time view of market depth and liquidity.
How a limit order book works
The limit order book consists of two sides:
- The bid side: Contains all buy orders, sorted by price (highest to lowest)
- The ask side: Contains all sell orders, sorted by price (lowest to highest)
Each price level maintains a queue of orders, typically processed in price-time priority. The difference between the best bid and best ask creates the bid-ask spread, a key measure of market liquidity.
Market depth representation
The LOB provides market depth information through multiple price levels:
- Level 1 (L1): Best bid and ask prices and quantities
- Level 2 (L2): Multiple price levels with aggregated quantities
- Level 3 (L3): Complete order-by-order detail
Next generation time-series database
QuestDB is an open-source time-series database optimized for market and heavy industry data. Built from scratch in Java and C++, it offers high-throughput ingestion and fast SQL queries with time-series extensions.
Price discovery and matching
When new orders arrive, the matching engine:
- Checks for possible matches against existing orders
- Executes trades when bid and ask prices cross
- Updates the order book state
- Disseminates market data updates
Market impact cost is directly related to how orders interact with the LOB's existing liquidity.
Order book analytics
Common LOB analytics include:
- Volume profile analysis
- Order flow imbalance
- Price pressure indicators
- Liquidity concentration metrics
These metrics help traders and algorithms assess market conditions and optimize execution strategies.
Time-series considerations
Order book data generates massive amounts of updates, requiring efficient:
- Data structures for real-time processing
- Storage solutions for historical analysis
- Compression techniques for archival
- Replay capabilities for backtesting
Tick data from order book updates forms the foundation for many trading strategies and market microstructure studies.
Market quality assessment
The LOB provides crucial indicators of market quality:
- Spread width and stability
- Market depth and resilience
- Price continuity
- Order book symmetry
These metrics help venues and regulators monitor market health and detect potential issues like flash crashes or market manipulation.
Trading system implementation
Modern trading systems must process LOB updates with minimal latency. Key considerations include:
- Memory-efficient data structures
- Lock-free algorithms
- Cache-friendly designs
- Network protocol optimization
Direct Market Access (DMA) systems particularly rely on efficient LOB processing for competitive performance.