This repository contains the code of a Telegram bot that gets information about stocks.
The bot supports the following commands:
/start
- show the description of what the bot can do/help
- show the list of commands the bot supports/price {symbol}
- get price stats/return {symbol}
- get return stats/vol {symbol}
- get volatility stats/all {symbol}
- get price, return, and volatility stats
For a detailed description of the response of each command, please see: commands.md
In addition to the commands, the bot also has a monitor mode which is responsible for two things:
- Send an alert when there is a price anomaly on a symbol of our portfolio.
- Send a daily report about our portfolio performance.
For a detailed description of what the monitor mode does, please see: monitor.md
This is the high level design of Stockbot:
python -m venv .venv
source .venv/bin/activate
make install
make build
To execute the unit tests please run the following command: make test
To see the code coverage report please execute the following commands:
make coverage
open htmlcov/index.html
First define the required environment variables:
export TELEGRAM_BOT_TOKEN='<bot-token-here>'
export CHANNEL_ID='<channel-id-here>'
export SYMBOLS='<symbol1>,<symbol2>,...,<symbolN>'
Please enter symbols that are valid in Yahoo Finance.
We can run the bot in two modes locally:
- Polling mode:
make poll
- Monitor mode:
make monitor
The project has three directories at the root level:
docs
: contains files related to documentation.infra
: contains CDK files that define the infrastructure.src
: contains the source code and tests of the bot.
The code is organized in the following way:
- We have components, each component has a single responsibility.
- Each component has its own folder.
- The folder of each component has its source code and tests.
We have the following components:
analyst
: it is responsible for performing the analysis over the data.bot
: it is responsible for receive commands and return answers.common
: it is responsible to hold common types and data structures.download
: it is responsible for downloading the data we need to analyst.
In addition to the components we have 4 files in the root of the project:
commands
: contains the commands supported by the bot.monitor
: lambda to monitor a list of symbols.poll
: code to get new messages via polling (polling Telegram).push
: lambda to get new messages via push (webhooks sent by Telegram).
To visualize the project structure, please execute the following command:
tree -I 'venv|__pycache__|test_files|htmlcov|cdk.out'
We use AWS CDK (infrastructure as code) + AWS API Gateway + AWS Lambda to deploy the bot. The details are documented here.
Run the following command to create the infrastructure and deploy the code:
make deploy
If we want to delete the infrastructure created, please run this command:
make destroy