This trading bot is designed to automate the process of buying oversold assets and selling overbought assets based on Yahoo Finance data. The bot also sends notifications about recent trades via Slack during specified hours. The project uses the Alpaca API for trading operations and the Yahoo Finance API to identify trading opportunities.
The project is organized into the following files:
src/trading_classes.py
: Contains theTradingOpportunities
andAlpaca
classes, which handle scraping trading opportunities and executing buy/sell orders, respectively.src/slack_app_notification.py
: Contains theslack_app_notification()
function, which formats and returns a string containing the trading activity details to be sent via Slack.main.py
: The main script that brings together the functionality from thesrc
folder, executing the trading bot's operations and sending Slack notifications.creds.cfg
: A configuration file that stores the Alpaca API and Slack API credentials. (Make sure to add your own API keys and tokens here).circleci/config.yml
: The CircleCI configuration file that defines jobs, steps, and workflows for automated testing, building, and deployment.
The trading bot performs the following tasks:
- Scrape trading opportunities from Yahoo Finance using the
TradingOpportunities
class. - Filter the scraped assets to identify the ones that meet the buying criteria.
- Liquidate currently held assets that meet the selling criteria.
- Execute buy orders for the assets that meet the buying criteria.
- Send a formatted Slack message containing the trading activity details during specified hours.
The trading bot is scheduled to run at different times of the day using CircleCI, as specified in the .circleci/config.yml
file.
- Clone the repository.
- Create a virtual environment and activate it:
python3 -m venv venv
source venv/bin/activate
- Install the required dependencies:
pip install -r requirements.txt
- Add your Alpaca API and Slack API credentials to the
creds.cfg
file. - Run the trading bot:
python main.py
To set up the CircleCI integration for automated testing and deployment, follow these steps:
- Sign up for a CircleCI account if you don't have one already.
- Add your GitHub repository to CircleCI.
- Push the
.circleci/config.yml
file to your repository. CircleCI will automatically detect the file and start running the specified workflows.
- Make sure to customize the arguments in the
main()
function inmain.py
based on your preferences (e.g., trading hours, number of stocks and cryptocurrencies to consider, etc.). - Ensure that your API keys and tokens are kept secure and not exposed publicly.
Happy trading!