A complete, multi-threaded real-time trading system built in C++
A high-performance, enterprise-grade trading system implementing core financial market infrastructure components. This system demonstrates advanced C++ programming techniques, real-time data processing, and financial software architecture patterns used in production trading environments.
- Multi-threaded Architecture: Concurrent order processing and GUI updates
- Real-time GUI: Live ImGui dashboard with order book visualization
- Risk Management: Pre-trade validation and position tracking
- WebSocket Integration: Real-time market data handling
- Cross-platform: Linux, Windows, and macOS support
|
|
30-second demo showing real-time order matching, GUI updates, and risk management
graph TB
A[WebSocket Market Data] --> B[Order Processing Thread]
B --> C[Risk Engine]
C --> D[Order Book Engine]
D --> E[Trade Execution]
E --> F[Position Update]
F --> G[GUI Dashboard]
D --> H[Order Book Display]
F --> I[Portfolio Panel]
E --> J[Trade History]
H --> G
I --> G
J --> G
style A fill:#e1f5fe
style D fill:#f3e5f5
style G fill:#e8f5e8
| Component | Description | Key Features |
|---|---|---|
| Order Book | Core matching engine | Price-time priority, O(log n) operations |
| WebSocket Client | Market data handler | Async I/O, message queuing |
| Risk Engine | Risk management | Pre-trade validation, position tracking |
| Dashboard | GUI visualization | Real-time updates, ImGui framework |
|
System Requirements
|
Dependencies
|
# 1. Clone the repository
git clone https://github.com/amank-23/cpp-trading-engine.git
cd cpp-trading-engine
# 2. Initialize submodules
git submodule update --init --recursive
# 3. Install dependencies (Ubuntu/Debian)
sudo apt update
sudo apt install -y build-essential cmake pkg-config
sudo apt install -y libboost-system-dev nlohmann-json3-dev libwebsocketpp-dev
sudo apt install -y libgtest-dev libglfw3-dev libgl1-mesa-dev
sudo apt install -y libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev
# 4. Build the project
mkdir build && cd build
cmake ..
make -j$(nproc)
# 5. Run the system
./TradingSystem🐳 Docker Installation
# Build Docker image
docker build -t trading-system .
# Run with GUI support (Linux)
docker run -it --rm \
-e DISPLAY=$DISPLAY \
-v /tmp/.X11-unix:/tmp/.X11-unix \
trading-system📦 Package Manager Installation
# Using vcpkg
vcpkg install boost nlohmann-json websocketpp gtest glfw3
# Using Conan
conan install . --install-folder=build --build=missing# Full system with GUI
./TradingSystem
# Backend-only test (no GUI required)
./BackendTest
# Unit tests
./RunTests
# Interactive launcher
../run.sh⚙️ System Configuration
// Risk management settings
RiskEngine risk_engine(80.0); // Max position size
// WebSocket connection
ws_client->connect("ws://your-market-data-feed.com");
// GUI settings
Dashboard dashboard(*order_book, *risk_engine);#include "order_book/OrderBook.h"
#include "risk/RiskEngine.h"
// Create components
auto order_book = std::make_shared<OrderBook>();
auto risk_engine = std::make_shared<RiskEngine>(100.0);
// Set up trade callback
order_book->on_trade([](const Trade& trade) {
std::cout << "Trade executed: " << trade.price
<< " x " << trade.quantity << std::endl;
});
// Create and add order
auto order = std::make_shared<Order>(
1, "BTC-USD", OrderType::LIMIT,
OrderSide::BUY, 50000.0, 1
);
if (risk_engine->check_pre_trade_risk(*order)) {
order_book->add_order(order);
}# Run unit tests
make test
# Or run directly
./RunTestsThe project includes unit tests for the OrderBook component using Google Test framework.
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) 2025 amank-23
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.



