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.