finds.dev

fmstephe/matching_engine

A simple financial trading matching engine. Built to learn more about how they work.

View on GitHub

★ 475Goupdated Feb 2022

// the take

A learning project implementing the core order-matching logic of a financial exchange — price-time priority, limit orders, and cancellations. It's not production-ready and the author is upfront about that. Good for developers wanting to understand how matching engines work internally without wading through a full system.

The dual-indexed red-black tree in pqueue is the real engineering here — one OrderNode living in two trees simultaneously (price-ordered and GUID-ordered) is a neat trick that makes O(log n) cancels possible without a secondary lookup. Invariant-based testing with random data is the right call for a data structure this subtle, and the author correctly notes it caught bugs that hand-written tests missed. Message-driven design where all state changes flow through a single message type makes the system trivially replayable, which matters for audit trails in financial systems. The README is unusually honest — the author explicitly calls out the bad design decisions they'd redo.

Abandoned in 2022 with half the networking layer sitting as `.disabled` files — the server, client, and trader code is all commented out, so you can't actually run this as anything beyond an in-process library. No order types beyond basic limit orders; no market orders, no IOC/FOK, no iceberg orders, which are all common requirements. The binary serialization is acknowledged as poorly designed and never finished. The coordinator abstraction embedding an interface into the matcher struct is exactly the kind of API mistake the author admits to — it's still in the code and would need rework before building on this.

We read the README, the directory tree and a key source file in June 2026. Nobody pays to be listed. How we judge →

// at a glance

Stars
475
Forks
125
Language
Go
Last commit
28 Feb 2022

// nearby

If matching_engine isn't quite it.

All repos →