A low-latency limit order matching engine with price-time priority, written in C++17 with zero external dependencies. Built to be a portfolio-grade demonstration of the systems that power electronic trading: an immutable order model, a deterministic matching core, a trade tape, and a WebSocket market-data feed.
┌──────────────────────────┐
Client order ──▶ │ Matching Engine (C++) │ ──▶ Trade tape
│ price-time priority │
│ FIFO within level │ ──▶ Order book depth
└──────────────────────────┘
│
▼
┌──────────────────────────┐
│ FastAPI + WebSocket │
│ REST /orders /depth │
│ WS /ws (live ticks) │
└──────────────────────────┘
⚡ Impact: 10.9M+ matches/sec (bench) · deterministic C++17 matching core, zero deps · price-time priority + FIFO · GTC / IOC / FOK · live trade tape + depth via FastAPI WebSocket
🖥️ Live demo: https://hobby-held-addition-plot.trycloudflare.com — submit orders and watch fills on the public REST API
Electronic exchanges and trading firms run on matching engines. This project demonstrates the core engineering problems that recur across low-latency systems:
- Price-time priority — best price first, FIFO within a level
- Order lifecycle — GTC / IOC / FOK, partial fills, cancellations, rejects
- Determinism — identical inputs produce identical fills (no floats, integer quantities)
- Observability — a trade tape + book-depth snapshots via callbacks
- Latency discipline — benchmark harness measuring µs/order throughput
| Order type | Time-in-force | Support |
|---|---|---|
LIMIT |
GTC / IOC / FOK | ✅ |
MARKET |
GTC / IOC / FOK | ✅ |
STOP |
GTC | ✅ (triggered on reference price) |
STOP_LIMIT |
GTC | ✅ (triggered on reference price) |
# 1. Build everything
make
# 2. Run the unit tests (no external framework)
make test
# 3. Interactive CLI — try: S 10 100 → B 10 50 → M B 25 → X <id> → q
./build/ome-cli
# 4. Latency / throughput benchmark (1,000,000 marketable orders)
make benchbench: 1000000 marketable orders in 1234.56 ms (1.23 us/order, 810000 orders/sec)
cd server
pip install -r requirements.txt
uvicorn main:app --reload --port 8000POST /orders— submit an order (JSON)DELETE /orders/{id}— cancelGET /depth— current book depthWS /ws— stream live trades + depth as they happen
├── engine/ # C++ core (no external deps)
│ ├── order.h # order model, enums
│ ├── types.h # fills, levels, accept results
│ ├── order_book.h # price-time priority book interface
│ ├── order_book.cpp
│ ├── matching_engine.h / .cpp
│ └── main.cpp # CLI demo + benchmark
├── tests/test_engine.cpp
├── server/ # FastAPI + WebSocket bridge
├── bench/ # benchmark notes
├── .github/workflows/ci.yml # build + test on every PR
└── Makefile
- Add a resting stop-order book (currently stops trigger on the last reference price only, which is a simplification)
- Lock-free queue between the engine and the feed publisher
- Persistence/audit log for every accepted order (WAL)
- Real
tcp_nodelayWebSocket fan-out with per-client backpressure
MIT — see LICENSE.
Contributions are welcome! For significant changes, please open an issue first to discuss the proposal.
- Fork the repository and create a feature branch.
- Make your changes (add tests where applicable).
- Ensure the CI workflow passes.
- Open a pull request with a clear description.
This project is released under the MIT License — see LICENSE.