恢复中控快照买一/流动性,与实例同步;未附带 preview 时不再误标残档。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-07 12:06:43 +08:00
parent 77fe0fa679
commit 1a4eb15109
2 changed files with 29 additions and 16 deletions
+21 -8
View File
@@ -57,6 +57,13 @@ def _enrich_hub_protocol(snap: dict[str, Any], *, app_module: Any) -> dict[str,
if not isinstance(p, dict): if not isinstance(p, dict):
continue continue
preview = p.get("close_preview") if isinstance(p.get("close_preview"), dict) else {} preview = p.get("close_preview") if isinstance(p.get("close_preview"), dict) else {}
# 仅在实例已附带 close_preview 时判定残档;缺字段=未同步,勿假装「无买一/残档」
preview_present = bool(preview) and (
"bid_invalid" in preview
or "levels" in preview
or "covered_sheets" in preview
or "liquidity_ok" in preview
)
levels = preview.get("levels") if isinstance(preview.get("levels"), list) else [] levels = preview.get("levels") if isinstance(preview.get("levels"), list) else []
top = levels[0] if levels and isinstance(levels[0], dict) else {} top = levels[0] if levels and isinstance(levels[0], dict) else {}
bid_px = top.get("px") bid_px = top.get("px")
@@ -64,22 +71,28 @@ def _enrich_hub_protocol(snap: dict[str, Any], *, app_module: Any) -> dict[str,
bid_px = preview.get("raw_bid_px") bid_px = preview.get("raw_bid_px")
bid_sz = top.get("available_sheets") bid_sz = top.get("available_sheets")
try: try:
uncovered = int(float(preview.get("uncovered_sheets") or 0)) uncovered = int(float(preview.get("uncovered_sheets") or 0)) if preview_present else 0
except (TypeError, ValueError): except (TypeError, ValueError):
uncovered = 0 uncovered = 0
try: try:
covered = int(float(preview.get("covered_sheets") or 0)) covered = int(float(preview.get("covered_sheets") or 0)) if preview_present else 0
except (TypeError, ValueError): except (TypeError, ValueError):
covered = 0 covered = 0
bid_invalid = bool(preview.get("bid_invalid")) bid_invalid = bool(preview.get("bid_invalid")) if preview_present else False
# 残档/无效买一,或买一深度盖不住持仓 → 流动性不足 bid_invalid_reason = preview.get("bid_invalid_reason") if preview_present else None
# 残档/无效买一,或买一深度盖不住持仓 → 流动性不足;未同步时不标黄残档
if not preview_present:
liq_ok = None
else:
liq_ok = (not bid_invalid) and uncovered <= 0 and ( liq_ok = (not bid_invalid) and uncovered <= 0 and (
preview.get("liquidity_ok") is not False preview.get("liquidity_ok") is not False
) )
if not levels and not bid_invalid and covered <= 0: if not levels and not bid_invalid and covered <= 0:
# 无买一档 # 已拉盘口但无可用买一档
liq_ok = False liq_ok = False
bid_invalid = True bid_invalid = True
if not bid_invalid_reason:
bid_invalid_reason = "无买一"
pnl_usdt = p.get("display_pnl_usdt") pnl_usdt = p.get("display_pnl_usdt")
if pnl_usdt is None: if pnl_usdt is None:
try: try:
@@ -132,10 +145,10 @@ def _enrich_hub_protocol(snap: dict[str, Any], *, app_module: Any) -> dict[str,
"target_monitor_text": p.get("target_monitor_text"), "target_monitor_text": p.get("target_monitor_text"),
"bid_px": bid_px, "bid_px": bid_px,
"bid_sz": bid_sz, "bid_sz": bid_sz,
"covered_sheets": covered, "covered_sheets": covered if preview_present else None,
"uncovered_sheets": uncovered, "uncovered_sheets": uncovered if preview_present else None,
"bid_invalid": bid_invalid, "bid_invalid": bid_invalid,
"bid_invalid_reason": preview.get("bid_invalid_reason"), "bid_invalid_reason": bid_invalid_reason,
"liquidity_ok": liq_ok, "liquidity_ok": liq_ok,
} }
) )
+2 -2
View File
@@ -23,9 +23,9 @@ def build_options_hub_snapshot(cfg: dict[str, Any]) -> dict[str, Any]:
raw = cfg["fetch_option_positions"](ex) raw = cfg["fetch_option_positions"](ex)
if raw is None: if raw is None:
return {"ok": False, "enabled": True, "msg": "获取期权持仓失败"} return {"ok": False, "enabled": True, "msg": "获取期权持仓失败"}
# 中控轮询勿拉买一深度(close_preview),避免超时离线 # 中控需同步实例买一/流动性;盘口在 DB 已释放后拉取(见 build_display_option_positions)
positions = build_display_option_positions( positions = build_display_option_positions(
cfg, ex, raw, include_close_preview=False cfg, ex, raw, include_close_preview=True
) )
target_monitors: list[dict[str, Any]] = [] target_monitors: list[dict[str, Any]] = []
try: try: