A high-performance, low-latency matching engine for financial instruments, built with modern C++.
This project implements a sophisticated matching engine designed for speed and reliability. It operates on a client-server model, communicating over UNIX sockets to process buy and sell orders. The core of the engine is a powerful order book that matches trades based on a price-time priority algorithm, ensuring fair and efficient execution. The multi-threaded architecture allows for concurrent client connections, making it a scalable solution for real-time trading environments.
- High Performance: Engineered for low-latency order processing and matching.
- Price-Time Priority: Implements the standard algorithm for fair order execution.
- Concurrency: Utilizes a multi-threaded design to handle multiple clients simultaneously.
- UNIX Socket API: Provides a simple and efficient communication interface for clients.
- Order Types: Supports both Buy and Sell orders.
- Robust and Reliable: Designed for stability in high-throughput scenarios.
Follow these instructions to get the matching engine up and running on your local machine.
Ensure you have the following installed:
- A C++20 compatible compiler (the project is configured for
clang++) make
To compile the engine and client executables, simply run the make command from the project's root directory:
makeThis will place the engine and client binaries in the root directory.
Start the matching engine by providing a file path for the UNIX socket:
./engine /tmp/matching_engine.sockThe engine is now running and will listen for incoming client connections on the specified socket.
You can interact with the engine using the provided client application or by directly sending commands to the socket.
The engine accepts simple text-based commands for placing orders:
- Buy Order:
B <order_id> <instrument> <price> <quantity> - Sell Order:
S <order_id> <instrument> <price> <quantity>
Here is an example of a sequence of orders from tests/basic-example1.in:
1
o
S 123 GOOG 2700 10
S 124 GOOG 2701 25
B 125 GOOG 2705 30
x
This script first places two sell orders for Google stock and then a buy order at a higher price, which would trigger a match.
For a containerized setup, you can use the provided Docker configuration.
docker build -t CS3211/build -f Dockerfile.build .docker run --name build -v "./:/home/ubuntu/workspace" -it CS3211/builddocker rm -f buildThis project is licensed under the MIT License - see the LICENSE file for details.