A high-performance limit order book simulator written in modern C++.
Implements millisecond-precision event handling, O(log n) inserts/cancels, and realistic market mechanics.
Designed for quantitative trading, backtesting, and microstructure analysis.
This engine maintains separate bid/ask trees using std::map (red–black trees) for price levels
and std::list for FIFO queues within each level, guaranteeing deterministic ordering and
accurate time priority. The simulator supports LIMIT, MARKET, and CANCEL orders with
complete trade and depth-of-book CSV logging.
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build . -j./orderbook_cli
# writes trades.csv and depth.csv in the working directoryctest --output-on-failure./bench
# prints throughput and writes bench_depth.csvBenchmark results (Release, Apple M3 Pro):
≈ 50 000 orders / second with >1 million total messages processed.
- Price maps
- Bids:
std::map<Price, PriceLevel, Desc>(descending order). - Asks:
std::map<Price, PriceLevel>(ascending order).
- Bids:
- FIFO Queues
std::list<Order>per price level for strict time priority.- O(1) cancels via id → iterator hash map.
- Integer arithmetic
- All prices/quantities in integer ticks for exactness
(price = 1000⇒100.0if tick = 0.1).
- All prices/quantities in integer ticks for exactness
- Execution rules
- Market orders cross only; limit orders cross then rest remainder.
- Outputs
trades.csv— execution log.depth.csv— level 2 snapshot for each event.
src/
├── orderbook.hpp / orderbook.cpp # Core matching logic
├── types.hpp # Price, Qty, Order structs
├── cli.cpp # Demo executable
├── bench.cpp # Benchmark tool
└── tests/ # GoogleTest unit tests
| Stack | Purpose |
|---|---|
| C++17 / STL | core data structures |
| CMake | build system |
| GoogleTest | unit testing |
| CSV I/O | data logging for analysis |
Alberto Rescigno
Durham University — MSci Computer Science & Mathematics
GitHub • LinkedIn
⚡ “Precision and determinism are the true benchmarks of a matching engine.”