A comprehensive Python framework for quantitative research, backtesting, and live trading. Supports multiple brokers (IBKR, OANDA), real-time data collection, technical analysis, machine learning predictions, and automated strategy execution.
- Features
- Quick Start
- Architecture
- Documentation
- Installation
- Usage
- Project Structure
- Contributing
- License
- Data Management: Download and cache historical OHLCV data from IBKR
- Technical Indicators: RSI, MACD, EMA/SMA, ATR, ADX, Bollinger Bands, Local Extrema
- Pattern Detection: Chart patterns (Head & Shoulders, Triangles, etc.) and candlestick patterns
- Strategy Backtesting: Comprehensive backtesting framework with multiple strategies
- Machine Learning: ML predictors for price direction, volatility, trend, and extrema
- Live Trading: Real-time trading system with multi-timeframe support
- Visualization: Interactive charts with Matplotlib and Plotly
- Momentum Strategies: Trend following with MACD, EMA crossovers
- Mean Reversion: RSI, Bollinger Bands mean reversion
- Breakout Strategies: Support/Resistance and ATR-based breakouts
- Multi-Timeframe: Higher timeframe trend confirmation
- Pattern-Based: Chart pattern and triangle detection strategies
- Adaptive: Multi-indicator adaptive strategies
See Strategy Documentation for details.
- IBKR: Market data and order execution (paper and live)
- OANDA: Order execution (paper and live)
See Broker Configuration for setup instructions.
- Python 3.10+
- IBKR TWS/Gateway (for IBKR data/trading)
- MongoDB (for live trading system)
- Node.js 18+ (for frontend, optional)
- Clone the repository:
git clone <repository-url>
cd trading-bot- Create virtual environment:
python3 -m venv .venv-cli
source .venv-cli/bin/activate # On Windows: .venv\Scripts\activate- Install system dependencies (macOS):
brew install ta-lib libomp- Install Python dependencies:
pip install --upgrade pip setuptools
pip install -r requirements.txt
pip install -e ./IBJts/source/pythonclient # IBKR API- Configure environment:
Create a
.envfile in the project root:
# Optional: For OANDA trading
OANDA_ACCESS_TOKEN=your_token
OANDA_ACCOUNT_ID=your_account_id
# Optional: For live trading system
MONGODB_URL=mongodb://localhost:27017
MONGODB_DB_NAME=trading_bot- Start IBKR TWS/Gateway:
- Enable API: Configure → Global Configuration → API → Settings
- Socket port: 7497 (paper) or 7496 (live)
- Add 127.0.0.1 to Trusted IPs
Interactive Mode (recommended):
python cli.pyThen in the shell:
trading-bot> help
trading-bot> download-and-process
trading-bot> test-forex-strategies --asset USD-CAD
trading-bot> exit
Single Command Mode:
# Download and process data
python cli.py download-and-process
# Test strategies
python cli.py test-forex-strategies --asset USD-CAD --bar-size "1 hour"
# Train ML models
python cli.py train-extrema-predictor --asset USD-CADThe system consists of two main components:
- CLI Interface: Interactive shell for data management, strategy testing, and ML training
- Data Pipeline: IBKR → CSV cache → Technical Indicators → Strategies → Backtesting
- Strategy Framework: Extensible strategy base classes with backtesting integration
- ML Pipeline: Feature engineering, model training, and prediction
See Architecture Documentation for details.
- Trading Engine: Orchestrates real-time trading operations
- Data Manager: Real-time data collection and bar aggregation
- Order Manager: Order placement, position tracking, risk management
- REST API: FastAPI-based API for operation management
- React Frontend: Web interface for monitoring and control
See Live Trading Documentation for details.
Comprehensive documentation is available in the docs/ directory:
- Installation Guide - Detailed setup instructions
- Quick Start Guide - Get up and running quickly
- Configuration - Environment variables and settings
- Architecture Overview - System architecture and design
- Data Management - Data download, processing, and storage
- Technical Indicators - Available indicators and usage
- Strategies - Strategy development and backtesting
- Live Trading System - Overview and setup
- Live Trading Architecture - Detailed architecture
- Real-Time Data Flow - How real-time data works
- Broker Integration - IBKR and OANDA setup
- Frontend Guide - React frontend usage
- Machine Learning - ML model training and usage
- Pattern Detection - Chart pattern and triangle detection
- Alternative Data Sources - Free data alternatives
- Troubleshooting - Common issues and solutions
- CLI Reference - Complete command reference
- API Reference - REST API documentation
- Strategy Examples - Example strategies
See Installation Guide for detailed instructions.
macOS:
brew install ta-lib libompLinux:
sudo apt-get install ta-lib libomp-dev # Ubuntu/DebianWindows: Download TA-Lib from https://ta-lib.org/install/
Download and process historical data:
python cli.py download-and-process
python cli.py download-and-process --include-1min --force-refreshTest all strategies on all assets:
python cli.py test-forex-strategiesTest specific strategies on specific assets:
python cli.py test-forex-strategies --asset USD-CAD --bar-size "1 hour" --strategies "MomentumStrategy,RSIStrategy"Train extrema predictor:
python cli.py train-extrema-predictor --asset USD-CAD --lookback-bars 20Train other predictors:
python cli.py train-price-direction-predictor --asset USD-CAD
python cli.py train-volatility-predictor --asset USD-CAD
python cli.py train-trend-predictor --asset USD-CADStart in interactive mode (foreground):
python -m live_trading.mainStart as a background daemon (recommended for production):
python -m live_trading.cli start # Start daemon
python -m live_trading.cli status # Check status
python -m live_trading.cli logs -f # Follow logs (like tail -f)
python -m live_trading.cli stop # Stop daemonAccess the system:
- API:
http://localhost:8000 - Frontend:
http://localhost:3000(if running separately) - Logs Viewer:
http://localhost:3000/logs(frontend)
See Live Trading Documentation for details.
trading-bot/
├── cli.py # Main CLI entry point
├── config.py # Global configuration
├── contracts.json # Instrument definitions
├── requirements.txt # Python dependencies
├── docs/ # Documentation
├── data/ # Cached historical data (CSV)
├── forex_strategies/ # Trading strategies
├── technical_indicators/ # Technical indicator implementations
├── machine_learning/ # ML models and predictors
├── patterns/ # Chart pattern detection
├── triangles/ # Triangle pattern detection
├── live_trading/ # Live trading system
│ ├── api/ # FastAPI REST API
│ ├── brokers/ # Broker adapters (IBKR, OANDA, cTrader)
│ ├── daemon/ # Background process management
│ ├── data/ # Data collection and aggregation
│ ├── engine/ # Trading engine
│ ├── logging/ # Modular logging system
│ ├── models/ # MongoDB models
│ ├── orders/ # Order management
│ ├── strategies/ # Strategy adapters
│ ├── cli.py # Daemon control CLI
│ └── frontend/ # React frontend
├── ib_api_client/ # IBKR API client wrapper
├── request_historical_data/ # Historical data requests
└── data_manager/ # Data download and processing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
See LICENSE file for details.
This project is for educational and research purposes. Trading involves significant risk. Use at your own risk and verify behavior on paper trading/sandbox environments before any live deployment.