@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user