finds.dev← search

// the find

fmstephe/matching_engine

★ 475 · Go · updated Feb 2022

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

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.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →