A high-performance order book matching engine implementation in C++, designed to efficiently process and match buy/sell orders across multiple stock tickers.
This project implements a complete trading order book system with the following features:
- Multi-ticker order books: Maintains separate order books for each stock ticker
- Buy/Sell order matching: Implements price-time priority matching algorithm
- Order cancellation: Supports cancelling orders by order ID
- High-performance data structures: Uses AVL trees and object pools for efficient memory management
- Performance metrics: Tracks timing statistics for order insertion, matching, and cancellation
orderbook-simulator/
├── core_code/
│ ├── engine.h/cpp
│ ├── orderbook.h/cpp
│ ├── order.h
│ └── pricelevel.h
├── data_structures/
│ ├── avltree.h
│ └── vector_object_pool.h
├── data_handling/
│ ├── types.h
│ ├── constants.h
│ └── logger.h
├── main.cpp
├── data.csv
└── README.md
The program accepts a CSV file with the following format:
BUY,<TICKER>,<PRICE>,<QUANTITY>
SELL,<TICKER>,<PRICE>,<QUANTITY>
CANCEL,<TICKER>,<ORDER_ID>,BUY,DIS,119.88,1814
SELL,PYPL,261.01,217
CANCEL,JPM,10,Fields:
- Command:
BUY,SELL, orCANCEL - Ticker: Stock symbol (e.g., AAPL, GOOGL, MSFT)
- Price: Order price (for BUY/SELL only)
- Quantity: Number of shares (for BUY/SELL only)
- Order ID: Order identifier (for CANCEL only)
- C++17 compatible compiler (GCC 7+, Clang 5+, or MSVC 2017+)
- Standard C++ library
Compile with the following command:
g++ main.cpp core_code/engine.cpp core_code/orderbook.cpp \
-Icore_code -Idata_handling -Idata_structures \
-std=c++17 -O3 -march=native -o orderbook.exeExecute the compiled binary with a CSV input file:
./orderbook.exe data.csvThe program will:
- Read trading orders from the CSV file
- Process each order (BUY/SELL/CANCEL) sequentially
- Execute the matching algorithm after each operation
- Display performance statistics at the end
The program tracks and displays:
- Total insertion time (microseconds)
- Total matching time (microseconds)
- Total cancellation time (microseconds)
- Number of insertions and cancellations processed
- Results in terms of latency might differ in different Operation Systems due to the presence of different allocators and system timers.
MIT

