A trading system consisting of a Trading Engine with price-time priority matching and an Order Client Server for handling order submissions.
TraderHub/
├── TradingEngine/ # Core matching engine implementation
├── OrderClientServer/ # Client-server interface for order management
└── build/ # Build outputs (created during build)
- CMake (>= 3.15)
- C++ Compiler supporting C++20
- Ninja build system
- gRPC
- Protocol Buffers
- GTest
- spdlog
- nlohmann_json
- Docker (optional, for containerized deployment)
# Update package list and install basic build tools
sudo apt update
sudo apt install -y build-essential cmake ninja-build
# Option 1: Install from package manager (Ubuntu)
sudo apt install libspdlog-dev
# Option 2: Build from source
git clone https://github.com/gabime/spdlog.git
cd spdlog
mkdir build && cd build
cmake ..
sudo make install
# Install dependencies
sudo apt update
sudo apt install -y build-essential autoconf libtool pkg-config
# Clone and install gRPC
git clone --recurse-submodules -b v1.42.0 https://github.com/grpc/grpc
cd grpc
mkdir -p cmake/build
cd cmake/build
cmake ../.. -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=/usr/local
make -j
sudo make install
# Install from package manager
sudo apt install libgtest-dev
# Build and install
cd /usr/src/gtest
sudo cmake CMakeLists.txt
sudo make
sudo cp lib/*.a /usr/lib
# Install from package manager
sudo apt install nlohmann-json3-dev
From the root TraderHub directory:
# Configure the build
cmake -B build -G Ninja
# Build all targets
cmake --build build
The project includes Docker support for easy deployment and testing. Make sure you have Docker and Docker Compose installed.
# Make the run script executable
chmod +x docker-run.sh
# Build the Docker images
./docker-run.sh build
# Start the server (in one terminal)
./docker-run.sh server
# In another terminal, run client commands:
./docker-run.sh client view # View all orders
./docker-run.sh client view AAPL # View AAPL orders
./docker-run.sh client submit order1 trader1 AAPL 150.50 100 buy # Submit order
./docker-run.sh client cancel order1 buy # Cancel order
./docker-run.sh client file orders.json # Process orders from file
# Clean up containers and networks when done
./docker-run.sh clean
From the build directory:
# Start the server
./OrderClientServer/OrderServer
# In another terminal, use the client
./OrderClientServer/OrderClient
./OrderClientServer/OrderClient submit <order_id> <trader_id> <symbol> <price> <quantity> <buy/sell>
./OrderClientServer/OrderClient cancel <order_id> <buy/sell>
./OrderClientServer/OrderClient view [symbol]
./OrderClientServer/OrderClient file <filename>
./OrderClientServer/OrderClient submit order1 trader1 AAPL 150.50 100 buy
./OrderClientServer/OrderClient cancel order1 buy
./OrderClientServer/OrderClient view AAPL
From the build directory:
cd TradingEngine
ctest --output-on-failure
# Or run test executables directly:
./unit_tests
./integration_tests
./performance_tests
cd OrderClientServer
ctest --output-on-failure
# Or run directly:
./OrderClientServerTests
- Price-time priority matching engine
- Order book management
- Trade execution
- Position tracking
- gRPC-based client-server architecture
- Order submission and cancellation
- Order book viewing
- JSON file-based order processing
- Unit tests go in
TradingEngine/tests/unit
orOrderClientServer/tests/
- Integration tests in
TradingEngine/tests/integration/
- Performance tests in
TradingEngine/tests/performance/
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug
cmake --build build
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build build
If CMake can't find a package, try adding the installation directory to CMAKE_PREFIX_PATH:
cmake -B build -G Ninja -DCMAKE_PREFIX_PATH=/usr/local
If you encounter permission issues during installation, make sure you have the necessary rights:
sudo ldconfig
If the client can't connect to the server:
- Ensure the server container is running (
docker ps
) - Wait a few seconds after starting the server before running client commands
- If issues persist, try cleaning up and rebuilding:
./docker-run.sh clean
./docker-run.sh build