The Momentum Trading Bot is a Python-based bot that identifies and trades assets with strong price momentum. It uses Pandas and NumPy for data analysis, the Interactive Brokers API for trading, and Yahoo Finance for historical data. API keys are securely stored in a .env file.
- Clone the Repository
git clone https://github.com/blockchaincyberpunk1/momentum_trading_bot.git cd momentum_trading_bot
- Create a Virtual Environment (Optional but recommended)
python -m venv venv source venv/bin/activate # On Windows, use venv\Scripts\activate
- Install Required Libraries
pip install -r requirements.txt
- Secure Your API Keys
Create a .env file in the project directory and add your API keys as follows:
IB_API_KEY=your_ib_api_key YAHOO_FINANCE_API_KEY=your_yahoo_finance_api_key
- Fetch Historical Data
Create a function to fetch historical data using Yahoo Finance and save it to data/historical_data.csv. Adapt and include this function in your code.
- Implement Momentum Strategy
Create and implement a momentum trading strategy in strategies/momentum_strategy.py.
- Interactive Brokers Integration
Use the ib_insync library to interact with the Interactive Brokers API. Include this functionality in utils/ib_api_utils.py.
- Run the Bot
In main.py, include the main logic for your trading bot. Fetch historical data, apply the momentum strategy, and execute trades.
python main.py
Momentum Trading Bot is built with the following tools and libraries:
- Interactive Brokers API: Allows for real-time trading and interaction with financial markets.
- Yahoo Finance API: Used to fetch historical price data for various assets.
- Python-decouple: Used to securely store and retrieve API keys from a .env file.
- ib-insync: A Python library for interactive trading with Interactive Brokers.
Run the bot using the provided instructions. It will identify assets with strong price momentum and execute trades accordingly.
Contributions to this project are welcome! If you would like to contribute, feel free to open issues, submit pull requests, or make suggestions for improvements.
Test the bot's functionality by running it with historical data and verifying that it correctly identifies and trades assets with strong momentum.
Visit my website: The Polyglot
Feel free to reach out to me on my email: [email protected]