A Python implementation of an exchange-like limit order book with full Level 3 (per-order) depth, Level 2 (aggregated) snapshots, and a price–time priority matching engine.
This project is designed to demonstrate core market microstructure concepts such as FIFO matching, partial fills, order lifecycle management, and event-driven execution — similar to how real electronic exchanges operate.
- Price–time priority (best price first, FIFO within price)
- Supports LIMIT and MARKET orders
- Partial fills and multi-fill execution
- Market-neutral matching logic (no crossing errors)
- NEW
- REST
- PARTIAL FILL
- FILLED
- CANCELED
- REPLACED
- REJECTED
- O(1) cancel and replace using intrusive linked lists
- Efficient per-price FIFO queues
- Sorted price ladders for best bid / best ask lookup
- Level 3 (L3): full per-order queues at each price level
- Level 2 (L2): aggregated depth by price
- Top-of-book (best bid / best ask)
- Exchange-style event stream:
NEW,TRADE,FILL,PARTIAL,CANCEL,REPLACE,REJECT
- Suitable for simulation, backtesting, or latency modeling