Use bid1-only option closes with hard-disabled market exits.
Manual close checks liquidity only; target auto still requires 2x recycle hold once, then reuses the shared bid1 executor. Add /options/guide doc and update hedge-plan refs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -40,6 +40,26 @@ def clear_close_gate(inst_id: str | None = None) -> None:
|
||||
_gates.clear()
|
||||
|
||||
|
||||
def mark_close_gate_passed(inst_id: str) -> None:
|
||||
"""标记同仓已通过 2× 门控,续批平仓只验流动性."""
|
||||
inst = (inst_id or "").strip()
|
||||
if not inst:
|
||||
return
|
||||
with _lock:
|
||||
st = _gates.get(inst) or {}
|
||||
st["passed"] = True
|
||||
st["updated"] = time.time()
|
||||
_gates[inst] = st
|
||||
|
||||
|
||||
def is_close_gate_passed(inst_id: str) -> bool:
|
||||
inst = (inst_id or "").strip()
|
||||
if not inst:
|
||||
return False
|
||||
with _lock:
|
||||
return bool((_gates.get(inst) or {}).get("passed"))
|
||||
|
||||
|
||||
def update_close_gate(
|
||||
inst_id: str,
|
||||
*,
|
||||
@@ -86,6 +106,8 @@ def update_close_gate(
|
||||
ok_since = None
|
||||
held = (ts - float(ok_since)) if ok_since is not None else 0.0
|
||||
ready = bool(recycle_ok and held + 1e-9 >= hold)
|
||||
prev_passed = bool(prev.get("passed"))
|
||||
passed = prev_passed or ready
|
||||
state = {
|
||||
"ok_since": ok_since,
|
||||
"recycle": recv,
|
||||
@@ -94,6 +116,7 @@ def update_close_gate(
|
||||
"updated": ts,
|
||||
"min_mult": mult,
|
||||
"hold_seconds": hold,
|
||||
"passed": passed,
|
||||
}
|
||||
_gates[inst] = state
|
||||
|
||||
@@ -103,18 +126,20 @@ def update_close_gate(
|
||||
elif recv is None:
|
||||
msg = "暂无有效买盘可回收金额"
|
||||
elif not recycle_ok:
|
||||
msg = f"可回收 {recv:.4f} USDC < 权利金×{mult:g}({need:.4f}),暂不可平仓"
|
||||
msg = f"可回收 {recv:.4f} USDC < 权利金×{mult:g}({need:.4f}),暂不可自动平仓"
|
||||
elif not ready:
|
||||
msg = (
|
||||
f"可回收已达×{mult:g}({recv:.4f}/{need:.4f}),"
|
||||
f"需再持续 {remain:.0f}s(已 {held:.0f}/{hold:.0f}s)"
|
||||
f"需再持续 {remain:.0f}s(已 {held:.0f}/{hold:.0f}s)后才可自动平仓"
|
||||
)
|
||||
else:
|
||||
msg = f"可回收已达×{mult:g}且持续≥{hold:.0f}s,允许按买盘平仓"
|
||||
msg = f"可回收已达×{mult:g}且持续≥{hold:.0f}s,允许自动按买一平仓"
|
||||
|
||||
auto_blocked = not (ready or passed)
|
||||
return {
|
||||
"ok": True,
|
||||
"ready": ready,
|
||||
"passed": passed,
|
||||
"recycle_ok": recycle_ok,
|
||||
"recycle_usdc": recv,
|
||||
"premium_paid": prem,
|
||||
@@ -125,8 +150,8 @@ def update_close_gate(
|
||||
"remain_seconds": round(remain, 1) if remain is not None else None,
|
||||
"ok_since": ok_since,
|
||||
"msg": msg,
|
||||
"auto_close_blocked": not ready,
|
||||
"close_gate_blocked": not ready,
|
||||
"auto_close_blocked": auto_blocked,
|
||||
"close_gate_blocked": auto_blocked,
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user