A high-performance, multi-threaded trading bot written in modern C++ (C++17) for stocks and futures. This project showcases the core components of a production-grade trading system: real-time market data ingestion, order management, risk controls, strategy execution, backtesting, and concurrency for low-latency performance.
- Modular Design
- MarketDataHandler: Simulates live market data or replays historical CSV data for backtesting.
- OrderManager: Places, logs, and tracks orders with an internal order history.
- RiskManager: Enforces exposure limits and rejects orders that exceed risk thresholds.
- StrategyEngine: Implements a moving average crossover strategy with configurable short/long windows.
- Backtesting Engine: Runs strategies against historical data to validate performance.
- Concurrency: Separates data feed, strategy logic, and order execution into distinct threads for realistic, low-latency operation.
Trading-Bot-Full-Functionality/
├── include/
│ ├── MarketDataHandler.h # Market data interfaces
│ ├── OrderManager.h # Order placement & tracking
│ ├── RiskManager.h # Exposure and risk checks
│ └── StrategyEngine.h # Trading logic (MA crossover)
├── src/
│ ├── MarketDataHandler.cpp
│ ├── OrderManager.cpp
│ ├── RiskManager.cpp
│ ├── StrategyEngine.cpp
│ └── main.cpp # Entry point & orchestration
├── data/ # Sample CSV data for backtesting
├── Makefile # Build automation
└── README.md # This document
- C++17-compatible compiler (GCC, Clang, MSVC)
makeorcmake- [Optional] Python (for advanced analytics or plotting)
-
Clone the repository
git clone https://github.com/Saurav756/Trading-Bot-Full-Functionality.git cd Trading-Bot-Full-Functionality -
Build with Make
make
-
Clean build artifacts
make clean
By default, the bot runs in live-simulation mode:
./tradingbot- Spawns a market data thread that simulates price ticks.
- Feeds each tick to the StrategyEngine.
- Logs order placements and risk rejections to the console.
To replay historical data, modify main.cpp:
// Replace live simulation
// mdh.simulateData();
// With CSV backtesting
mdh.loadFromCSV("data/data.csv");Rebuild and run:
make && ./tradingbotAll CSV ticks are processed in sequence, and executed orders are logged for offline analysis.
- Risk Limit: Adjust the maximum exposure in
main.cppwhen constructingRiskManager. - Strategy Parameters: Tweak
shortWindowandlongWindowinStrategyEngineto refine signal sensitivity. - Subscribed Symbols: Add or remove symbols by calling
mdh.subscribe("SYMBOL", callback)inmain.cpp.
- Add New Strategies: Create new strategy classes following the same callback pattern.
- Live Market Integration: Replace
simulateData()with a real API connector (FIX, WebSocket). - Persistent Storage: Integrate a database (SQLite, PostgreSQL) to archive trades and P&L.
- Visualization: Use ImGui + ImPlot for real-time dashboards, or export logs for Python-based plotting.
Contributions are welcome! Open issues or pull requests on GitHub to:
- Report bugs
- Propose new features
- Improve documentation
Distributed under the MIT License. See LICENSE for details.