Skip to content
shaikhmubin02Public

About

A limit orderbook supporting multiple order types written in C++.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

Orderbook

C++20 limit order book and matching engine with price-time priority. Supports multiple order types, O(1) cancel via stored level iterators, optional Good-For-Day pruning, and a Google Benchmark / GoogleTest harness.

This is a correctness-first educational matcher (map-backed price levels, shared_ptr orders, optional mutex). Numbers below are single-threaded, in-memory and are not exchange wire-to-book latency.

Features

  • Order types: GTC, FAK, FOK, GFD, Market
  • Price-time priority matching with partial fills and execution reports
  • Cancel / modify with O(1) erase from a price level (list iterator in the order id map)
  • Optional mutex-backed API locking and GFD prune thread (OrderbookConfig)
  • OrderPool to reuse Order storage and cut heap churn on hot paths
  • Scenario + invariant tests, Google Benchmark targets

Requirements

  • CMake 3.20+
  • C++20 compiler (GCC/MinGW 14+, Clang, or MSVC)
  • Git (FetchContent pulls GoogleTest and Google Benchmark)

Visual Studio solution (Orderbook.sln) remains available; CMake is the recommended path for tests and benches.

Build

cmake -G "MinGW Makefiles" -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=g++
cmake --build build -j
Target Description
orderbook Core library
orderbook_demo Small smoke demo
orderbook_tests Unit / scenario tests
orderbook_bench Throughput and latency benchmarks
cmake -B build -DORDERBOOK_BUILD_TESTS=OFF -DORDERBOOK_BUILD_BENCH=OFF

Tests

./build/orderbook_tests

Covers 7 file scenarios (GTC/FAK/FOK/Market/Cancel/Modify) plus invariants: price-time FIFO, FOK miss leaves book unchanged, cancel of missing id, partial-fill size/qty consistency, and order pool reuse (12 tests).

Benchmarks

./build/orderbook_bench

Measured on a modern desktop (Release, prune thread off, locking off, OrderPool, in-memory):

Path Approx. rate / latency
Resting GTC add ~1.9M ops/s
Cancel by id ~7.6M ops/s
Aggressive match (crossed) ~1.3M ops/s
Add + cancel median ~400 ns, p99 ~700 ns

Layout

Orderbook.{h,cpp}     matching engine
Order.h / OrderPool.h order + preallocated pool
OrderbookTest/        original MSVC scenario files
tests/                GoogleTest (invariants + scenarios)
bench/                Google Benchmark

License

See LICENSE.

About

A limit orderbook supporting multiple order types written in C++.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages