A Python-based stock alerting service that monitors prices (One symbol/sec) using Finnhub API and sends push notifications via Alertzy based on user-defined thresholds.
- Monitor multiple stock tickers with percentage-based alert thresholds.
- Send push notifications to configured devices using Alertzy.
- Automatically pull the code and restart the server when the repository updates.
- Free service for gail residents, add symbols and your encrypted alertzy account id (check below on how to encrypt) in
config.yaml
file to get started
- Python 3.7+
- Poetry
- Docker/Docker Compose
-
Clone the Repository
git clone https://github.com/vinaykudari/stocklerts.git cd stocklerts
-
Install Dependencies
poetry install
-
Configure Environment Variables
Register at finnhub and set the key:
export FINNHUB_API_KEY="<your-finnhub-api-key>"
-
Gail residents use our wifi passsword twice
<password><password>
to encrypt your account id -
Encrypt your Alertz account id at devglan.com using the exact same settings and set the passcode as env var
export ENCRYPT_KEY="<encrypt-key>"
-
Configure Application
Install Alerty app and copy the account id and update
config/config.yaml
with your desired settings:defaults: cooldown_period_minutes: 60 max_notifications_per_day: 100 max_quote_calls_per_min: 60 alertzy: accounts: - user_id: 1 account_id: <encrypted_account_id> - user_id: 2 account_id: 18tu6LkU4y9uNArpNlAyog== tickers: - symbol: AAPL threshold: - value: 5 users: - 1 - value: 0 users: - 2 - symbol: MSFT threshold: - value: 5 users: - 1 - symbol: GOOGL threshold: - value: 0 users: - 1
-
Run the application
- Install the dependencies from
webhook_handler_reqs.txt
- Start the webhook handler (Check at the end to set this as system service)
gunicorn -b 0.0.0.0:5005 webhook_handler:app
- Start the app server
poetry run python -m app.main
- Alternatively, use docker
docker compose build
# make sure you sent the env vars before you run this
docker compose up
-
Setup webhook in github repository
-
Install
venv
for your python version
sudo apt install python3.10-venv
- Create a venv in the directory
python3 -m venv venv
- Update the permissions
sudo chown -R <username>:<username> /path/to/project/venv
- Create a system service to run the server on boot as daemon
sudo vim /etc/systemd/system/stocklerts_webhook_handler.service
[Unit]
Description=Stocklerts Webhook Handler
After=network.target
[Service]
Type=simple
User=dexter
Group=dexter
WorkingDirectory=/path/to/project
Environment="GH_WEBHOOK_SECRET=<webhhok-secret-you-setup-in-github>"
Environment="ENCRYPT_KEY=<encrypt-key>"
Environment="FINNHUB_API_KEY=<your-finnhub-api-key>"
Environment=PATH=/path/to/project/venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ExecStartPre=/usr/bin/python3 -m venv venv
ExecStartPre=/path/to/project/venv/bin/pip install -r /path/to/project/webhook_handler_reqs.txt
ExecStart=/path/to/project/venv/bin/gunicorn --bind 0.0.0.0:5005 webhook_handler:app
Restart=on-failure
[Install]
WantedBy=multi-user.target
- Update the service
sudo systemctl daemon-reload
- Start the service
sudo systemctl start stocklerts_webhook_handler.service
- Enable the service to start at boot
sudo systemctl enable stocklerts_webhook_handler
- Monitor logs
journalctl -u stocklerts_webhook_handler.service -f
- Setup ngrok account and add your config to the file
- Create
ngrok
config file in home directory
vim ~/ngrok.yml
authtoken: <auth-token>
version: 1
tunnels:
stocklerts:
proto: http
addr: 5005
hostname: <your-static-domain>
- Create a system service to run the server on boot as daemon
sudo vim /etc/systemd/system/ngrok_tunnel.service
[Unit]
Description=Ngrok Tunnel for Stocklerts
After=network.target
[Service]
ExecStart=/snap/bin/ngrok start --config /home/<username>/ngrok.yml stocklerts
Restart=on-failure
User=<username>
[Install]
WantedBy=multi-user.target
- Update the service
sudo systemctl daemon-reload
- Start the service
sudo systemctl start ngrok_tunnel.service
- Enable the service to start at boot
sudo systemctl enable ngrok_tunnel