feat(hub): show exchange mark price on monitor positions

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-03 22:25:23 +08:00
parent 5b6babd699
commit c1fda1e7d5
4 changed files with 72 additions and 2 deletions
+24
View File
@@ -408,6 +408,24 @@ def _position_entry_price(p: dict[str, Any]) -> float | None:
return None
def _position_mark_price(p: dict[str, Any]) -> float | None:
"""四所 ccxt 持仓统一解析标记价(用于强平/浮盈计算)。"""
info = p.get("info") or {}
if not isinstance(info, dict):
info = {}
for key in (
p.get("markPrice"),
p.get("mark_price"),
info.get("markPx"),
info.get("mark_price"),
info.get("markPrice"),
):
px = _finite_or_none(key)
if px is not None and px > 0:
return px
return None
def _extract_usdt_total(balance: dict[str, Any]) -> float | None:
"""从 ccxt balance 结构中尽量取出 USDT 总额(与 crypto_monitor_binance 一致)。"""
usdt_info = balance.get("USDT") or {}
@@ -583,6 +601,10 @@ def _status_inner(x_control_token: str | None) -> Any:
notional_f = None
entry_f = _position_entry_price(p)
_, entry_fmt, price_tick = _position_price_fmt(ex, sym, entry_f)
mark_f = _position_mark_price(p)
_, mark_fmt, mark_tick = _position_price_fmt(ex, sym, mark_f)
if price_tick is None and mark_tick is not None:
price_tick = mark_tick
positions_out.append(
{
"symbol": sym,
@@ -593,6 +615,8 @@ def _status_inner(x_control_token: str | None) -> Any:
"unrealized_pnl": _finite_or_none(upnl_f),
"entry_price": entry_f,
"entry_price_fmt": entry_fmt,
"mark_price": mark_f,
"mark_price_fmt": mark_fmt,
"price_tick": _finite_or_none(price_tick) if price_tick is not None else None,
}
)