Fix strategy-logic P0s from audit: monitor false-flat, fill-confirmed open/close, mode gates.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-30 09:56:18 +08:00
parent fa7ff739a0
commit 4b4dca9e3c
15 changed files with 820 additions and 167 deletions
+18 -9
View File
@@ -187,7 +187,7 @@ def close_option_by_bid1(
max_levels=1,
)
if preview.get("bid_invalid") or preview.get("auto_close_blocked"):
_cancel_sell_pending(ex, inst_id)
# 不撤他人挂单:仅拒绝本轮下单
update_close_gate(inst_id, recycle_usdc=None, premium_paid=premium_paid)
return {
"ok": False,
@@ -248,8 +248,6 @@ def close_option_by_bid1(
"auto_close_blocked": True,
"close_gate": gate,
}
if gate.get("ready"):
mark_close_gate_passed(inst_id)
locked_bid_px = level_px
before_avail = avail
@@ -272,6 +270,9 @@ def close_option_by_bid1(
"locked_bid_px": locked_bid_px,
"batch_sheets": level_sheets,
}
# 仅下单被接受后才记门控已通过,避免下单失败却跳过后续 2× 等待
if require_recycle_gate and gate.get("ready"):
mark_close_gate_passed(inst_id)
px = float(order.get("px", locked_bid_px))
oid = str((order.get("data") or {}).get("ordId") or "")
@@ -279,12 +280,20 @@ def close_option_by_bid1(
time.sleep(0.6)
invalidate_option_positions_cache()
raw2 = cfg["fetch_option_positions"](ex)
after_avail = 0
if raw2 is not None:
after_pos = next((p for p in raw2 if str(p.get("instId")) == inst_id), None)
after_avail = _avail_sheets(after_pos) if after_pos else 0
reduced = max(0, before_avail - after_avail) if raw2 is not None else 0
remaining_pos = after_avail if raw2 is not None else max(0, before_avail - level_sheets)
if raw2 is None:
return {
"ok": False,
"msg": "下单后获取持仓失败,未确认是否成交",
"stopped_reason": "position_fetch_failed",
"locked_bid_px": locked_bid_px,
"batch_sheets": level_sheets,
"close_ord_id": oid or None,
"fully_closed": False,
}
after_pos = next((p for p in raw2 if str(p.get("instId")) == inst_id), None)
after_avail = _avail_sheets(after_pos) if after_pos else 0
reduced = max(0, before_avail - after_avail)
remaining_pos = after_avail
fully_closed = remaining_pos < 1
if fully_closed: