修复平仓后查仓失败仍卖币,并恢复期权说明页。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-07 16:19:18 +08:00
parent a23fb7cbdc
commit a45b5d1b0b
4 changed files with 222 additions and 14 deletions
+18 -13
View File
@@ -574,22 +574,27 @@ def maybe_sell_spot_after_close(
inst_id: str,
close_result: dict[str, Any] | None = None,
) -> dict[str, Any] | None:
"""期权平仓后若该合约为币本位且已空仓,卖回本桥残留币."""
"""期权平仓后若该合约为币本位且已空仓,卖回本桥残留币.
持仓查询失败/空响应时不卖,等下次监控再查(与 sweep_spot_after_options_flat 一致).
"""
del close_result # 预留字段;卖回只认交易所持仓实况
if margin_mode_from_inst_id(inst_id) != "coin":
return None
# 仍有仓则不卖
try:
rows = cfg["fetch_option_positions"](ex) or []
for p in rows:
if str(p.get("instId") or p.get("inst_id") or "") != inst_id:
continue
try:
if abs(float(p.get("pos") or 0)) > 1e-12:
return {"ok": True, "skipped": True, "msg": "仍有持仓,暂不卖币"}
except (TypeError, ValueError):
pass
except Exception:
pass
rows = cfg["fetch_option_positions"](ex)
except Exception as e:
return {"ok": False, "msg": f"持仓查询失败,暂不卖币: {e}", "skipped": True}
if rows is None:
return {"ok": False, "msg": "持仓查询失败: 空响应,暂不卖币", "skipped": True}
for p in rows or []:
if str(p.get("instId") or p.get("inst_id") or "") != inst_id:
continue
try:
if abs(float(p.get("pos") or 0)) > 1e-12:
return {"ok": True, "skipped": True, "msg": "仍有持仓,暂不卖币"}
except (TypeError, ValueError):
pass
parts = inst_id.split("-")
underlying = (parts[0] if parts else "ETH").upper()
return _spot_bridge.sell_residual_after_option_flat(
+1 -1
View File
@@ -438,7 +438,7 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
from flask import render_template_string
from lib.hub.hub_strategy_lib import render_markdown_html
from lib.common.markdown_html_lib import render_markdown_html
md_path = Path(__file__).resolve().parents[2] / "docs" / "期权开平仓与监控说明.md"
try: