Gate option closes behind 2x recycle sustained for 2 minutes.

Require bid-side recoverable premium at least 2x cost continuously before target auto-close or depth close can fire.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-15 21:13:43 +08:00
parent c025c06fac
commit c2a0cea3f4
7 changed files with 387 additions and 38 deletions
+24 -1
View File
@@ -5,6 +5,7 @@ from typing import Any
from lib.options.options_db import init_options_tables
from lib.options.options_history_lib import enrich_position_row_display
from lib.options.options_close_gate_lib import clear_close_gate, update_close_gate
from lib.options.options_pricing_lib import estimate_close_by_bids, intrinsic_px_per_unit
@@ -40,7 +41,7 @@ def attach_close_preview(
_safe_float(row.get("strike") or row.get("stk")),
_safe_float(row.get("idx_px") or row.get("idxPx")),
)
row["close_preview"] = estimate_close_by_bids(
preview = estimate_close_by_bids(
row["bid_depth"],
target_sheets,
ct_mult=ct_mult,
@@ -48,9 +49,31 @@ def attach_close_preview(
mark_px=mark_px,
intrinsic_px=intrinsic,
)
# 残档时不累计 2×权利金门控;有效回收时刷新持续计时
if preview.get("bid_invalid") or preview.get("auto_close_blocked"):
gate = update_close_gate(inst_id, recycle_usdc=None, premium_paid=paid)
preview["close_gate"] = gate
preview["close_gate_blocked"] = True
preview["close_gate_msg"] = preview.get("bid_invalid_reason") or gate.get("msg")
else:
gate = update_close_gate(
inst_id,
recycle_usdc=_safe_float(preview.get("total_received")),
premium_paid=paid,
)
preview["close_gate"] = gate
preview["close_gate_blocked"] = not gate.get("ready")
preview["close_gate_msg"] = gate.get("msg")
if not gate.get("ready"):
preview["auto_close_blocked"] = True
row["close_preview"] = preview
return row
def forget_close_gate_for_inst(inst_id: str) -> None:
clear_close_gate(inst_id)
def build_display_option_positions(
cfg: dict[str, Any],
ex: Any,