Case study · Quant / Trading & Performance
ApexBook
Crypto execution and market-data engine in Go: paper matching against public L2 data

The problem
A depth stream cannot be applied to an empty map. Missed or misordered updates silently corrupt the local book, and matching on top of that book is meaningless. ApexBook makes snapshot/delta reconciliation, determinism, and pre-trade risk inspectable. It does not place real-money orders.
What I built
Snapshot/delta reconciliation
Buffer diffs, anchor on a REST snapshot, apply the bridging event, then require continuity. Any gap invalidates the book and forces a fresh snapshot. Stale events are discarded and counted.
Per-symbol actor model
One goroutine owns mutable state. Commands enter a bounded FIFO queue. Map iteration never influences execution order. Identical command sequences produce byte-identical fills and positions.
Paper matching
Price-time priority with LIMIT, MARKET, GTC, IOC, FOK, and post-only. Idempotent submissions. Pre-trade risk: kill switch, max notional, max quantity, max position.
Persistence and surfaces
Append-only fills, derived positions, PostgreSQL recovery of open orders in engine_seq order, REST, WebSocket, Prometheus, and an operator dashboard with an explicit demo snapshot.
Engineering decisions
Fixed-point money
All prices and quantities are int64 at scale 1e8. float64 never touches an economic value.
Honest durability window
Persistence is batched. A crash can lose accepted-but-unflushed events; that bound is documented rather than hidden.
Measured benchmarks, not slogans
On Windows 11, i3-1315U, Go 1.26.5: ApplyLevel 28.3 ns/op (0 allocs), match single fill 1.24 µs/op, end-to-end driver 34,761 cmd/s with p99 997 µs. Reproduce with make bench.
Testing & CI
make test covers unit, API, WebSocket, and reconciliation without Docker. make test-race. make test-integration uses Postgres testcontainers including TestRestartRecovery. Property tests cover remaining ≥ 0, fill conservation, and canceled orders never filling.
Screenshots

Overview
Feed health, paper activity, and system status from the operator dashboard

Order book
Local L2 book reconstructed from public Binance depth after snapshot/delta reconciliation

Execution
Paper fills against the local book: simulated matching, not live exchange orders
Go / PostgreSQL / WebSocket / Prometheus / fixed-point int64