Trading engine
A trading engine written in C++. It tests a trading strategy on recorded market prices and works out the price each trade would have gotten. The same strategy code then runs on live prices.
Result: Replays four hours of recorded market data in 15 seconds
Independent engine with a live exchange connection.
Walkthrough 1:02
Earlier simulator and charting interface. The current C++23 engine is described below. This footage does not demonstrate live execution.
- Who it is for
- People who write trading strategies and want to test them on recorded market data before real money is involved.
Engineering details How it works and the decisions behind it
- Independent project
- Source code is private
- Problem
- Restarting a trading process meant recomputing every indicator and losing track of orders already at the exchange.
- Engineering decision
- Built a C++23 engine with a persistent indicator cache and order-journal recovery. A versioned C ABI lets strategy plugins share the same interface across replay and exchange integrations.
- Measured evidence
- Decisions in about a microsecond at the 99th percentile, Sep 2026
- My role
- Engineer, independent systems project
- Source access
- Private repository
What it does
- Persistent indicators
- Memory-mapped storage saves calculation progress for the next run.
- Order recovery
- Journal replay rebuilds local order state before exchange reconciliation.
- Strategy plugins
- A versioned C ABI checks compatibility when a strategy library loads.
- Replay adapters
- An interchangeable clock and market interfaces support historical replay.
Give replay and exchange integrations the same boundaries
Market data and order execution sit behind explicit interfaces, with an interchangeable clock for replay. This lets a strategy use the same interface against historical data and exchange adapters. Strategy plugins load through a versioned C ABI, which makes compatibility checks explicit at the library boundary.
Orders cross threads through a single-producer, single-consumer ring. The repository has a live exchange integration.
Recover state after an interruption
The indicator cache stores calculation progress in memory-mapped files. On restart, it can resume from the stored input position instead of recalculating the entire history.
Order recovery replays a journal into a fresh order-management system. Reconciliation compares local orders with the exchange's state, including fills that occurred during downtime and orders the exchange no longer reports.
A missing order is not enough evidence to cancel it locally. The recovery tests check that uncertain exchange state does not invent a fill. They also check that an order filled in part and then cancelled keeps both its fill history and its final cancelled status.
Tests exercise those recovery cases and reopen persisted stores after writes. That verifies restart behavior. It does not simulate a physical power failure. Sanitizer builds check memory errors and data races.
Profile the bottleneck
In an earlier simulator, allocation on the ingestion path limited how much history a backtest could process. Linux profiling directed the work toward container sizing and ownership. Preallocating storage and moving data instead of copying it removed that bottleneck. Pooling database connections reduced repeated setup work.
The changes allowed longer backtests without the same allocation bottleneck.
Build on exchange-integration experience
The project began with open-source contributions to zenbot in 2016. Merged pull requests #28 corrected the altcoin pair graph and #34 added USDT trading pairs.
Subsequent versions added a C++ feed handler with gap detection and backfilling, followed by a backtesting simulator with an order book and charting interface. That work informed the boundaries in the current engine.
Decisions in about a microsecond at the 99th percentile
Measured Sep 2026
- Replay. An observed four-hour live exchange capture, 1.53 million receipts across eight assets, replayed in 15.19 seconds, about 950 times real time. The trace and the recovered account matched byte for byte across both input paths. Measured Sep 18, 2026.
- Decision latency. Across 263,200 recorded inputs, with the order queue, execution engine and order management in the loop, the 99th-percentile decision took 1.25 microseconds. Measured Sep 18, 2026 on 100 fresh hosts.
- Throughput and charting. A synthetic single-thread benchmark ingested 70.2 million events a second on a Ryzen 9 7950X on Sep 9. The Vulkan chart redrew a million candles at about 18,000 frames a second on an RTX 4080 on Aug 19.
These are replay and benchmark measurements on recorded or synthetic data. They exclude exchange network latency, and the chart figure comes from an offscreen benchmark.
Source revision 5a4f89d
Email is the best way to reach me. I usually reply within a day. alandevaney@gmail.com