14522262e6
Reset del progetto su fondamenta verificate dopo la scoperta che l'intera libreria "validata OOS" era artefatto di feed contaminato (print fantasma del feed Cerbero TESTNET + storico Binance/USDT). - Storico ricostruito da Deribit MAINNET (ccxt pubblico, tokenless) e CERTIFICATO (certify_feed.py): BTC/ETH puliti su TUTTA la storia (mediana 2-6 bps vs Coinbase USD), integrita' OHLC + coerenza resample (maxΔ 0.00) + cross-venue OK. Alt esclusi (illiquidi/divergenti: LTC/DOGE 50-82% barre flat; XRP/BNB non certificabili). - Verdetto sul feed pulito: FADE / PAIRS / XS01 / TSM01 morti (ogni portafoglio Sharpe -2.3..-3.0, DD ~40%); solo SH01 e frammenti HONEST con segnale residuo, da ri-validare in isolamento. - Cleanup "restart pulito": strategie, stack live (src/live, src/portfolio, runner/executor, yml, docker), ~100 script ricerca/gate, waste/games/ portfolios, dati non certificati + cache e 60+ diari -> archiviati in Old/ (preservati, non cancellati). Diario consolidato in un unico documento. - Skeleton ricerca tenuto: Strategy ABC + indicatori + src/fractal + src/backtest/engine + load_data; tool dati certificati (rebuild_history, certify_feed, audit_feed, multi_source_check). - Universo dati ATTIVO: solo BTC/ETH (5m/15m/1h); guardrail fisico (load_data su alt -> FileNotFoundError). Esecuzione DISABILITATA, conto flat. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
56 lines
2.3 KiB
Python
56 lines
2.3 KiB
Python
"""Notifiche Telegram per il paper trader."""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import urllib.request
|
|
import urllib.parse
|
|
import json
|
|
|
|
from src.version import APP_VERSION
|
|
|
|
BOT_TOKEN = os.environ.get("TELEGRAM_BOT_TOKEN", "")
|
|
CHAT_ID = os.environ.get("TELEGRAM_CHAT_ID", "")
|
|
|
|
NOTIFY_EVENTS = {
|
|
"SIGNAL", "OPENED", "CLOSED", "OPEN_FAILED", "CLOSE_FAILED",
|
|
"ERROR", "STARTUP", "SHUTDOWN", "TRAINING_FAILED",
|
|
# esecuzione REALE (shadow su Deribit testnet)
|
|
"REAL_EXEC_LIVE", # primo ordine reale verificato di un worker (conferma "e' vivo")
|
|
"REAL_OPEN_FAIL", # un'apertura reale NON si e' verificata (problema da guardare)
|
|
"STALE_FEED", # feed flat/fermo da >= N barre 1h (worker ciechi: il prossimo
|
|
# prezzo reale puo' gappare, come ETH 2026-06-05 1655->1600)
|
|
"PANEL_SHORT", # TSM01/ROT02: panel inner-join troncato sotto il lookback
|
|
# richiesto -> tick() salterebbe in SILENZIO (worker inerte)
|
|
"FEED_OUTAGE", # N poll consecutivi falliti/degradati nel runner: exit non
|
|
# valutati, posizioni reali protette solo dal disaster-SL
|
|
"REAL_DIVERGENCE", # |slippage| sim/reale anomalo a open/close (es. spike print
|
|
# testnet: sim entra su un prezzo fantasma, il reale sul book)
|
|
"REAL_DSL_CANCEL_FAIL", # cancel del disaster-SL fallita dopo retry: possibile
|
|
# stop ORFANO sul book -> verificare a mano
|
|
"REAL_CLOSE_FAILED", # chiusura reale a 2 gambe (pairs) non verificata su una gamba
|
|
}
|
|
|
|
|
|
def send_telegram(text: str) -> bool:
|
|
if not BOT_TOKEN or not CHAT_ID:
|
|
return False
|
|
try:
|
|
url = f"https://api.telegram.org/bot{BOT_TOKEN}/sendMessage"
|
|
data = urllib.parse.urlencode({"chat_id": CHAT_ID, "text": text, "parse_mode": "HTML"}).encode()
|
|
urllib.request.urlopen(url, data, timeout=10)
|
|
return True
|
|
except Exception:
|
|
return False
|
|
|
|
|
|
def notify_event(event: str, data: dict | None = None):
|
|
if event not in NOTIFY_EVENTS:
|
|
return
|
|
lines = [f"📊 <b>{event}</b> <code>v{APP_VERSION}</code>"]
|
|
if data:
|
|
for k, v in data.items():
|
|
if k in ("signal",):
|
|
continue
|
|
lines.append(f" {k}: {v}")
|
|
send_telegram("\n".join(lines))
|