Strategy Engine
The Go engine behind backtests, paper trading and live crypto orders. I made it faster and harder to break.
- Context
- Built at a crypto derivatives exchange
- Year
- 2026
- Role
- Second-largest contributor; led the worker decomposition and the performance work
- Stack
- Go, proto-actor, MySQL, TimescaleDB
The problem
Traders write a strategy once and run it as a two-year backtest, on live data with simulated fills, and with real money on futures and multi-leg options. A teammate designed the engine. I joined in August 2026 and took on the parts that decide whether live trading stays fast and correct under load and failure: the run worker, the order path, the database load and the backtest hot loop.
- Backtest, paper and live must stay identical after every change.
- Live trading must never guess when the exchange is ambiguous.
- Every performance change ships with byte-identical golden output, and every benchmark says where it was measured.
Architecture
What I built
- 01Broke the live-trading run worker into a non-blocking status board, an order-desk actor, typed engine facts and a write-ahead LIVE order journal, across a six-PR stack.
- 02Rewrote the backtest hot loop to stop allocating per bar, and tuned the market-data WebSocket hub, indicator inputs and the catalog build.
- 03Found and fixed the scans and missing indexes that pinned the production MySQL server at its disk IOPS limit.
- 04Hardened the LIVE fill-claim ledger (co-developed with a teammate) and run ownership, so sibling runs and failover workers cannot double-book a close or trade one account twice.
- 05Launched XAUT gold options behind a switch, with a validated per-asset registry for settlement times, listings and opening auctions.
- 06Shipped fixes for production incidents: half-filled straddles on OI-capped strikes, short options run at the wrong leverage, and a customer-reported expiry roll bug.
By the numbers
- faster options backtests per bar
- 7.5×
- faster heartbeat round with a stuck run, fake-exchange test
- 45×
- faster per-fill trade lookup
- 18×
- of the engine's surviving Go code, written in 3 months
- 28.5%
Hard problems
01
One slow order stalled every run on the worker
The run worker saved every run's heartbeat in one round, so a single run waiting on a slow order held up all the others. I split it into a status board the coordinator reads without waiting, an order desk that owns venue calls, typed engine facts and a journal written before any LIVE order leaves. With one stuck run among 50, the save round went from 5,148 ms to 113 ms in a fake-exchange test, and a lost entry reply can no longer open a second position.
02
7.5× faster options backtests, same trades
Options backtests spent most of each bar building keys, copying the chain into maps and copying trade logs. Removing those cut time per bar from 11.3 µs to 1.5 µs and allocations by 94%, measured with a per-bar Go benchmark I added and re-run independently. Golden trade logs stayed byte-identical. Futures gained less, about 1.4×, because they never paid the chain cost.
03
A database pinned at its disk limit
Single-row updates averaged 16 ms and heartbeats deadlocked 1,451 times in a day. Every worker was re-scanning every run each second. Slimming the orphan and detach scans and adding four composite indexes cut bytes and index reads by 95 to 99%, and made the per-fill trade lookup 18× faster, measured on a 200k-run copy of the production schema.
04
Half a straddle, bought back at a loss
When a strike hit its open-interest cap, the venue refused one leg after the other had filled, and the engine unwound the filled leg at a loss, often daily. I shipped a master hotfix: a parallel 2-second pre-flight check of every leg before either is sent, so a capped strike now skips the entry instead of leaving half a straddle to unwind at a loss, and the owner is told why.