From 1a4eb15109dcf60f2d7ac355fcb894ec0c78ba40 Mon Sep 17 00:00:00 2001 From: dekun Date: Wed, 7 Oct 2026 12:06:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=81=A2=E5=A4=8D=E4=B8=AD=E6=8E=A7=E5=BF=AB?= =?UTF-8?q?=E7=85=A7=E4=B9=B0=E4=B8=80/=E6=B5=81=E5=8A=A8=E6=80=A7?= =?UTF-8?q?=EF=BC=8C=E4=B8=8E=E5=AE=9E=E4=BE=8B=E5=90=8C=E6=AD=A5=EF=BC=9B?= =?UTF-8?q?=E6=9C=AA=E9=99=84=E5=B8=A6=20preview=20=E6=97=B6=E4=B8=8D?= =?UTF-8?q?=E5=86=8D=E8=AF=AF=E6=A0=87=E6=AE=8B=E6=A1=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- lib/hub/hub_bridge_register.py | 41 ++++++++++++++++++++++------------ lib/options/options_hub_lib.py | 4 ++-- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/lib/hub/hub_bridge_register.py b/lib/hub/hub_bridge_register.py index 2f62148..0f7f886 100644 --- a/lib/hub/hub_bridge_register.py +++ b/lib/hub/hub_bridge_register.py @@ -57,6 +57,13 @@ def _enrich_hub_protocol(snap: dict[str, Any], *, app_module: Any) -> dict[str, if not isinstance(p, dict): continue 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 [] top = levels[0] if levels and isinstance(levels[0], dict) else {} 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_sz = top.get("available_sheets") 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): uncovered = 0 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): covered = 0 - bid_invalid = bool(preview.get("bid_invalid")) - # 残档/无效买一,或买一深度盖不住持仓 → 流动性不足 - liq_ok = (not bid_invalid) and uncovered <= 0 and ( - preview.get("liquidity_ok") is not False - ) - if not levels and not bid_invalid and covered <= 0: - # 无买一档 - liq_ok = False - bid_invalid = True + 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 ( + preview.get("liquidity_ok") is not False + ) + if not levels and not bid_invalid and covered <= 0: + # 已拉盘口但无可用买一档 + liq_ok = False + bid_invalid = True + if not bid_invalid_reason: + bid_invalid_reason = "无买一" pnl_usdt = p.get("display_pnl_usdt") if pnl_usdt is None: 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"), "bid_px": bid_px, "bid_sz": bid_sz, - "covered_sheets": covered, - "uncovered_sheets": uncovered, + "covered_sheets": covered if preview_present else None, + "uncovered_sheets": uncovered if preview_present else None, "bid_invalid": bid_invalid, - "bid_invalid_reason": preview.get("bid_invalid_reason"), + "bid_invalid_reason": bid_invalid_reason, "liquidity_ok": liq_ok, } ) diff --git a/lib/options/options_hub_lib.py b/lib/options/options_hub_lib.py index cd43471..6930119 100644 --- a/lib/options/options_hub_lib.py +++ b/lib/options/options_hub_lib.py @@ -23,9 +23,9 @@ def build_options_hub_snapshot(cfg: dict[str, Any]) -> dict[str, Any]: raw = cfg["fetch_option_positions"](ex) if raw is None: return {"ok": False, "enabled": True, "msg": "获取期权持仓失败"} - # 中控轮询勿拉买一深度(close_preview),避免超时离线 + # 中控需同步实例买一/流动性;盘口在 DB 已释放后拉取(见 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]] = [] try: