Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

136 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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, cache-line padded heads and tails, no false sharing.
  • Multi-symbol scalability via per-symbol 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 so each shard publishes events into its own SPSC ring, keeping the publish path lock-free and contention-free.
  • 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

  • Latency histograms via nanobench for tail-aware p50 / p99 / p99.9.
  • 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.
  • scripts/perfstat.sh wraps perf stat for IPC, branch-miss and L1-miss telemetry under a fixed-seed workload.
  • CI bench job gates throughput regressions against bench/baseline.json.

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

A .venv exists for repo tooling only: pre-commit, clang-format, cmake-format, ruff, pytest for harness scripts, pandas and matplotlib for latency analysis. It is not a runtime dependency.

uv sync --frozen
uv run pre-commit install --install-hooks

Repository layout

include/lob/    public headers (header-only domain types + engine ABI)
src/lob/        translation units (build-only internals)
tests/          Catch2 v3 unit + property tests, reference engine, replay fixtures
bench/          Google Benchmark microbenches + nanobench tail reports
cmake/          warnings, sanitisers, hardening, dependencies modules
scripts/        perfstat, formatting, lint, replay helpers
docs/           design specs, dev guides, ADRs

Maintainers

See CODEOWNERS.

Contributing

See CONTRIBUTING.md. Conventional Commits 1.0.0 and DCO sign-off required.

License

MIT.

Related

SECURITY | SUPPORT | GOVERNANCE | CHANGELOG | 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

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages