π€ An intelligent autonomous trading system using a multi-agent architecture for algorithmic trading via Interactive Brokers
Quantum Trader is a sophisticated algorithmic trading system that leverages Interactive Brokers' API to make trading decisions. The system uses a multi-agent approach where specialized components collaborate to analyze market data, assess risks, and execute trades.
-
Technical Analysis Agent
- Analyzes market data using multiple indicators:
- SMA (20, 50, 200 periods)
- EMA (12, 26 periods)
- RSI
- MACD
- Bollinger Bands
- Identifies trading patterns and signals
- Analyzes market data using multiple indicators:
-
Sentiment Analysis Agent
- Analyzes market sentiment from news and social media
- Monitors multiple platforms (Twitter, Reddit)
- Provides weighted sentiment signals
-
Risk Management System
- Position size and portfolio exposure limits
- Daily loss limits and drawdown protection
- Trade frequency controls
- Dynamic stop-loss using ATR
-
Trade Execution System
- Supports market and limit orders
- Slippage tolerance controls
- Position sizing based on risk or fixed size
- Order timeout management
A comprehensive training program is included to help you understand and effectively use Quantum Trader.
- Start the training server:
cd training
python3 server.py # Runs on default port 7555
# Or specify a custom port:
python3 server.py --port 8000
- Open your web browser and visit:
http://localhost:7555
(or your custom port if specified)
-
Level 1: Getting Started (Trader - Basic)
- Prerequisites
- System Setup
- Basic Operations
- Risk Management Fundamentals
-
Level 2: Intermediate Trading
- Advanced configuration
- Portfolio management
- Technical analysis implementation
-
Level 3: Advanced Operations
- Custom strategy development
- Advanced risk metrics
- System optimization
- Interactive tutorials with step-by-step guidance
- Practical exercises to reinforce learning
- Progress tracking
- Quizzes to test understanding
- Comprehensive documentation for each module
-
Python 3.10+
-
Interactive Brokers TWS or IB Gateway
- Download and install from Interactive Brokers
- Enable API connections in TWS/Gateway
- Configure the socket port (default: 7497)
- Enable auto-restart in TWS/Gateway
- Disable 'Read-Only API' in TWS/Gateway configuration
-
Market Data Subscriptions
- Appropriate market data subscriptions for your symbols
- Permissions for the markets you want to trade
- Clone the repository:
git clone https://github.com/zoharbabin/quantum-trader.git
cd quantum-trader
- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
- Install dependencies:
pip install -r requirements.txt
-
Configure the system:
- Review and modify
src/config/config.yaml
for your needs - Key configurations include:
- API connection settings
- Risk management parameters
- Trading execution preferences
- Analysis thresholds
- Review and modify
-
Start trading:
python -m src.cli.cli_interface --symbols AAPL MSFT GOOGL --mode paper
Required arguments:
--symbols
: List of stock symbols to trade--mode
: Trading mode ('paper' or 'live', default: paper)
The system is configured through src/config/config.yaml
. Key sections include:
api:
tws_endpoint: "127.0.0.1"
port: 7497
risk_management:
position_limits:
max_position_size: 100
max_portfolio_exposure: 0.25
loss_limits:
daily_loss_limit: 1000
max_drawdown: 0.15
trade_frequency:
min_time_between_trades: 300
max_daily_trades: 10
technical_analysis:
indicators:
sma_periods: [20, 50, 200]
rsi:
period: 14
overbought: 70
oversold: 30
macd:
fast_period: 12
slow_period: 26
signal_period: 9
execution:
order_types: ["market", "limit"]
default_order_type: "limit"
limit_order_timeout: 60
slippage_tolerance: 0.001
The system provides detailed logging of all operations:
2024-11-10 18:24:20,523 - INFO - === Quantum Trader Starting ===
2024-11-10 18:24:20,523 - INFO - Mode: paper
2024-11-10 18:24:20,523 - INFO - Symbols: ['AAPL', 'MSFT', 'GOOGL']
2024-11-10 18:24:20,524 - INFO - Checking Interactive Brokers prerequisites...
2024-11-10 18:24:20,525 - INFO - Successfully connected to Interactive Brokers
-
Connection Problems
- Verify TWS/Gateway is running
- Check API connection settings in TWS/Gateway
- Confirm port configuration matches config.yaml
- Ensure proper permissions in TWS/Gateway
-
Market Data Issues
- Verify market data subscriptions
- Check symbol validity
- Confirm market hours
- Monitor data synchronization logs
-
Trading Issues
- Check risk limits in config.yaml
- Verify account permissions in TWS/Gateway
- Monitor order status in logs
- Review execution reports
Detailed documentation is available in the docs
directory:
Run the test suite:
python -m unittest discover tests
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
This project is licensed under the MIT License. See the LICENSE file for details.