Update stock notifications with company names and new schedule times

Add full company names to stock price notifications displayed alongside tickers. Update scheduled message times from hourly to three specific times: market open (9:30 AM ET), noon (12:00 PM ET), and market close (4:00 PM ET).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Michael Simard
2025-12-04 20:18:08 -06:00
parent c35771c77a
commit 45d9965638
3 changed files with 51 additions and 13 deletions

44
bot.py
View File

@@ -46,13 +46,20 @@ class StockBot(commands.Bot):
"""Initialize the bot and set up scheduled tasks."""
logger.info("Bot setup initiated")
# Schedule hourly updates during market hours
# Run every hour on the hour, but only post if market is open
# Schedule market open update at 9:30 AM ET on weekdays
self.scheduler.add_job(
self.send_hourly_update,
CronTrigger(minute=0, timezone=MarketHours.NYSE_TIMEZONE),
id='hourly_update',
name='Hourly Stock Price Update'
self.send_market_open_update,
CronTrigger(hour=9, minute=30, day_of_week='mon-fri', timezone=MarketHours.NYSE_TIMEZONE),
id='market_open_update',
name='Market Open Update'
)
# Schedule noon update at 12:00 PM ET on weekdays
self.scheduler.add_job(
self.send_noon_update,
CronTrigger(hour=12, minute=0, day_of_week='mon-fri', timezone=MarketHours.NYSE_TIMEZONE),
id='noon_update',
name='Noon Update'
)
# Schedule market close update at 4:00 PM ET on weekdays
@@ -64,7 +71,7 @@ class StockBot(commands.Bot):
)
self.scheduler.start()
logger.info("Scheduler started for hourly updates and market close")
logger.info("Scheduler started for market open, noon, and market close updates")
async def on_ready(self):
"""Called when bot successfully connects to Discord."""
@@ -85,13 +92,23 @@ class StockBot(commands.Bot):
await self.send_startup_announcement()
self.startup_announced = True
async def send_hourly_update(self):
"""Send hourly stock price update if market is open."""
if not MarketHours.is_market_open():
logger.info("Market is closed, skipping hourly update")
async def send_market_open_update(self):
"""Send stock price update at market open on trading days."""
if not MarketHours.is_trading_day():
logger.info("Not a trading day, skipping market open update")
return
logger.info(f"Sending hourly update for {self.primary_ticker}")
logger.info(f"Sending market open update for {self.primary_ticker}")
for channel_id in self.target_channel_ids:
await self.send_stock_update(self.primary_ticker, channel_id)
async def send_noon_update(self):
"""Send stock price update at noon on trading days."""
if not MarketHours.is_trading_day():
logger.info("Not a trading day, skipping noon update")
return
logger.info(f"Sending noon update for {self.primary_ticker}")
for channel_id in self.target_channel_ids:
await self.send_stock_update(self.primary_ticker, channel_id)
@@ -169,6 +186,7 @@ class StockBot(commands.Bot):
Discord embed object
"""
ticker = stock_data['ticker']
company_name = stock_data.get('company_name', ticker)
current_price = stock_data['current_price']
change_dollar = stock_data['change_dollar']
change_percent = stock_data['change_percent']
@@ -192,7 +210,7 @@ class StockBot(commands.Bot):
if ticker == "PYPL":
title = f"{change_emoji} Steaks Stablecoin Value"
else:
title = f"{change_emoji} {ticker} Stock Price"
title = f"{change_emoji} {company_name} ({ticker}) Stock Price"
# Create embed
embed = discord.Embed(