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
+30
View File
@@ -105,6 +105,36 @@ def perp_close_book_side(position_side: str) -> str:
return "bids" if str(position_side or "").lower() == "long" else "asks"
def fetch_perp_mark_px(exchange: Any, symbol: str) -> Optional[float]:
"""公开行情标记价:优先 markPx,其次 last / 买卖中间价.模拟盘无持仓 metrics 时用此刷新标记."""
sym = str(symbol or "").strip()
if not sym or exchange is None or not hasattr(exchange, "fetch_ticker"):
return None
try:
t = exchange.fetch_ticker(sym) or {}
info = t.get("info") if isinstance(t.get("info"), dict) else {}
for v in (
info.get("markPx"),
t.get("mark"),
t.get("last"),
info.get("last"),
):
px = _sf(v)
if px is not None and px > 0:
return float(px)
bid = _sf(t.get("bid") or info.get("bidPx"))
ask = _sf(t.get("ask") or info.get("askPx"))
if bid and ask and bid > 0 and ask > 0:
return float((bid + ask) / 2.0)
if bid and bid > 0:
return float(bid)
if ask and ask > 0:
return float(ask)
except Exception:
return None
return None
def fetch_perp_close_vwap(
exchange: Any,
*,