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),
+6
View File
@@ -278,6 +278,12 @@ body.hub-page-dashboard .page#page-dashboard {
font-variant-numeric: tabular-nums;
}
.dash-tp-program {
color: var(--dash-accent);
font-size: 0.72rem;
font-weight: 600;
}
.dash-side {
font-weight: 700;
}
+16 -8
View File
@@ -130,18 +130,25 @@
return "—";
}
function tpProfitCell(ln) {
const n = ln && ln.reward_at_tp_usdt != null ? Number(ln.reward_at_tp_usdt) : NaN;
if (!Number.isFinite(n)) return "—";
return `<span class="dash-tp-profit">${fmt(n, 2)}U</span>`;
}
function floatPnlCell(ln) {
const pnl = ln && ln.pnl != null ? Number(ln.pnl) : NaN;
if (!Number.isFinite(pnl)) return "—";
return `<span class="${pnlClass(pnl)}">${fmt(pnl, 2)}</span>`;
}
function slTpCell(ln, kind) {
if (kind === "tp") {
const note = String((ln && ln.tp_note) || "").trim();
if (note) return `<span class="dash-tp-program">${esc(note)}</span>`;
}
const raw = kind === "sl" ? ln && ln.stop_loss : ln && ln.take_profit;
if (raw == null || raw === "") return "—";
if (Number.isFinite(Number(raw))) {
return esc(fmt(raw, 4).replace(/\.?0+$/, ""));
}
return esc(String(raw));
}
function collectUnifiedPositions(accounts) {
const perp = [];
const options = [];
@@ -204,7 +211,8 @@
<td>${priceCell(ln && ln.entry_price_fmt, ln && ln.entry_price)}</td>
<td>${priceCell(ln && ln.mark_price_fmt, ln && ln.mark_price)}</td>
<td>${contracts}</td>
<td>${tpProfitCell(ln)}</td>
<td>${slTpCell(ln, "sl")}</td>
<td>${slTpCell(ln, "tp")}</td>
<td>${floatPnlCell(ln)}</td>
</tr>`;
})
@@ -214,7 +222,7 @@
<div class="dash-table-wrap">
<table class="dash-table dash-pos-table">
<thead><tr>
<th>交易所</th><th>类型</th><th>合约</th><th>方向</th><th>开仓价</th><th>标记价</th><th>张数</th><th>盈利金额</th><th>浮盈</th>
<th>交易所</th><th>类型</th><th>合约</th><th>方向</th><th>开仓价</th><th>标记价</th><th>张数</th><th>止损</th><th>止盈</th><th>浮盈</th>
</tr></thead>
<tbody>${body}</tbody>
</table>
+2 -2
View File
@@ -20,7 +20,7 @@
<link rel="stylesheet" href="/assets/trade_stats_calendar.css?v=4" />
<link rel="stylesheet" href="/assets/account_risk_badge.css?v=4" />
<script src="/assets/account_risk_badge.js?v=4"></script>
<link rel="stylesheet" href="/assets/dashboard.css?v=20260720-dash-hedge-type" />
<link rel="stylesheet" href="/assets/dashboard.css?v=20260720-dash-sl-tp" />
</head>
<body>
<div class="app-bg" aria-hidden="true"></div>
@@ -1385,7 +1385,7 @@
<script src="/assets/archive.js?v=20260717-archive-cal-chart"></script>
<script src="/assets/quotes.js?v=20260717-quotes-feed"></script>
<script src="/assets/funds.js?v=20260717-funds-scroll-fix"></script>
<script src="/assets/dashboard.js?v=20260720-dash-hedge-type"></script>
<script src="/assets/dashboard.js?v=20260720-dash-sl-tp"></script>
<script src="/assets/strategy.js?v=8"></script>
<script src="/assets/help.js?v=1"></script>
<script src="/assets/logs.js?v=1"></script>