Skip to content

Latest commit

Β 

History

History
82 lines (64 loc) Β· 2.34 KB

File metadata and controls

82 lines (64 loc) Β· 2.34 KB

Trade Matching Engine

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.


Features

  • 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, and MatchingEngine.

🧱 Project Structure

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)

Build Instructions

Prerequisites

  • CMake β‰₯ 3.14
  • C++17-compatible compiler (e.g., clang++, g++, MSVC)

Build

From the project root:

rm -rf build
mkdir build && cd build
cmake ..
make

This will build both:

  • main β€” the market simulation executable
  • runTests β€” the Catch2 unit test suite

Run Unit Tests

via CTest (recommended)

ctest --output-on-failure

Run the Market Simulation

After building:

./main

This runs src/main.cpp, which:

  1. Generates 200 random buy/sell orders for ticker AAPL.
  2. Submits them to the MatchingEngine.
  3. Prints the final order book snapshot.

Technical Notes

  • Order Matching: Uses std::priority_queue with 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.