building a stock alert system with python

i've always wanted a low-effort way to stay on top of stock movements without constantly refreshing a finance app. so i built one. the system fetches daily stock data, checks for significant price changes, and fires off an email with relevant news — all automatically.

the core idea is simple: hit a stock price api, calculate the percentage change from yesterday's close, and if it crosses a threshold (i use ±3%), pull headlines from a news api and bundle it into an html email.

the stack is minimal on purpose. requests for api calls, smtplib for email dispatch, and python-dotenv to keep credentials out of the codebase. that's it. no frameworks, no databases — just a python script and a cron job.

one thing that tripped me up early was rate limits on the news api. the fix was a small delay between requests and caching yesterday's results in a json file.

securing credentials felt obvious but a lot of beginner projects skip it. i use a .env file with dotenv and a .gitignore that explicitly excludes it.

i run this as a cron job on a linux machine every weekday at 9am before the market opens. the project is open-source — check it out on github.

← back to blog