Skip to content

πŸ€– An intelligent stock trading bot combining technical & qualitative analysis with Interactive Brokers TWS API integration

License

Notifications You must be signed in to change notification settings

zoharbabin/quantum-trader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

39 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Quantum Trader

πŸ€– An intelligent autonomous trading system using a multi-agent architecture for algorithmic trading via Interactive Brokers

Overview

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.

Key Features

Multi-Agent Architecture

  1. 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
  2. Sentiment Analysis Agent

    • Analyzes market sentiment from news and social media
    • Monitors multiple platforms (Twitter, Reddit)
    • Provides weighted sentiment signals
  3. Risk Management System

    • Position size and portfolio exposure limits
    • Daily loss limits and drawdown protection
    • Trade frequency controls
    • Dynamic stop-loss using ATR
  4. Trade Execution System

    • Supports market and limit orders
    • Slippage tolerance controls
    • Position sizing based on risk or fixed size
    • Order timeout management

Training Program

A comprehensive training program is included to help you understand and effectively use Quantum Trader.

Running the Training Program

  1. Start the training server:
cd training
python3 server.py  # Runs on default port 7555
# Or specify a custom port:
python3 server.py --port 8000
  1. Open your web browser and visit: http://localhost:7555 (or your custom port if specified)

Training Structure

  1. Level 1: Getting Started (Trader - Basic)

    • Prerequisites
    • System Setup
    • Basic Operations
    • Risk Management Fundamentals
  2. Level 2: Intermediate Trading

    • Advanced configuration
    • Portfolio management
    • Technical analysis implementation
  3. Level 3: Advanced Operations

    • Custom strategy development
    • Advanced risk metrics
    • System optimization

Training Resources

  • Interactive tutorials with step-by-step guidance
  • Practical exercises to reinforce learning
  • Progress tracking
  • Quizzes to test understanding
  • Comprehensive documentation for each module

Prerequisites

  1. Python 3.10+

  2. 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
  3. Market Data Subscriptions

    • Appropriate market data subscriptions for your symbols
    • Permissions for the markets you want to trade

Quick Start

  1. Clone the repository:
git clone https://github.com/zoharbabin/quantum-trader.git
cd quantum-trader
  1. Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows use `venv\Scripts\activate`
  1. Install dependencies:
pip install -r requirements.txt
  1. 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
  2. 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)

Configuration

The system is configured through src/config/config.yaml. Key sections include:

API Configuration

api:
  tws_endpoint: "127.0.0.1"
  port: 7497

Risk Management

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

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

Trading Execution

execution:
  order_types: ["market", "limit"]
  default_order_type: "limit"
  limit_order_timeout: 60
  slippage_tolerance: 0.001

System Output

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

Troubleshooting

Common Issues

  1. 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
  2. Market Data Issues

    • Verify market data subscriptions
    • Check symbol validity
    • Confirm market hours
    • Monitor data synchronization logs
  3. Trading Issues

    • Check risk limits in config.yaml
    • Verify account permissions in TWS/Gateway
    • Monitor order status in logs
    • Review execution reports

Documentation

Detailed documentation is available in the docs directory:

Testing

Run the test suite:

python -m unittest discover tests

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request

License

This project is licensed under the MIT License. See the LICENSE file for details.