A modular trading system for Interactive Brokers that allows you to implement and test trading strategies with ease.
- Modular Design: Easily add new trading strategies by implementing the
BaseStrategyinterface. - Broker Agnostic: Built with a broker-agnostic design, though currently focused on Interactive Brokers.
- Example Strategy: Includes a moving average crossover strategy as a starting point.
- Configuration Management: Uses YAML for easy configuration management.
- Type Hints: Full Python type hints for better code quality and IDE support.
- Python 3.8+
- Interactive Brokers TWS or IB Gateway installed and running
- An Interactive Brokers account with API access enabled
-
Clone the repository:
git clone https://github.com/yourusername/ib-trader.git cd ib-trader -
Create and activate a virtual environment (recommended):
python -m venv venv # On Windows: .\venv\Scripts\activate # On Unix or MacOS: source venv/bin/activate
-
Install the package in development mode:
pip install -e . -
Install development dependencies:
pip install -r dev-requirements.txt
-
Copy the example configuration file:
cp config/trading_config.yaml config/local_config.yaml
-
Edit
config/local_config.yamlwith your Interactive Brokers connection details and trading parameters.
-
Make sure Interactive Brokers TWS or IB Gateway is running and API connections are enabled.
-
Run the example strategy:
python -m ib_trader.main
ib-trader/
├── config/ # Configuration files
│ ├── trading_config.yaml # Example configuration
│ └── local_config.yaml # Local configuration (gitignored)
├── ib_trader/ # Main package
│ ├── brokers/ # Broker implementations
│ │ ├── __init__.py
│ │ ├── base_broker.py # Base broker interface
│ │ └── interactive_brokers.py # IB implementation
│ ├── strategies/ # Trading strategies
│ │ ├── __init__.py
│ │ ├── base_strategy.py # Base strategy interface
│ │ └── example_strategy.py # Example strategy
│ └── __init__.py
├── tests/ # Unit tests
├── .gitignore
├── README.md
├── requirements.txt # Production dependencies
├── dev-requirements.txt # Development dependencies
└── setup.py # Package configuration
To create a new trading strategy:
- Create a new file in the
ib_trader/strategies/directory. - Create a class that inherits from
BaseStrategy. - Implement all required methods from the base class.
- Add your strategy to
ib_trader/strategies/__init__.py. - Configure your strategy in the configuration file.
Run the test suite with:
pytest tests/This project is licensed under the MIT License - see the LICENSE file for details.
This software is for educational purposes only. Use it at your own risk. The authors are not responsible for any trading losses you might incur. Always test your strategies thoroughly before using real money.