A comprehensive proof-of-concept for algorithmic trading with OANDA and Interactive Brokers APIs.
- Python 3.8 or higher
- OANDA account (for OANDA examples)
- Interactive Brokers account with TWS/IB Gateway (for IBKR examples)
-
Clone or download this repository
-
Install dependencies:
pip install -r requirements.txt
-
Set up your trading credentials (see Configuration section below)
-
Start trading! Open the Jupyter notebooks and begin exploring.
oanda-algo-trading-basics/
├── brokers/
│ ├── oanda/ # OANDA-specific implementations
│ └── ibkr/ # Interactive Brokers implementations
│ └── notebooks/ # Jupyter notebooks for IBKR
├── requirements.txt # Python dependencies
└── README.md # This file
HistoricalAccountValues.ipynb- Fetch and analyze historical market dataTradingChallenge.ipynb- Complete SMA crossover trading system with performance analysis
- Create a
.envfile in the project root - Add your OANDA credentials:
OANDA_API_KEY=your_api_key_here OANDA_ACCOUNT_ID=your_account_id_here OANDA_ENVIRONMENT=practice # or 'live' for real trading
- Install and run TWS (Trader Workstation) or IB Gateway
- Enable API connections in TWS/Gateway settings:
- Go to Global Configuration → API → Settings
- Enable "Enable ActiveX and Socket Clients"
- Note the Socket Port (usually 7497 for TWS, 4001 for Gateway)
- The notebooks will connect to
localhost:7497by default
- Start with demo/paper trading accounts
- Test all strategies thoroughly before risking real money
- The code includes educational examples - modify for your risk tolerance
- Never commit API keys or credentials to version control
# Run HistoricalAccountValues.ipynb
# - Fetch EUR/USD historical data
# - Analyze price movements
# - Convert data to pandas DataFrames# Run TradingChallenge.ipynb
# - Implement SMA crossover strategy
# - Execute backtests on historical data
# - Analyze performance metrics
# - Optional: Run live signal monitoring- ✅ Multiple Broker Support - OANDA and Interactive Brokers
- ✅ Historical Data - Fetch and analyze market data
- ✅ Trading Strategies - SMA crossover and more
- ✅ Risk Management - Stop-loss, take-profit, position sizing
- ✅ Performance Analysis - Win rate, Sharpe ratio, drawdown analysis
- ✅ Visualization - Charts and performance metrics
- ✅ Backtesting - Test strategies on historical data
Key libraries used:
- ib_async - Interactive Brokers API
- oandapyV20 - OANDA REST API
- pandas/numpy - Data analysis
- matplotlib - Visualization
- requests - HTTP requests
This is a proof-of-concept project. Feel free to:
- Add new trading strategies
- Improve risk management
- Add support for other brokers
- Enhance visualizations
This software is for educational purposes only. Trading involves significant risk of loss. The authors are not responsible for any financial losses incurred through the use of this software. Always do your own research and consider consulting with a financial advisor.
For questions or issues:
- Check the notebook comments and documentation
- Review the broker API documentation
- Test with paper trading accounts first
- Ensure all dependencies are properly installed
Happy Trading! 📈