#!/usr/bin/env bash
set -euo pipefail

ROOT="/var/www/vps2.happyuser.info/top/callme_overnight_20260601"
PY="/home/simple_user/.pyenv/versions/3.8.18/bin/python3.8"
OUT="$ROOT/output"
STOP="$ROOT/STOP"
mkdir -p "$OUT"

echo "Callme overnight run starting at $(date -u +%Y-%m-%dT%H:%M:%SZ)"
echo "Root: $ROOT"
echo "Python: $($PY -V 2>&1)"
echo "nproc: $(nproc)"
free -m || true
df -h "$ROOT" || true

CPUSET="0"
if command -v taskset >/dev/null 2>&1; then
  RUNNER=(taskset -c "$CPUSET")
else
  RUNNER=()
fi

if command -v ionice >/dev/null 2>&1; then
  IO=(ionice -c2 -n7)
else
  IO=()
fi

exec "${RUNNER[@]}" "${IO[@]}" nice -n 15 "$PY" "$ROOT/callme_dca_v21_overnight_runner.py" \
  --positions "$ROOT/input/position_history_normalized.csv" \
  --ohlcv-cache "$ROOT/input/ohlcv_1m_cache" \
  --out-dir "$OUT" \
  --initial-equity 500 \
  --max-target-notional 500 \
  --min-free-mb 4096 \
  --stop-file "$STOP"
