A C++ implementation of a high-performance order matching engine with price-time priority.
order-matching-engine/
├── src/
│ ├── order_book/
│ │ ├── order.hpp
│ │ ├── order_book.hpp
│ │ ├── order_generator.hpp
│ │ └── trade.hpp
│ └── main.cpp
├── build/ # Build output directory
├── CMakeLists.txt # CMake build configuration
├── README.md # Project documentation
└── .gitignore # Git ignore file
- Supports both limit and market orders
- Price-time priority matching algorithm
- Real-time order book management
- Order operations:
- Add new orders
- Modify existing orders
- Cancel orders
- Trade execution and logging
- Random order generation for testing
For convenience, a shell script is provided to build and run the project:
# Make the script executable (first time only)
chmod +x build_and_run.sh
# Build and run the project
./build_and_run.shThe build_and_run.sh script automates:
- Creating build directory if it doesn't exist
- Running CMake configuration
- Building the project
- Running the executable
- Displaying the output
// Initialize order book
OrderBook orderBook;
// Create and add orders
Order buyOrder(OrderSide::BUY, 100.5, 10);
Order sellOrder(OrderSide::SELL, 100.0, 5);
orderBook.addOrder(buyOrder);
orderBook.addOrder(sellOrder);
// View order book state
orderBook.printOrderBook();
// View executed trades
orderBook.printTrades();The system includes an order generator for testing:
OrderGenerator generator(100.0); // Base price of 100
Order randomOrder = generator.generateOrder();This project is licensed under the MIT License.