Limit Order Book Engine
A C++20 limit order book and matching engine with strict price-time priority, fixed-point prices and data structures chosen for predictable, cache-friendly latency.
- ops / sec
- 6.1M
- mean per op
- 163 ns
- p99 per op
- ≤ 542 ns
Median of 11 runs: 500K mixed ops on a 100K-order book over 5,000 levels per side, single thread on an Apple M3. p99 includes timer overhead, so it is an upper bound.
- Strict price-time priority: crossing limits sweep the book and rest the remainder, market orders fill IOC, and modifies follow exchange rules (size cuts keep queue position, reprices re-queue)
- Each
PriceLevelis both an AVL tree node and the head of an intrusive FIFO order queue, so a hash-mapped cancel is a pointer splice: O(1) average, O(log L) only when a level empties - 64-byte
OrderandPriceLevelrecords, pinned bystatic_assert, come from fixed-capacity memory pools and are never individually heap-allocated - Fail-safe API:
[[nodiscard]]status codes reject duplicate IDs, unknown IDs and zero quantities before any state changes; fills append to a caller-owned buffer; runs clean under ASan/UBSan
- C++20
- CMake
- Intrusive AVL
- Memory pools
- ASan/UBSan

