Skip to content

About

Deterministic FIFO order-matching engine — header-only C++20, up to ~105M orders/sec per core, 120M across 8 shards

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

matcher-cpp

ci license

Deterministic FIFO limit order book and matching engine core — header-only C++20, measured at up to ~105M orders/sec batched on a cache-resident book (25M at 100k live orders, 14M at 1M; 44M on the mixed workload), and 120M orders/sec aggregate across 8 shards on a mixed workload (see spec/BENCH.md).

Single-writer book per symbol, commands in, monotonically sequenced events out. All I/O hangs off the Sink concept; there is no networking, persistence, or clock dependence in the core. Zero dependencies.

#include <matcher/matcher.hpp>
matcher::OrderBook book(matcher::BookConfig{});
matcher::VecSink sink;

book.apply(matcher::Command::new_limit(1, matcher::Side::Ask, 100, 10,
                                       matcher::Tif::Gtc), sink);
book.apply(matcher::Command::new_limit(2, matcher::Side::Bid, 100, 4,
                                       matcher::Tif::Gtc), sink);
// order 2 filled 4 @100 against order 1 and closed; order 1 keeps 6 resting.

Use it

Header-only, C++20 — add include/ to your include path, or via CMake:

add_subdirectory(matcher-cpp)
target_link_libraries(your_target PRIVATE matcher)
# or: cmake --install build, then find_package(matcher) → matcher::matcher

Features

  • Limit + Market orders, New / Cancel / Replace
  • GTC, IOC, FOK, Post-Only
  • FIFO price-time priority, maker-price execution, partial fills, sweeps
  • Pooled orders, intrusive FIFO price levels, bitmap ladder index with std::map fallback for unbounded prices
  • Enum-dispatched index — no virtual dispatch on the hot path
  • Thin multi-symbol Engine router
  • Deterministic event streams — verified byte-identically against the shared golden vector corpus (vectors/)

Layout

include/matcher/   headers (book, engine, types, sink, detail/internals)
tests/golden.cpp   golden vector runner
bench/             matcherbench harness
vectors/           shared golden corpus (spec repo: github.com/abhijitkrm/matcher)
spec/              semantics contract (SPEC.md, SCHEMA.md, BENCH.md)
tools/             vectorgen — deterministic workload generator

Test & bench

cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j
ctest --test-dir build --output-on-failure   # 43 golden vectors

# benchmark (see spec/BENCH.md)
mkdir -p bench/corpora
cargo run --release --manifest-path tools/vectorgen/Cargo.toml -- \
  --workload w2 --n 200000 --setup-n 100000 --out bench/corpora/w2
./build/matcherbench bench/corpora/w2

License

MIT OR Apache-2.0

About

Deterministic FIFO order-matching engine — header-only C++20, up to ~105M orders/sec per core, 120M across 8 shards

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages