Day 65 of the 100 Days Coding Challenge: Python
Today’s project was all about giving my stock tracker a voice—or at least the Python equivalent of tapping me on the shoulder. I added a suite of functions to build a simple price alert system. Now, I can set an alert for any stock symbol, pick a target price (whether I expect it to go soaring or take a nosedive), and check those alerts whenever I feel like it. The alerts live in alerts.json, which means they survive beyond the current run of the program, unlike my patience for earnings season.
Given the market’s recent mood swings—some days it’s caffeine-powered optimism, other days it’s “time to move into a cabin in the woods”—this feature feels like a smart way to keep tabs on a few key stocks. I also tossed in the ability to list all active alerts and remove them once they’re no longer relevant.
I’m not a day trader, so I won’t be glued to this alert system like it’s the final episode of a drama series. But I’m already thinking about how this little foundation could be built into something bigger—perhaps even a full-blown, automated “call me when it matters” system.
Today’s Motivation / Challenge
Sometimes you don’t want to watch the market all day—you just want it to tap you politely when something interesting happens. This project scratches that itch. It’s like hiring a butler who only bothers you when your investments hit the numbers you care about.
Purpose of the Code (Object)
The code lets you set stock price alerts for any symbol, save them, and check them against live prices. You can remove old alerts, list current ones, and trust they’ll be there the next time you run the program. It’s a neat way to track specific opportunities without manually refreshing a stock chart every five minutes.
AI Prompt
Please add a Price Alert system. Let the user set a target price and alert if the current price crosses it. The system needs the following functions: set a price alert, check price alerts now, list alerts, and remove an alert.
Functions & Features
- Set a Price Alert – Choose a stock, pick a price, and decide if you want to be notified when it rises above or falls below that level.
- Check Alerts – Compare live prices against saved alerts.
- List Alerts – See what you’re tracking at a glance.
- Remove Alerts – Delete alerts you no longer need.
Requirements / Setup
pip install yfinance
Python 3.8+ recommended.
Minimal Code Sample
def check_price_alerts():
alerts = load_alerts()
for alert in alerts:
price = get_price(alert[“symbol”])
if (alert[“type”] == “above” and price > alert[“target”]) or \
(alert[“type”] == “below” and price < alert[“target”]):
print(f”ALERT: {alert[‘symbol’]} hit {price:.2f}”)
Checks each saved alert and prints a message if the condition is met.
Notes / Lessons Learned
Yes, I was a bit tired today, so when I created my shiny new alerts.json file, I somehow misspelled it. Naturally, the program refused to recognize it. That was my first mistake. The second? Entering an alert incorrectly—forgetting to choose “above” or “below” before typing in the target price. This left the file corrupted and the program more confused than I was during my first economics class.
The fix was simple but satisfying: I added a load_alerts() function that returns [] if the file is empty and quietly backs up a corrupt JSON before starting fresh. I also made save_alerts() write to a temporary file first, then replace the original in one move. No more half-written files, no more unexpected crashes.
The real lesson? Creating new errors isn’t a bad thing—it’s a great way to see where the cracks are before the whole thing falls apart. It’s a bit like stress-testing your code, except the stress is mostly on you.
Optional Ideas for Expansion
- Add email or SMS notifications when an alert triggers.
- Integrate with a dashboard to show alert history.
- Let alerts expire after a set number of days.

