Wide order dialog (calc|form); enrich live cards with lev/bid/margin/time.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-14 16:45:05 +08:00
parent e6701563bd
commit b7b1a7e7e0
4 changed files with 213 additions and 36 deletions
+68 -12
View File
@@ -631,14 +631,26 @@
const profitBox = $("hp-po-exit-profit");
const targetBox = $("hp-po-exit-target");
if (profitBox) {
profitBox.classList.toggle("hidden", mode !== "profit");
if (mode === "profit") profitBox.removeAttribute("hidden");
else profitBox.setAttribute("hidden", "hidden");
const show = mode === "profit";
profitBox.classList.toggle("hidden", !show);
if (show) {
profitBox.removeAttribute("hidden");
profitBox.style.display = "";
} else {
profitBox.setAttribute("hidden", "hidden");
profitBox.style.display = "none";
}
}
if (targetBox) {
targetBox.classList.toggle("hidden", mode !== "target");
if (mode === "target") targetBox.removeAttribute("hidden");
else targetBox.setAttribute("hidden", "hidden");
const show = mode === "target";
targetBox.classList.toggle("hidden", !show);
if (show) {
targetBox.removeAttribute("hidden");
targetBox.style.display = "";
} else {
targetBox.setAttribute("hidden", "hidden");
targetBox.style.display = "none";
}
}
}
@@ -904,6 +916,19 @@
return n > 0 ? "+" + s : s;
}
function fmtDuration(sec) {
if (sec == null || Number.isNaN(Number(sec))) return "—";
let s = Math.max(0, Math.floor(Number(sec)));
const d = Math.floor(s / 86400);
s -= d * 86400;
const h = Math.floor(s / 3600);
s -= h * 3600;
const m = Math.floor(s / 60);
if (d > 0) return d + "天 " + h + "时" + m + "分";
if (h > 0) return h + "时" + m + "分";
return m + "分";
}
function renderLivePosCard(card) {
const opt = card.option || {};
const perp = card.perp || {};
@@ -911,6 +936,11 @@
const optType = String(opt.opt_type || "").toUpperCase() === "P" ? "Put" : "Call";
const perpSide = String(perp.side || "").toLowerCase() === "short" ? "空" : "多";
const comboCls = pnlClsNum(combo.net_usdt);
const liqWarn = opt.liq_ok === false;
const bidTxt =
opt.bid != null
? fmt(opt.bid, 4) + (opt.bid_sz != null ? "/" + fmt(opt.bid_sz, 0) : "")
: "—";
return (
'<article class="hp-live-card" data-plan-id="' +
(card.plan_id || "") +
@@ -920,9 +950,18 @@
(card.plan_id || "—") +
" · " +
(card.underlying || "") +
'</strong><span class="muted">' +
(card.opened_at || "") +
"</span></div>" +
"</strong></div>" +
'<div class="hp-live-time-row">' +
"<span>开仓 <strong>" +
(card.opened_at || "—") +
"</strong></span>" +
"<span>持仓时长 <strong>" +
fmtDuration(card.hold_sec) +
"</strong></span>" +
"<span>到期剩余 <strong>" +
fmtDuration(card.remain_sec) +
"</strong></span>" +
"</div>" +
'<div class="hp-live-legs">' +
'<div class="hp-live-leg">' +
'<div class="hp-live-leg-title">期权 · ' +
@@ -935,12 +974,23 @@
"<span>张数 <strong>" +
fmt(opt.sheets, 0) +
"</strong></span>" +
"<span>杠杆 <strong>" +
(opt.leverage != null ? fmt(opt.leverage, 1) + "×" : "—") +
"</strong></span>" +
"<span>开仓 <strong>" +
fmt(opt.avg_open, 4) +
"</strong></span>" +
"<span>标记 <strong>" +
fmt(opt.mark_px, 4) +
"</strong></span>" +
'<span class="' +
(liqWarn ? "hp-liq-warn" : "") +
'" title="' +
String(opt.liq_msg || "").replace(/"/g, "&quot;") +
'">买一/流动性 <strong>' +
bidTxt +
(liqWarn ? " · 不足" : "") +
"</strong></span>" +
'<span>净利 <strong class="' +
pnlClsNum(opt.net_usdt) +
'">' +
@@ -958,12 +1008,18 @@
"<span>张数 <strong>" +
fmt(perp.contracts, 4) +
"</strong></span>" +
"<span>杠杆 <strong>" +
(perp.leverage != null ? fmt(perp.leverage, 0) + "×" : "—") +
"</strong></span>" +
"<span>开仓 <strong>" +
fmt(perp.avg_open, 2) +
"</strong></span>" +
"<span>标记 <strong>" +
fmt(perp.mark_px, 2) +
"</strong></span>" +
"<span>保证金 <strong>" +
(perp.margin != null ? fmt(perp.margin, 2) + " U" : "—") +
"</strong></span>" +
'<span>净利 <strong class="' +
pnlClsNum(perp.net_usdt) +
'">' +
@@ -985,7 +1041,7 @@
'">成交细节</button> ' +
'<button type="button" class="btn-secondary hp-btn-end" data-id="' +
(card.plan_id || "") +
'">结束计划</button>' +
'">平仓</button>' +
"</div></article>"
);
}
@@ -2864,9 +2920,9 @@
async function endActivePlan(planId) {
if (
!window.confirm(
"确认结束计划 #" +
"确认平仓并结束计划 #" +
planId +
"?\n不会自动平仓;未成交/待补腿将标为未成交取消。\n已有持仓请自行平掉。"
"?\n未成交/待补腿将取消。\n说明:当前为结束计划标记,交易所持仓请自行确认已平。"
)
) {
return;