feat(live): fallback OHLCV a Deribit MAINNET quando Cerbero/testnet e' giu'
Deribit testnet (test.deribit.com) va giu' periodicamente (502) e Cerbero lo rilancia -> il runner si bloccava senza dati. Aggiunto CerberoClient.get_historical_mainnet (Deribit MAINNET public, NO-AUTH, paginato sotto il cap ~5000 candele/chiamata) e fallback nel runner: try Cerbero -> on fail/empty usa mainnet. Prezzi REALI (meglio del testnet farlocco per il paper). Verificato durante l'outage: tutti gli 8 strumenti (BTC/ETH + alt _USDC) coperti su mainnet. Log una-tantum all'attivazione/disattivazione del fallback. Caveat: testnet e mainnet hanno prezzi diversi (~9%) -> al primo switch le posizioni aperte su prezzi testnet vanno resettate (transizione pulita). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+19
-2
@@ -39,6 +39,9 @@ _LOOKBACK_DAYS = {"1h": 90, "4h": 220, "1d": 440}
|
||||
# margine ampio per il walk-forward. Difensivo: non dipende dal fetch 440g di TSM01/ROT02.
|
||||
_ML_LOOKBACK_DAYS = 365
|
||||
|
||||
# stato del fallback dati: True quando Cerbero (testnet) è giù e usiamo Deribit MAINNET public
|
||||
_MAINNET_FALLBACK = {"on": False}
|
||||
|
||||
|
||||
def build_worker_for(spec: SleeveSpec, alloc_capital: float, leverage: float,
|
||||
data_dir: Path = DATA_DIR, position_size: float = 0.15):
|
||||
@@ -182,8 +185,22 @@ def run(config_path: str = "portfolios.yml"):
|
||||
for asset, days in asset_days.items():
|
||||
inst = inst_map.get(asset, f"{asset}-PERPETUAL")
|
||||
start = end - timedelta(days=days)
|
||||
candles = client.get_historical_v2(inst, start.strftime("%Y-%m-%d"),
|
||||
end.strftime("%Y-%m-%d"), "1h")
|
||||
candles = None
|
||||
try:
|
||||
candles = client.get_historical_v2(inst, start.strftime("%Y-%m-%d"),
|
||||
end.strftime("%Y-%m-%d"), "1h")
|
||||
except Exception:
|
||||
candles = None
|
||||
if not candles:
|
||||
# FALLBACK: Cerbero (testnet) giù -> OHLCV reale da Deribit MAINNET public
|
||||
candles = client.get_historical_mainnet(
|
||||
inst, int(start.timestamp() * 1000), int(end.timestamp() * 1000), "60")
|
||||
if candles and not _MAINNET_FALLBACK["on"]:
|
||||
_MAINNET_FALLBACK["on"] = True
|
||||
print("[runner] FALLBACK attivo: OHLCV da Deribit MAINNET (Cerbero/testnet non disponibile)")
|
||||
elif _MAINNET_FALLBACK["on"]:
|
||||
_MAINNET_FALLBACK["on"] = False
|
||||
print("[runner] Cerbero tornato disponibile: fallback mainnet disattivato")
|
||||
if candles:
|
||||
df = pd.DataFrame(candles)
|
||||
df["timestamp"] = df["timestamp"].astype("int64")
|
||||
|
||||
Reference in New Issue
Block a user