A lightweight C++ trade matching engine built to simulate core exchange functionality such as order placement, matching, and order book management.
Implements price-time priority and supports both market and limit orders.
- Order Book Management: Efficient insertion and prioritization of buy/sell orders.
- Matching Engine Core: Matches orders using a price-time priority model.
- Randomized Market Simulation: Generates and processes hundreds of synthetic orders.
- Unit Testing Suite: Automated Catch2 tests for
Order,OrderBook, andMatchingEngine.
trade-matching/
├── CMakeLists.txt # Build configuration
├── engine/ # Core logic
│ ├── MatchingEngine.cpp/.hpp
│ ├── OrderBook.cpp/.hpp
│ ├── models/ # Data models (Order, Trade)
│ └── network/ # Placeholder for future server layer
├── src/
│ └── main.cpp # Entry point / market simulation
├── tests/ # Unit tests (Catch2)
│ ├── test_order.cpp
│ ├── test_orderbook.cpp
│ ├── test_engine.cpp
│ └── ...
└── build/ # Generated build artifacts (not tracked by Git)
- CMake ≥ 3.14
- C++17-compatible compiler (e.g., clang++, g++, MSVC)
From the project root:
rm -rf build
mkdir build && cd build
cmake ..
makeThis will build both:
main— the market simulation executablerunTests— the Catch2 unit test suite
ctest --output-on-failureAfter building:
./mainThis runs src/main.cpp, which:
- Generates 200 random buy/sell orders for ticker
AAPL. - Submits them to the
MatchingEngine. - Prints the final order book snapshot.
- Order Matching: Uses
std::priority_queuewith custom comparators to enforce correct price-time ordering. - Randomized Input: Market orders and limit orders are generated using C++
<random>utilities. - Thread-Safe Design (Future Work): Planned expansion to multithreaded order submission and socket-based networking layer.