8d69a0cef5
- Gioco GRID TRADERS (sessione 3, regola STRATEGIA_GRIGLIA.md): grid_engine (backtest causale fee-aware della griglia geometrica), grid_brief (digest anonimo per dimensionare la griglia), grid_arena (torneo 100 agenti); diario docs/diary/2026-06-10-grid-traders-game3.md - Gioco OPZIONI: options_engine (BS + skew fittato + DVOL storica), options_arena, opt_calibrate (superficie premi REALE da cerbero-bite) - Gioco SESSION: session_engine/session_arena (pattern orari intraday) - arena: vincolo GAME_NO_LIVE=1 (vieta pairs e fade zscore/breakout/momentum gia' live, coercizione a trend/ma_cross) + normalize del candidato PRIMA della valutazione nel hill-climb - Gate: grid_game_gate (griglia ETH vincitrice vs PORT06, mark-to-market), pairs30m_gate (ETH/BTC 30m ridondante col 15m gia' deployato?) - reset_flatten: flatten one-shot del conto testnet per il reset portafoglio - .gitignore: data/portfolio_paper_stats/ (stato runtime sleeve paper-only) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
65 lines
2.4 KiB
Python
65 lines
2.4 KiB
Python
"""Flatten one-shot del conto Deribit testnet per il RESET del portafoglio (2026-06-10).
|
|
|
|
Cancella gli ordini resting noti (TP limit / disaster-SL dai status.json dei worker),
|
|
poi chiude TUTTE le posizioni USDC con market reduce-only (close_position di cerbero
|
|
non supporta i lineari USDC) e verifica che il conto sia flat.
|
|
|
|
Uso: uv run python scripts/analysis/reset_flatten.py
|
|
"""
|
|
import glob
|
|
import json
|
|
import time
|
|
|
|
from src.live.cerbero_client import CerberoClient
|
|
from src.live.execution import ExecutionClient, contract_spec, register_contract
|
|
|
|
|
|
def main():
|
|
c = CerberoClient()
|
|
ex = ExecutionClient(client=c)
|
|
|
|
# 1) ordini resting noti dai status.json (TP limit + disaster bracket)
|
|
oids = set()
|
|
for f in glob.glob("data/portfolio_paper/*/status.json"):
|
|
s = json.load(open(f))
|
|
for k in ("real_tp_order_id", "real_dsl_order_id"):
|
|
if s.get(k):
|
|
oids.add(s[k])
|
|
for oid in sorted(oids):
|
|
r = ex.cancel_order(oid)
|
|
print(f"cancel {oid}: {r.get('state', r)}")
|
|
|
|
# 2) flatten posizioni USDC (market reduce-only, max 5 passate)
|
|
for attempt in range(5):
|
|
live = [p for p in c.get_positions("USDC")
|
|
if abs(float(p.get("size", 0) or 0)) > 0]
|
|
if not live:
|
|
print("FLAT — conto pulito")
|
|
return True
|
|
for p in live:
|
|
inst = p["instrument"]
|
|
register_contract(inst, c)
|
|
size_usd = abs(float(p["size"]))
|
|
mark = float(p.get("mark_price") or 0)
|
|
step = contract_spec(inst)["step"]
|
|
entry_side = "buy" if p["direction"] == "long" else "sell"
|
|
units = size_usd / mark if mark else 0
|
|
amount = round(units / step) * step
|
|
if amount <= 0:
|
|
print(f" {inst}: residuo {size_usd:.2f} USD sotto mezzo step, ok")
|
|
continue
|
|
f = ex.close_amount(inst, entry_side, amount, label="reset_flatten")
|
|
print(f" close {inst} amt={amount} -> {f.order_state} fill={f.fill_price} "
|
|
f"verified={f.verified} {f.notes[:60]}")
|
|
time.sleep(3)
|
|
|
|
left = [(p["instrument"], round(float(p["size"]), 4))
|
|
for p in c.get_positions("USDC") if abs(float(p.get("size", 0) or 0)) > 0]
|
|
print("RESIDUO FINALE:", left or "FLAT")
|
|
return not left
|
|
|
|
|
|
if __name__ == "__main__":
|
|
ok = main()
|
|
raise SystemExit(0 if ok else 1)
|