NanoMatch
NanoMatch is a C++20 limit order book and matching engine for price-time priority matching. It supports Limit, Market, IOC and FOK orders, independent books per symbol, CSV input/output, and throughput and per-call latency benchmarks (adds that rest, adds that trade, cancels). The README reports 7.6 to 8.2 million operations/s on a GitHub-hosted runner (GCC 15.2) and 11.7 million on an idle Apple M2, one thread, synthetic workload in which every cancel removes a resting order; the book stays shallow in that workload. The order book does not use the standalone pool allocator, so the repository does not claim an allocation-free hot path.
01 / Overview
Problem
Exchanges match orders under tight latency budgets. NanoMatch is a from-scratch matching engine built to study the data structures and costs behind price-time priority.
My contribution
- Implemented price-time priority (FIFO) matching with support for Limit, Market, IOC, and FOK orders
- Implemented expected O(1) order-ID lookup, O(log M) cancellation through the price-level tree, and modification that keeps time priority for a quantity reduction and re-queues otherwise
- Built a standalone fixed-capacity pool allocator and a benchmark comparing it with new/delete
- Added multi-instrument support with independent order books per symbol
- 01C++20
- 02CMake 3.20+
- 03Google Test
- 04GitHub Actions CI/CD
- 05AddressSanitizer
- 06UBSan
02 / Evidence
Proof & Verification
- Repository-reported throughput: median 7,575,135 and 8,157,600 ops/s on two GitHub-hosted CI runs (GCC 15.2) and 11,723,239 on an idle Apple M2; Release -O3 -march=native, single thread, 5M synthetic operations, five runs each
- Latency benchmark reports p50/p99/p99.9 per call type; on CI p50 is 120-128 ns for an add that rests, 170-186 ns for an add that trades and 90-99 ns for a cancel, each including about 20 ns of clock overhead
- 170 Google Test cases in 20 test files, including a regression test per defect found in review and a randomized differential test; they pass in CI under ASan and UBSan
- CI config includes ASan, UBSan, cppcheck and clang-format checks for main-branch pushes and pull requests
Sources
Sources: Source Code03 / Methods
Build
Tech Stack
- C++20
- CMake 3.20+
- Google Test
- GitHub Actions CI/CD
- AddressSanitizer
- UBSan
- Price-time priority (FIFO) matching algorithm
- 4 order types: Limit, Market, IOC, Fill-or-Kill
- Expected O(1) order-ID lookup; cancellation also searches a price-level tree in O(log M); a quantity reduction keeps its place in the queue and any other modification re-queues the order
- Standalone fixed-capacity pool allocator with a separate allocation benchmark
Secure
- AddressSanitizer and UndefinedBehaviorSanitizer in CI
- 170 Google Test cases in 20 test files, including a regression test per defect found in review and a randomized differential test
- cppcheck static-analysis job configured for main-branch pushes and pull requests
- No external runtime dependencies