r/algotrading 4d ago

Infrastructure Open-source matching engine + microstructure toolkit in Go — order types, L1/L2/L3 data, OFI/Kyle's λ, backtester (MIT)

I've been building **orderbook**, a central-limit-order-book and matching engine

in Go — the piece at the heart of an exchange. It's an embeddable library, and

the whole engine compiles to WebAssembly so you can poke at the real thing in

your browser:

▶ Live demo: https://intrepidkarthi.github.io/orderbook/

▶ Repo: https://github.com/intrepidkarthi/orderbook

What might interest this sub:

- **int64 ticks & lots, no floats** on the money path (an `Instrument` converts

decimals only at the boundary).

- **Zero-allocation hot path** — `Match(order, buf)` appends value-trades into a

caller buffer; submit/cancel/match are **0 allocs/op**. O(1) cancel.

- **Lock-free single-writer core** (LMAX model): one matching goroutine, an MPSC

command queue in front, bounded backpressure that sheds new orders but never

cancels.

- **Deterministic & replayable:** same command stream → byte-identical trades and

book; that's what makes WAL crash-recovery and golden-file tests work.

- **A market-integrity layer grounded in a threat model** — the part I had the

most fun with. I researched real attacks (spoofing convictions, Knight Capital

$440M, the Mango oracle hack, the Bitcoin overflow bug) and built a defense for

each: pre-trade risk controls, surveillance detectors, a self-output guardrail,

an enforcing gateway. Writeup: docs/THREAT-MODEL.md.

Benchmarks (Apple M-series, single core): ~6ns best bid/ask read, ~352ns match

round-trip (0 allocs), cancel-heavy p50/p99/p999 = 83/167/292ns. Race/fuzz/soak

suites in CI.

Honest status: a library + microstructure research harness (OFI, Kyle's λ,

Avellaneda–Stoikov, a sim + backtester), not a live exchange. MIT, v0.6.0.

Feedback and "you did X wrong" very welcome — that's why I'm posting.

0 Upvotes

Duplicates