diff --git a/manual_trading_hub/hub_ai/context.py b/manual_trading_hub/hub_ai/context.py index d86b88c..f7e9ce0 100644 --- a/manual_trading_hub/hub_ai/context.py +++ b/manual_trading_hub/hub_ai/context.py @@ -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), diff --git a/manual_trading_hub/static/dashboard.css b/manual_trading_hub/static/dashboard.css index 978cc25..9959a24 100644 --- a/manual_trading_hub/static/dashboard.css +++ b/manual_trading_hub/static/dashboard.css @@ -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; } diff --git a/manual_trading_hub/static/dashboard.js b/manual_trading_hub/static/dashboard.js index a8be8af..560cb9b 100644 --- a/manual_trading_hub/static/dashboard.js +++ b/manual_trading_hub/static/dashboard.js @@ -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 `${fmt(n, 2)}U`; - } - function floatPnlCell(ln) { const pnl = ln && ln.pnl != null ? Number(ln.pnl) : NaN; if (!Number.isFinite(pnl)) return "—"; return `${fmt(pnl, 2)}`; } + function slTpCell(ln, kind) { + if (kind === "tp") { + const note = String((ln && ln.tp_note) || "").trim(); + if (note) return `${esc(note)}`; + } + 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 @@ ${priceCell(ln && ln.entry_price_fmt, ln && ln.entry_price)} ${priceCell(ln && ln.mark_price_fmt, ln && ln.mark_price)} ${contracts} - ${tpProfitCell(ln)} + ${slTpCell(ln, "sl")} + ${slTpCell(ln, "tp")} ${floatPnlCell(ln)} `; }) @@ -214,7 +222,7 @@
- + ${body}
交易所类型合约方向开仓价标记价张数盈利金额浮盈交易所类型合约方向开仓价标记价张数止损止盈浮盈
diff --git a/manual_trading_hub/static/index.html b/manual_trading_hub/static/index.html index b9dc9cc..2cbef76 100644 --- a/manual_trading_hub/static/index.html +++ b/manual_trading_hub/static/index.html @@ -20,7 +20,7 @@ - + @@ -1385,7 +1385,7 @@ - +