#!/bin/bash
# ops/restart_trading.sh — Gracefully restart trading_bot
# The watcher will detect it restarted and not double-start.
set -e

echo "[$(date '+%H:%M:%S')] Stopping trading bot..."
pkill -f 'trading_bot/Stock_Bot/StockTrading' && sleep 3 || echo '  (was not running)'

echo "[$(date '+%H:%M:%S')] Starting trading bot (watcher will keepalive from here)..."
cd /opt/services/bots/trading_bot/Stock_Bot
nohup /opt/services/bots/trading_bot/venv/bin/python3     /opt/services/bots/trading_bot/Stock_Bot/StockTrading.py     --mode both --max-workers 12     >> /opt/services/bots/trading_bot/Stock_Bot/trading.log 2>&1 &
echo "[$(date '+%H:%M:%S')] Trading bot started PID $!"
