feat: 持仓快照盈亏比与交易所止损已保本标识
盈亏比固定用开仓 initial_stop_loss 计算,人工改委托后不变化;轮询交易所止损触发价相对成交价判定已保本,四所实例与中控统一显示绿色标识。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -403,6 +403,28 @@
|
||||
return reward / risk;
|
||||
}
|
||||
|
||||
function resolveSnapshotRr(mo, side, entry, sl, tp, tpMonitored) {
|
||||
if (tpMonitored) return null;
|
||||
const snap = mo && mo.rr_ratio;
|
||||
if (snap != null && snap !== "") {
|
||||
const n = Number(snap);
|
||||
if (Number.isFinite(n)) return n;
|
||||
}
|
||||
const initSl = mo && (mo.initial_stop_loss != null ? mo.initial_stop_loss : mo.stop_loss);
|
||||
return calcRrRatio(side, entry, initSl || sl, tp);
|
||||
}
|
||||
|
||||
function isBreakevenSecured(side, entry, monitorOrder, cond) {
|
||||
const mo = monitorOrder || {};
|
||||
if (mo.sl_breakeven_secured === true || mo.sl_breakeven_secured === 1) return true;
|
||||
const { sl } = pickExTpslOrders(cond);
|
||||
const trig = sl && sl.trigger_price != null ? Number(sl.trigger_price) : NaN;
|
||||
const e = Number(entry);
|
||||
if (!Number.isFinite(trig) || !Number.isFinite(e)) return false;
|
||||
if ((side || "long").toLowerCase() === "short") return trig <= e;
|
||||
return trig >= e;
|
||||
}
|
||||
|
||||
async function loadMonitorBoard() {
|
||||
const box = document.getElementById("monitor-grid");
|
||||
const showLoading = !lastMonitorRows.length;
|
||||
@@ -932,7 +954,8 @@
|
||||
const sl = tpsl.sl;
|
||||
const tp = tpsl.tp;
|
||||
const tpMonitored = tpsl.tp_monitored;
|
||||
const rr = tpMonitored ? null : calcRrRatio(side, entry, sl, tp);
|
||||
const rr = resolveSnapshotRr(mo, side, entry, sl, tp, tpMonitored);
|
||||
const beSecured = isBreakevenSecured(side, entry, mo, cond);
|
||||
const upnl = pos.unrealized_pnl;
|
||||
let pnlText = fmt(upnl, 2) + "U";
|
||||
if (pos.notional_usdt && upnl != null && Math.abs(Number(pos.notional_usdt)) > 1e-8) {
|
||||
@@ -956,6 +979,9 @@
|
||||
meta.push(
|
||||
`<span class="${beOn ? "pos-meta-on" : "pos-meta-off"}">移动保本:${beOn ? "开" : "关"}</span>`
|
||||
);
|
||||
if (beSecured) {
|
||||
meta.push(`<span class="pos-meta-item"><span class="pos-breakeven-badge">已保本</span></span>`);
|
||||
}
|
||||
const mktAttrs = marketOpenBtnAttrs(exchangeId, exchangeKey, symbol, pos, monitorOrder, trendPlan);
|
||||
return `<div class="pos-card hub-pos-card">
|
||||
<div class="pos-card-head">
|
||||
|
||||
Reference in New Issue
Block a user