A high-performance order matching engine built in C++ that supports limit orders, multi-threaded execution, and UDP-based order intake. This engine simulates a real-time financial trading system by efficiently processing buy and sell orders.
- Limit Order Matching: Supports limit buy and sell orders.
- Multi-threaded Processing: Handles multiple orders concurrently.
- UDP-Based Order Intake: Receives orders over a network using UDP.
- Persistent Order Book: Stores and reloads orders from disk.
- Performance Benchmarks: Provides tools to measure system efficiency.
order-matching/
├── benchmarks/ # Performance tests
│ ├── order_matching_benchmark.cpp
│ └── network_benchmark.cpp
├── docs/ # Documentation
│ ├── api.md
│ └── design.md
├── scripts/ # Helper scripts
│ ├── start_engine.sh
│ └── send_orders.sh
├── src/ # Core engine source code
│ ├── order.hpp
│ ├── order_book.hpp
│ ├── matching_engine.hpp
│ ├── network.hpp
│ ├── order_book.cpp
│ ├── matching_engine.cpp
│ ├── network.cpp
│ └── main.cpp
├── tests/ # Unit tests
│ ├── test_order_book.cpp
│ └── test_matching_engine.cpp
├── .gitignore
├── CMakeLists.txt
└── README.md
- C++17+ Compiler
- CMake (e.g., install via
sudo apt install cmakeon Linux or via Homebrew on macOS) - Netcat (for sending UDP test orders)
mkdir build && cd build
cmake ..
make./matching_engineExpected output:
Matching Engine running on port 8080...
In a separate terminal, run:
echo "buy 100.5 10" | nc -u -w1 127.0.0.1 8080
echo "sell 100.5 10" | nc -u -w1 127.0.0.1 8080The engine will output messages such as:
Trade executed: 10 units at price 100.5
No open orders for symbol: AAPL
./order_benchmarkExample output:
Processed 100000 orders in 0.56 seconds
./network_benchmarkExample output:
Sent 10000 UDP orders in 1.23 seconds
Run unit tests to verify functionality:
./order_book_test
./matching_engine_testFor detailed information on the classes, functions, and how to integrate with the Order Matching Engine, please see the API Documentation.
- Order: Represents individual buy or sell orders.
- OrderBook: Manages orders for a specific financial instrument.
- MatchingEngine: Oversees multiple
OrderBookinstances and processes incoming orders. - Network: Handles the reception of orders via UDP.
Client Network MatchingEngine OrderBook
| | | |
| -- Order --> | | |
| | -- Parse Order -->| |
| | | -- Route Order --> |
| | | | -- Match Order
| | | |
For more details, see docs/design.md.
MIT License. Feel free to modify and use.
- Your Name – GitHub Profile
- Email: xfb7hj@virginia.edu