Skip to content

About

Header-only C++20 matching engine with strict price-time priority, an O(1) hierarchical-bitmap book, and allocation-free hot paths at a 10 ns median and 30 ns p99 submit latency.

Topics

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

239 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Orderbooks

Low-latency limit order book and matching engine. C++20 over Boost.Intrusive, designed for sub-microsecond order processing on Linux x86_64.

License: MIT C++20 CMake vcpkg Conventional Commits SemVer pre-commit

Scope

Engine

  • Strict price-time priority FIFO matching at every level.
  • Dense tick-ladder order book with hierarchical bitmap for O(1) best-bid / best-ask lookup.
  • Time-in-force coverage: GTC, IOC, FOK. Post-only and pegged on the roadmap.
  • Configurable self-cross policy: cancel-newest, cancel-oldest, decrement-trade.

Allocation and data structures

  • Slab arena over preallocated, cache-aligned storage; intrusive freelist removes runtime new/delete from the hot path.
  • boost::intrusive::list FIFOs at each price level; no node allocation per order.
  • Open-addressed robin-hood map (ankerl::unordered_dense::segmented_map) for order-id to order lookup on cancel and modify.
  • 2 MiB huge-page backing for the slab arena where the host allows, cutting data-TLB pressure during bursts, with a transparent fallback to regular pages and no change to the first-touch NUMA policy.

Concurrency

  • Single-threaded engine pinned to an isolated core.
  • Vyukov-style bounded SPSC ring at the ingress and egress boundaries, with heads and tails padded onto separate cache lines.
  • Multi-symbol support through a shard router over independent per-symbol engines.
  • Threaded shard runtime that drives each shard on its own worker thread, pinned to its own core, draining a dedicated SPSC ingress ring.
  • Optional per-shard egress rings. Each shard publishes events into its own SPSC ring without locks or contention.
  • Single-threaded merging consumer that fans the per-shard egress rings into one sequenced event stream for a downstream recorder or publisher.
  • Publisher-concept seam bridging the merged stream onto any publisher, so the runtime streams straight into the JSON Lines recorder unchanged.

Wire format

  • Zero-copy FIX 4.4 tag-value parser over std::span<const std::byte>, no allocations, no std::string. Tracked under a separate ADR.

Determinism and recovery

  • Monotonic sequence number on every command and event; replay from any prefix reproduces engine state bit-exactly.
  • Snapshot sink serialises the book to a flat POD layout for warm-start.

Observability

  • In-process HDR latency histogram (lob::latency_histogram) with O(1) allocation-free record and exact percentile queries for the engine's own timing loops.
  • just perfstat runs perf stat over the benchmark for IPC, branch-miss and L1-miss telemetry under a fixed-seed workload.
  • CI bench job records every run through github-action-benchmark and shows the comparison with the previous run on main in the job summary.

Build

Requires CMake 3.28, vcpkg in manifest mode, and a C++20 compiler (GCC 13+, Clang 17+, Apple Clang 15+).

git clone https://github.com/ZacKienzle2/Orderbooks
cd Orderbooks
cmake --preset linux-clang-rel
cmake --build --preset linux-clang-rel
ctest --preset linux-clang-rel --output-on-failure

macOS dev:

cmake --preset macos-clang-dev
cmake --build --preset macos-clang-dev
ctest --preset macos-clang-dev --output-on-failure

Benchmarks:

cmake --build --preset linux-clang-rel --target lob_bench
./build/linux-clang-rel/bench/lob_bench --benchmark_format=json | tee bench/last.json

Tooling harness

The Python package under src/orderbooks holds the analysis harness, which the engine does not depend on. orderbooks.viz reads event logs and draws plots and a Streamlit dashboard, and orderbooks.bench_ci computes benchmark statistics.

uv sync
uv run pytest

Repository layout

include/lob/    public headers (header-only domain types + engine ABI)
src/lob/        translation units (build-only internals)
src/orderbooks/ Python analysis harness (plots, dashboard, benchmark statistics)
tests/          Catch2 v3 unit + property tests, reference engine, replay fixtures
bench/          Google Benchmark microbenches with HDR latency counters
cmake/          warnings, sanitisers, hardening, dependencies modules
docs/           design specs, dev guides, ADRs

Contributing

See CONTRIBUTING.

License

MIT.

Related

Releases | ROADMAP | CITATION

About

Header-only C++20 matching engine with strict price-time priority, an O(1) hierarchical-bitmap book, and allocation-free hot paths at a 10 ns median and 30 ns p99 submit latency.

Topics

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages