Low-Latency Market-Making Engine
A deterministic single-queue event loop with explicit latency and fill models, built so that a naive quoting strategy loses money for the right reasons.
At a glance
- Engine
- C++20, event-driven
- Unit tests
- 28 cases, 109 assertions
- Latency model
- explicit, both directions
- Sample run on a random walk
- loses, by design
About this project
A modular C++20 prototype of the patterns found in a production market-making stack: a top-of-book-plus-depth order book, a CSV market-data feed, an OMS with position tracking and P&L attribution, a pre-trade risk gate with a kill switch, an exchange simulator with acknowledgement and fill latency, an inventory-aware market-maker, and a replay backtest driver on a single timestamp-ordered event bus. 28 Catch2 test cases, 109 assertions. It is a learning and portfolio piece, not an HFT system, and the README says so.
Why it matters
Market-making economics are decided by fill assumptions, latency and adverse selection, not by the quoting formula. An engine whose modules have clean boundaries lets each of those be changed independently and tested, which is what makes the result of any strategy experiment interpretable.
Methodology
- std::variant event types dispatched through a deterministic priority queue; strategy-to-exchange and exchange-to-strategy latency are modelled explicitly and re-scheduled by the driver.
- Order book with top-of-book and depth, OMS state machine with acknowledgement, partial fill, cancel and rejection paths, and position and P&L attribution in ticks.
- Pre-trade risk gate on position, order size, open quantity and drawdown with a kill switch; exchange simulator with marketable and passive fill logic.
- Inventory-skewed market-maker with configurable half-spread, quote size and requote threshold; synthetic feed generators (random walk, stable, oscillating) and a PnL/inventory plotter.
Strongest findings
- On the random-walk feed the default strategy loses money by construction, to adverse selection; the engine reports it rather than hiding it, which is the point of the exercise.
- The unit-test suite covers the order book, OMS, risk gate, simulator and strategy (28 cases, 109 assertions) and passes with clang++ on macOS and g++ on Linux.
Figures

Figure 1. Sample run on the bundled random-walk feed with the default config (5,000 events, 53 fills): mid, net position and total PnL in ticks. The strategy loses to adverse selection, as a naive quoter on a random walk should.
Robustness and caveats
- Educational scope: synthetic top-of-book feeds, no queue-position model, no real exchange protocol, no production latency engineering.
- A queue-aware extension on real CME market-by-order data is planned and blocked on a paid data pull; it is not part of this repository.
Challenges
Designing clean module boundaries (book / OMS / risk / simulator), keeping the event loop deterministic, and modelling fills and latency realistically.
Learnings
Market microstructure, low-latency systems design in C++, and how adverse selection punishes a naive quoting strategy.