fix(hub): align Binance chart ticks and improve monitor mark price
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -416,9 +416,43 @@ def _position_mark_price(p: dict[str, Any]) -> float | None:
|
||||
for key in (
|
||||
p.get("markPrice"),
|
||||
p.get("mark_price"),
|
||||
p.get("mark"),
|
||||
info.get("markPx"),
|
||||
info.get("mark_price"),
|
||||
info.get("markPrice"),
|
||||
info.get("last"),
|
||||
info.get("lastPrice"),
|
||||
):
|
||||
px = _finite_or_none(key)
|
||||
if px is not None and px > 0:
|
||||
return px
|
||||
contracts = _position_contracts(p)
|
||||
if abs(contracts) >= 1e-12:
|
||||
notional = _finite_or_none(p.get("notional"))
|
||||
if notional is not None and abs(notional) > 0:
|
||||
return abs(notional) / abs(contracts)
|
||||
return None
|
||||
|
||||
|
||||
def _ticker_mark_price(ex: Any, symbol: str) -> float | None:
|
||||
"""持仓行无 mark 时,用 ticker 补标记价(last/mark)。"""
|
||||
sym = (symbol or "").strip()
|
||||
if not sym:
|
||||
return None
|
||||
try:
|
||||
t = ex.fetch_ticker(sym)
|
||||
except Exception:
|
||||
return None
|
||||
if not isinstance(t, dict):
|
||||
return None
|
||||
info = t.get("info") if isinstance(t.get("info"), dict) else {}
|
||||
for key in (
|
||||
t.get("mark"),
|
||||
t.get("last"),
|
||||
t.get("close"),
|
||||
info.get("markPrice"),
|
||||
info.get("mark_price"),
|
||||
info.get("markPx"),
|
||||
):
|
||||
px = _finite_or_none(key)
|
||||
if px is not None and px > 0:
|
||||
@@ -602,6 +636,8 @@ def _status_inner(x_control_token: str | None) -> Any:
|
||||
entry_f = _position_entry_price(p)
|
||||
_, entry_fmt, price_tick = _position_price_fmt(ex, sym, entry_f)
|
||||
mark_f = _position_mark_price(p)
|
||||
if mark_f is None and sym:
|
||||
mark_f = _ticker_mark_price(ex, sym)
|
||||
_, 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
|
||||
|
||||
Reference in New Issue
Block a user