From 584ad2a4f459c7783f1d43ba6d60516573058343 Mon Sep 17 00:00:00 2001 From: Michael Simard Date: Wed, 3 Dec 2025 18:57:13 -0600 Subject: [PATCH] Add market close updates and update deployment path for Compose Manager MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bot enhancements: - Add scheduled update at market close (4:00 PM ET on trading days) - Implement is_trading_day() method to check weekdays/holidays - Market close update sends PYPL price at end of trading day Deployment changes: - Update all scripts to use Docker Compose Manager plugin path - New path: /boot/config/plugins/compose.manager/projects/discord-stock-bot - Container now integrates with Unraid Docker UI Compose section - Update documentation with plugin integration details 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- DEPLOYMENT.md | 7 +++++-- bot.py | 19 ++++++++++++++++++- deploy.sh | 2 +- manage.sh | 2 +- market_hours.py | 28 ++++++++++++++++++++++++++++ setup-unraid.sh | 2 +- 6 files changed, 54 insertions(+), 6 deletions(-) diff --git a/DEPLOYMENT.md b/DEPLOYMENT.md index 5045a28..6f8ec86 100644 --- a/DEPLOYMENT.md +++ b/DEPLOYMENT.md @@ -298,9 +298,10 @@ git push #### Configuration Details - **Unraid Host**: `root@192.168.2.61` -- **Deployment Path**: `/mnt/user/docker/custom-dockers/discord-stock-bot` +- **Deployment Path**: `/boot/config/plugins/compose.manager/projects/discord-stock-bot` - **Git Repository**: `git@git.michaelsimard.ca:msimard/discord-stock-bot.git` - **Git Server Port**: 28 (configured in SSH config) +- **Integration**: Docker Compose Manager plugin (stack appears in Unraid Docker tab) #### Troubleshooting Automated Deployment @@ -325,10 +326,12 @@ ssh root@192.168.2.61 "git ls-remote git@git.michaelsimard.ca:msimard/discord-st **Container Won't Start:** ```bash # Check .env exists on Unraid -ssh root@192.168.2.61 "cat /mnt/user/docker/custom-dockers/discord-stock-bot/.env" +ssh root@192.168.2.61 "cat /boot/config/plugins/compose.manager/projects/discord-stock-bot/.env" # View detailed logs ./manage.sh logs + +# Check in Unraid UI: Docker tab > Compose section ``` ### Method 1: Docker Compose diff --git a/bot.py b/bot.py index 03da942..87d27a7 100644 --- a/bot.py +++ b/bot.py @@ -52,8 +52,16 @@ class StockBot(commands.Bot): name='Hourly Stock Price Update' ) + # Schedule market close update at 4:00 PM ET on weekdays + self.scheduler.add_job( + self.send_market_close_update, + CronTrigger(hour=16, minute=0, day_of_week='mon-fri', timezone=MarketHours.NYSE_TIMEZONE), + id='market_close_update', + name='Market Close Update' + ) + self.scheduler.start() - logger.info("Scheduler started for hourly updates") + logger.info("Scheduler started for hourly updates and market close") async def on_ready(self): """Called when bot successfully connects to Discord.""" @@ -77,6 +85,15 @@ class StockBot(commands.Bot): logger.info(f"Sending hourly update for {self.primary_ticker}") await self.send_stock_update(self.primary_ticker, self.target_channel_id) + async def send_market_close_update(self): + """Send stock price update at market close on trading days.""" + if not MarketHours.is_trading_day(): + logger.info("Not a trading day, skipping market close update") + return + + logger.info(f"Sending market close update for {self.primary_ticker}") + await self.send_stock_update(self.primary_ticker, self.target_channel_id) + async def send_stock_update(self, ticker: str, channel_id: int): """ Fetch stock data and send formatted embed to specified channel. diff --git a/deploy.sh b/deploy.sh index 2add3eb..7865443 100755 --- a/deploy.sh +++ b/deploy.sh @@ -5,7 +5,7 @@ set -e # Configuration UNRAID_HOST="${UNRAID_HOST:-root@192.168.2.61}" -REMOTE_PATH="/mnt/user/docker/custom-dockers/discord-stock-bot" +REMOTE_PATH="/boot/config/plugins/compose.manager/projects/discord-stock-bot" GIT_REPO="git@git.michaelsimard.ca:msimard/discord-stock-bot.git" echo "Deploying discord-stock-bot to ${UNRAID_HOST}..." diff --git a/manage.sh b/manage.sh index 912d3c5..9e8a144 100755 --- a/manage.sh +++ b/manage.sh @@ -2,7 +2,7 @@ # manage.sh - Manage discord-stock-bot on Unraid UNRAID_HOST="${UNRAID_HOST:-root@192.168.2.61}" -REMOTE_PATH="/mnt/user/docker/custom-dockers/discord-stock-bot" +REMOTE_PATH="/boot/config/plugins/compose.manager/projects/discord-stock-bot" CMD="$1" diff --git a/market_hours.py b/market_hours.py index 892661c..50bca70 100644 --- a/market_hours.py +++ b/market_hours.py @@ -79,6 +79,34 @@ class MarketHours: logger.debug(f"Market closed: Outside trading hours ({current_time})") return False + @classmethod + def is_trading_day(cls, check_time: datetime = None) -> bool: + """ + Determine if the given date is a trading day (weekday, not a holiday). + + Args: + check_time: Datetime to check (defaults to now) + + Returns: + True if it's a trading day, False otherwise + """ + if check_time is None: + check_time = datetime.now(cls.NYSE_TIMEZONE) + else: + check_time = check_time.astimezone(cls.NYSE_TIMEZONE) + + # Check if weekend + if check_time.weekday() >= 5: # Saturday = 5, Sunday = 6 + return False + + # Check if holiday + check_date = check_time.date() + all_holidays = cls.HOLIDAYS_2024 + cls.HOLIDAYS_2025 + if any(holiday.date() == check_date for holiday in all_holidays): + return False + + return True + @classmethod def get_next_market_open(cls, from_time: datetime = None) -> datetime: """ diff --git a/setup-unraid.sh b/setup-unraid.sh index dc3bab8..964d4d8 100755 --- a/setup-unraid.sh +++ b/setup-unraid.sh @@ -4,7 +4,7 @@ set -e UNRAID_HOST="${UNRAID_HOST:-root@192.168.2.61}" -REMOTE_PATH="/mnt/user/docker/custom-dockers/discord-stock-bot" +REMOTE_PATH="/boot/config/plugins/compose.manager/projects/discord-stock-bot" echo "Setting up Unraid server for git-based deployment..." echo ""