Align funds bar and win-rate with OO expiry intrinsic repair; wire Binance balances.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-11 17:18:16 +08:00
parent 3520fc0214
commit fc74b8e913
5 changed files with 254 additions and 20 deletions
+29 -6
View File
@@ -1035,6 +1035,12 @@ class BinanceLiveExecutor(Matcher):
),
)
now = int(time.time() * 1000)
settle_px = None
if reason == "expiry":
try:
settle_px = self._close_spot_px(get_session().snapshot())
except Exception:
settle_px = None
for i, (leg, inst, qty, contracts) in enumerate(legs):
if not inst:
continue
@@ -1042,6 +1048,29 @@ class BinanceLiveExecutor(Matcher):
px, fee, notional, cash = self._live_option_settlement_fill(
option_inst_id=inst, qty_eth=qty, group_id=group_id
)
if settle_px is not None and qty > 0:
if leg == "option":
side = str(pos.get("option_side") or "call")
strike = self._group_strike(group_id, inst)
else:
side = str(pos.get("option2_side") or "put")
try:
strike = float(pos.get("strike2") or 0) or None
except (TypeError, ValueError):
strike = None
if strike is not None:
iv = float(
option_intrinsic(
option_side=side,
strike=float(strike),
spot=float(settle_px),
)
)
tol = max(0.5, abs(iv) * 0.05)
if abs(float(px) - iv) > tol:
px = iv
notional = iv * float(qty)
cash = notional - float(fee or 0)
else:
px, fee, notional, cash = 0.0, 0.0, 0.0, 0.0
if abs(cash) > 1e-12:
@@ -1082,12 +1111,6 @@ class BinanceLiveExecutor(Matcher):
)
summary = summarize_fills_pnl(list(fill_rows))
net = float(summary.get("net_pnl") or 0.0)
settle_px = None
if reason == "expiry":
try:
settle_px = self._close_spot_px(get_session().snapshot())
except Exception:
settle_px = None
with self.db._lock:
self.db._conn.execute(
"""UPDATE groups SET status=?, close_at_ms=?, close_reason=?, realized_pnl=?,