Replace dashboard perp profit column with stop-loss and take-profit.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-20 12:47:16 +08:00
parent 913c7d5be6
commit f467f94fe9
4 changed files with 50 additions and 12 deletions
+26 -2
View File
@@ -291,25 +291,45 @@ def _find_plan_tpsl_for_position(
if not isinstance(hub_mon, dict):
return None, None, False
side_l = (side or "").lower()
if side_l in ("buy",):
side_l = "long"
elif side_l in ("sell",):
side_l = "short"
for o in hub_mon.get("orders") or []:
if not isinstance(o, dict):
continue
o_sym = o.get("exchange_symbol") or o.get("symbol") or ""
if not _symbols_match(symbol, o_sym):
continue
if (o.get("direction") or "").lower() != side_l:
o_side = (o.get("direction") or "").lower()
if o_side and o_side != side_l:
continue
return (
_safe_float(o.get("stop_loss")),
_safe_float(o.get("take_profit")),
False,
)
for r in hub_mon.get("rolls") or []:
if not isinstance(r, dict):
continue
o_sym = r.get("exchange_symbol") or r.get("symbol") or ""
if not _symbols_match(symbol, o_sym):
continue
o_side = (r.get("direction") or "").lower()
if o_side and o_side != side_l:
continue
return (
_safe_float(r.get("stop_loss")),
_safe_float(r.get("take_profit")),
False,
)
for t in hub_mon.get("trends") or []:
if not isinstance(t, dict):
continue
if not _symbols_match(symbol, t.get("symbol") or ""):
continue
if (t.get("direction") or "").lower() != side_l:
t_side = (t.get("direction") or "").lower()
if t_side and t_side != side_l:
continue
plan_tp = t.get("take_profit")
tp = _safe_float(plan_tp) if plan_tp not in (None, "") else None
@@ -1176,6 +1196,7 @@ def format_dashboard_account_detail(ac: dict) -> dict[str, Any]:
if notional is None:
notional = _safe_float(p.get("notional"))
reward_tp = resolve_position_reward_at_tp(p, hub_mon)
tpsl = _resolve_position_tpsl(p, hub_mon)
position_lines.append(
{
"kind": "position",
@@ -1188,6 +1209,9 @@ def format_dashboard_account_detail(ac: dict) -> dict[str, Any]:
"mark_price": mark,
"mark_price_fmt": p.get("mark_price_fmt"),
"notional_usdt": notional,
"stop_loss": tpsl.get("sl"),
"take_profit": tpsl.get("tp"),
"tp_note": tpsl.get("tp_note") or "",
"reward_at_tp_usdt": round(reward_tp, 4) if reward_tp is not None else None,
"text": f"{sym} {side}",
"pnl": round(upnl, 4),