#!/bin/bash
# Background backtest - full datasets, no timeout
# Usage: bot_backtest_bg.sh [period] [rows]
#
# Period options:
#   6month     - Full 6-month file (legacy, loads 2.1GB)
#   5year      - Full 5-year file (loads 25GB) 
#   1month     - Latest 1 month only (~300MB)
#   2month     - Latest 2 months (~600MB)
#   3month     - Latest 3 months (~900MB)
#   202601     - Specific month (Jan 2026)
#   202510-202512 - Month range (Oct-Dec 2025)
#
# rows=0 means all (default)

cd /var/www/html/crpytotradingbot

PERIOD="${1:-1month}"
ROWS="${2:-0}"

echo "=== Background Backtest: period=$PERIOD, rows=$ROWS ==="
echo "Monitor progress: bash bot_check.sh"

nohup nice -n 15 python3 bot_runner.py \
    --csv="$PERIOD" \
    --max-rows=$ROWS \
    --timeout=86400 \
    --throttle=5 \
    > /var/www/html/crpytotradingbot/results/bg_output_$(date +%Y%m%d_%H%M%S).txt 2>&1 &

BG_PID=$!
echo "PID: $BG_PID"
echo "Progress file: /var/www/html/crpytotradingbot/backtest_progress.json"
