Refresh perp mark from public ticker when position metrics are unavailable.

Sim/no-keys mode was falling back to entry so 标记 stayed frozen at open price.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-14 17:34:43 +08:00
parent 9295dcffe3
commit 14cbbc300d
2 changed files with 34 additions and 1 deletions
@@ -4,7 +4,7 @@ from __future__ import annotations
from datetime import datetime, timedelta, timezone
from typing import Any, Optional
from lib.hedge_plan.hedge_plan_book_lib import fetch_perp_close_vwap
from lib.hedge_plan.hedge_plan_book_lib import fetch_perp_close_vwap, fetch_perp_mark_px
from lib.hedge_plan.hedge_plan_option_primary_lib import (
estimate_combo_net_pnl,
fee_rate,
@@ -205,6 +205,9 @@ def build_live_hedge_cards(cfg: dict[str, Any], conn: Any) -> list[dict[str, Any
margin = _sf(m.get("initial_margin") or m.get("margin"))
except Exception:
pass
# 模拟盘/无私钥时持仓 metrics 为空,标记会卡在开仓价 → 改拉公开 ticker
if perp_mark is None or perp_mark <= 0:
perp_mark = fetch_perp_mark_px(ex_perp, sym)
if perp_mark is None or perp_mark <= 0:
perp_mark = perp_entry
if live_contracts and live_contracts > 0: