中控快照增加买一/流动性字段,便于总览标黄不足仓位。
含买一价、张数、未覆盖张数与残档标记。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -54,17 +54,54 @@ def _enrich_hub_protocol(snap: dict[str, Any], *, app_module: Any) -> dict[str,
|
||||
for p in positions:
|
||||
if not isinstance(p, dict):
|
||||
continue
|
||||
preview = p.get("close_preview") if isinstance(p.get("close_preview"), dict) else {}
|
||||
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")
|
||||
if bid_px is None:
|
||||
bid_px = preview.get("raw_bid_px")
|
||||
bid_sz = top.get("available_sheets")
|
||||
try:
|
||||
uncovered = int(float(preview.get("uncovered_sheets") or 0))
|
||||
except (TypeError, ValueError):
|
||||
uncovered = 0
|
||||
try:
|
||||
covered = int(float(preview.get("covered_sheets") or 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
|
||||
pnl_usdt = p.get("display_pnl_usdt")
|
||||
if pnl_usdt is None:
|
||||
try:
|
||||
from lib.options.options_positions_lib import display_pnl_usdt_from_option_row
|
||||
|
||||
pnl_usdt = display_pnl_usdt_from_option_row(p)
|
||||
except Exception:
|
||||
pnl_usdt = p.get("net_pnl_usdt")
|
||||
slim_pos.append(
|
||||
{
|
||||
"inst_id": p.get("inst_id"),
|
||||
"opt_type": p.get("opt_type"),
|
||||
"sheets": p.get("sheets") or p.get("pos"),
|
||||
"pnl_usdt": p.get("display_pnl_usdt")
|
||||
if p.get("display_pnl_usdt") is not None
|
||||
else p.get("net_pnl_usdt"),
|
||||
"pnl_usdt": pnl_usdt,
|
||||
"mark": p.get("mark") or p.get("mark_px"),
|
||||
"underlying": p.get("underlying"),
|
||||
"source_label": p.get("source_label"),
|
||||
"bid_px": bid_px,
|
||||
"bid_sz": bid_sz,
|
||||
"covered_sheets": covered,
|
||||
"uncovered_sheets": uncovered,
|
||||
"bid_invalid": bid_invalid,
|
||||
"bid_invalid_reason": preview.get("bid_invalid_reason"),
|
||||
"liquidity_ok": liq_ok,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -83,6 +83,7 @@ def build_options_hub_snapshot(cfg: dict[str, Any]) -> dict[str, Any]:
|
||||
for p in positions:
|
||||
# 合计一律折 U:币本位 × 指数,避免 BTC/ETH 币数量与 USDC 混加
|
||||
pnl = display_pnl_usdt_from_option_row(p)
|
||||
p["display_pnl_usdt"] = pnl
|
||||
if pnl is None:
|
||||
continue
|
||||
has_upl = True
|
||||
|
||||
Reference in New Issue
Block a user