01 · C++20 · Matching engine
OrderBook
A price-time-priority limit order book. It replays a ClickHouse-backed trade tape and streams every fill as JSON, with a live browser depth ladder.
Personal code. It uses no proprietary data and no strategy parameters from any employer.

Where it came from
Built during a summer researching high-frequency backtesting infrastructure for A-share statistical arbitrage, where a fast order book and a ClickHouse columnar store were the two pieces of plumbing everything else depended on. This project is that order book, built out as a standalone matching engine.
The orderbook executable streams a configured ClickHouse table in chronological order, runs each row through the matching engine, and writes every trade to standard output as one JSON object per line. Source order IDs restart on each trading date, so it runs one matching engine per date. Completed session engines stay in memory, and orders from different dates can never match each other.
Matching
MatchingEngine accepts owned orders and keeps every buy and sell in its OrderBook, including filled and cancelled orders. Each execution is appended to Trades, so a partially filled order can appear in more than one trade record.
Recalling an order marks it CANCELLED without removing its queue entry. Matching and the depth ladder ignore cancelled orders, and stale queue entries are discarded lazily when matching reaches them.
By the numbers
Orders are looked up by ID in a hash map, so recalling an order is an average O(1) operation with no queue scan. Price levels sit in an ordered map, so opening a new level costs O(log levels).
The replay speed is 373,126 events per second, measured end to end: it includes ClickHouse retrieval, parsing, matching and caching the resulting trades. The engine-only figures below come from a synthetic order flow driven straight into MatchingEngine: 2 million orders, 76% passive limit orders near a drifting mid price, 12% spread-crossing orders and 12% recalls, on one core of an Intel Haswell VPS with -O2, timing each call with steady_clock. Three seeds gave 1.10 to 1.22 million orders per second, a median of about 255 ns per order, p99 of 7 to 9 µs and p99.9 near 30 µs. The worst single order took 39 to 54 ms. I have not profiled that tail; the usual suspect is a hash-table rehash while millions of orders are retained. This is not a replay of real data.
- 2.35M
- order events replayed over 20 trading days; all 1.27M exchange fills reproduced
- 373K/s
- events per second replaying real order flow, end to end including ClickHouse retrieval and parsing
- 1.1 to 1.2M/s
- engine only, synthetic flow, one core; median 255 ns per order
- 87
- assertions across two test executables
Live view
The executable opens a local browser GUI that polls every 100 ms. Trades are grouped into 100 ms intervals using their ClickHouse market timestamps, and the chart keeps every sample from program startup so the first point stays visible. A classic depth ladder shows five asks above the spread and five bids below it, best prices nearest the center, with total quantity at each level.
Backtest commissions
A second executable, backtest_commissions, reads commission rows through ClickHouse's HTTP interface using HTTP Basic auth, with connection details kept outside the source. Output is JSON Lines with values as strings, so ClickHouse decimals do not lose precision on the way out. Nullable values come through as JSON null.
If this is the kind of work you need, let's talk.
Coffee chat