#!/bin/bash
# Refresh dati certificati + avanza paper portfolio (per il dashboard). v2.0.0+.
export PATH="/home/adriano/.local/bin:$PATH"
cd /opt/docker/PythagorasGoal || exit 1
mkdir -p logs
{
  echo "===== $(date -u '+%Y-%m-%dT%H:%M:%SZ') cron_daily ====="
  uv run python scripts/analysis/rebuild_history.py --asset BTC ETH   # BTC/ETH Deribit mainnet
  uv run python scripts/analysis/fetch_hyperliquid.py                 # 52 alt Hyperliquid (certify)
  uv run python scripts/research/fetch_dvol.py                        # DVOL (per ricerca opzioni)
  uv run python scripts/live/paper_portfolio.py                       # avanza paper TP01+XS01
  uv run python scripts/live/paper_prevday.py                         # forward-monitor lead prevday-breakout (PAPER, non deploy)
  # NB: l'esecuzione Deribit e' passata al BOOK (TP01+SKH01 nettati) via scripts/cron_book.sh a
  #     cadenza ORARIA (SKH01 e' a 230m: il daily mancherebbe gli ingressi). live_execute.py
  #     (TP01-only) NON va piu' eseguito qui, sennò i due farebbero a pugni sullo stesso strumento.
  # --- COMBO cross-venue (PAPER): refresh ETF IB (GTAA) + avanza paper TP01+GTAA ---
  docker compose up -d ib-gateway >/dev/null 2>&1                      # gateway IB paper (idempotente)
  for i in $(seq 1 25); do (echo > /dev/tcp/127.0.0.1/4002) >/dev/null 2>&1 && break; sleep 6; done
  uv run --with ib_async python scripts/research/fetch_ib_equities.py --only SPY,QQQ,IWM,TLT,GLD,HYG  # ETF GTAA freschi
  uv run python scripts/live/paper_combo.py                           # avanza paper combo (forward-only)
  echo "===== done $(date -u '+%H:%M:%SZ') ====="
} >> logs/cron_daily.log 2>&1
