systems project // active development
Order Book [ Phase 04 // Core Matching Engine ]
I am building a correctness-first electronic limit order book in modern C++ because apparently my idea of a relaxing side project is asking, "what if a queue had opinions about fairness, latency, and the memory hierarchy?"
This is explicitly a current work in progress. It is not done, not polished, and not pretending to be a production exchange. The goal is to understand the infrastructure underneath modern markets: matching orders, preserving price-time priority, and designing data structures that do not make the CPU file a formal complaint.
As it grows, I am planning to add benchmarking, profiling, unit tests, market data feeds, replay tools, and progressively more performance-focused experiments. Less "hot stock tip," more "let me build the tiny engine room where the market plumbing lives."
[DONE] define orders and price levels
[DONE] store bids and asks in price priority
[DONE] preserve FIFO within each price level
[DONE] index active orders by ID
[ACTIVE] implement matching and trade generation
[QUEUED] test, replay, benchmark, and profile (before bragging about speed)
awaiting next commit
| Bid Size | Bid | Ask | Ask Size |
|---|---|---|---|
| 420 | 101.24 | 101.25 | 180 |
| 310 | 101.23 | 101.26 | 260 |
| 780 | 101.22 | 101.27 | 640 |
| 150 | 101.21 | 101.28 | 390 |
| 900 | 101.20 | 101.29 | 710 |
Inspect a component or submit an order to trace its path through the system. Order storage is the completed milestone; matching and trade generation are the next implementation phase, so this trace previews target behaviour rather than the live C++ engine.
A conceptual request flow from order submission through validation, matching, the order book, optional trade generation, and a submission result. This browser illustration does not execute the C++ project.
Bids high โ low // Asks low โ highstd::list<Order> // FIFOstd::unordered_map<OrderId, OrderLocation>Opposite price ordering keeps the best bid and ask at the front of their respective maps. Orders at each price retain FIFO priority, while the active-order index avoids scanning the entire book during cancellation and fill cleanup.
O(1)O(log P)AVG O(1)O(D)Browse the C++ implementation, tests, benchmarks, and build setup.
[ OPEN GITHUB REPOSITORY ]