Align hedge-plan perp contract precision with exchange and show TP/SL USDT PnL.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -177,6 +177,7 @@
|
||||
const acctLabel = d.account_label || "合约账户";
|
||||
const tag = $("hp-perp-acct-tag");
|
||||
if (tag) tag.textContent = acctLabel;
|
||||
const amtPrec = d.amount_precision != null ? Number(d.amount_precision) : 4;
|
||||
const q = $("hp-perp-quote");
|
||||
if (q) {
|
||||
q.innerHTML =
|
||||
@@ -186,7 +187,7 @@
|
||||
acctLabel +
|
||||
"可用 <strong>" +
|
||||
fmt(d.available_usdt, 2) +
|
||||
"</strong> U<br/>标记 <strong>" +
|
||||
"</strong> USDT<br/>标记 <strong>" +
|
||||
fmt(d.mark, 2) +
|
||||
"</strong> · 最新 " +
|
||||
fmt(d.last, 2) +
|
||||
@@ -195,7 +196,15 @@
|
||||
" · 买一 " +
|
||||
fmt(d.bid, 2) +
|
||||
" · 面值 " +
|
||||
fmt(d.contract_size, 4);
|
||||
fmt(d.contract_size, 4) +
|
||||
" · 张精度 " +
|
||||
amtPrec +
|
||||
" 位";
|
||||
}
|
||||
const contractsInput = $("hp-contracts");
|
||||
if (contractsInput) {
|
||||
const step = amtPrec <= 0 ? "1" : String(Math.pow(10, -amtPrec));
|
||||
contractsInput.step = step;
|
||||
}
|
||||
const sz = $("hp-sizing-line");
|
||||
if (sz) {
|
||||
@@ -206,25 +215,73 @@
|
||||
acctLabel +
|
||||
"):保证金 " +
|
||||
fmt(s.margin_capital, 2) +
|
||||
"U × " +
|
||||
" USDT × " +
|
||||
s.leverage +
|
||||
"x → 名义 " +
|
||||
fmt(s.notional_value, 2) +
|
||||
"U · 建议约 " +
|
||||
fmt(d.suggest_contracts, 4) +
|
||||
" 张";
|
||||
" USDT · 建议 " +
|
||||
fmt(d.suggest_contracts, amtPrec) +
|
||||
" 合约张(已按交易所精度)";
|
||||
} else {
|
||||
sz.textContent = "非全仓或不具备保证金数据时仅手动填张数;永期开仓需全仓.";
|
||||
}
|
||||
}
|
||||
const entry = $("hp-entry");
|
||||
if (entry && d.entry_ref && !entry.value) entry.value = d.entry_ref;
|
||||
const contracts = $("hp-contracts");
|
||||
if (contracts && d.suggest_contracts != null && !contracts.value) {
|
||||
contracts.value = d.suggest_contracts;
|
||||
if (contractsInput && d.suggest_contracts != null && !contractsInput.value) {
|
||||
contractsInput.value = fmt(d.suggest_contracts, amtPrec);
|
||||
}
|
||||
const label = $("hp-opt-type-label");
|
||||
if (label) label.textContent = d.suggested_opt_type === "C" ? "Call" : "Put";
|
||||
updatePerpPnlHint();
|
||||
}
|
||||
|
||||
function updatePerpPnlHint() {
|
||||
const el = $("hp-perp-pnl-line");
|
||||
if (!el) return;
|
||||
const entry = Number(($("hp-entry") && $("hp-entry").value) || NaN);
|
||||
const tp = Number(($("hp-tp") && $("hp-tp").value) || NaN);
|
||||
const sl = Number(($("hp-sl") && $("hp-sl").value) || NaN);
|
||||
const contracts = Number(($("hp-contracts") && $("hp-contracts").value) || NaN);
|
||||
const cs = Number((state.market && state.market.contract_size) || 0.01);
|
||||
const dir = (($("hp-direction") && $("hp-direction").value) || "long").toLowerCase();
|
||||
if (!(entry > 0) || !(contracts > 0) || !(cs > 0)) {
|
||||
el.textContent = "填写开仓价与张数后,输入止盈/止损可看永续盈亏金额(USDT)";
|
||||
return;
|
||||
}
|
||||
function pnlAt(exitPx) {
|
||||
const coins = contracts * cs;
|
||||
if (dir === "short") return (entry - exitPx) * coins;
|
||||
return (exitPx - entry) * coins;
|
||||
}
|
||||
const parts = [];
|
||||
if (tp > 0) {
|
||||
const p = pnlAt(tp);
|
||||
parts.push(
|
||||
"止盈预期 <strong class=\"" +
|
||||
(p >= 0 ? "hp-pnl-pos" : "hp-pnl-neg") +
|
||||
"\">" +
|
||||
(p >= 0 ? "+" : "") +
|
||||
fmt(p, 2) +
|
||||
" USDT</strong>"
|
||||
);
|
||||
} else {
|
||||
parts.push("止盈预期 —");
|
||||
}
|
||||
if (sl > 0) {
|
||||
const p = pnlAt(sl);
|
||||
parts.push(
|
||||
"止损预期 <strong class=\"" +
|
||||
(p >= 0 ? "hp-pnl-pos" : "hp-pnl-neg") +
|
||||
"\">" +
|
||||
(p >= 0 ? "+" : "") +
|
||||
fmt(p, 2) +
|
||||
" USDT</strong>"
|
||||
);
|
||||
} else {
|
||||
parts.push("止损预期 —");
|
||||
}
|
||||
el.innerHTML = parts.join(" · ");
|
||||
}
|
||||
|
||||
function fillExpSelect(sel, chain) {
|
||||
@@ -632,6 +689,10 @@
|
||||
});
|
||||
});
|
||||
}
|
||||
["hp-entry", "hp-tp", "hp-sl", "hp-contracts"].forEach(function (id) {
|
||||
const el = $(id);
|
||||
if (el) el.addEventListener("input", updatePerpPnlHint);
|
||||
});
|
||||
if ($("hp-refresh"))
|
||||
$("hp-refresh").addEventListener("click", function () {
|
||||
void refreshAll();
|
||||
|
||||
@@ -3212,6 +3212,28 @@ html[data-theme="light"] .opt-be-dist-down {
|
||||
font-weight: 500;
|
||||
margin-left: 4px;
|
||||
}
|
||||
.hedge-plan-page-wrap .hp-unit {
|
||||
font-size: 0.66rem;
|
||||
color: #8892b0;
|
||||
font-weight: 500;
|
||||
margin-right: 2px;
|
||||
}
|
||||
.hedge-plan-page-wrap .hp-unit-hint {
|
||||
font-size: 0.68rem;
|
||||
margin: 2px 0 6px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
.hedge-plan-page-wrap #hp-perp-pnl-line {
|
||||
font-size: 0.74rem;
|
||||
margin: 4px 0 6px;
|
||||
line-height: 1.45;
|
||||
}
|
||||
.hedge-plan-page-wrap .hp-pnl-pos {
|
||||
color: #7ee787;
|
||||
}
|
||||
.hedge-plan-page-wrap .hp-pnl-neg {
|
||||
color: #ff8a8a;
|
||||
}
|
||||
.hedge-plan-page-wrap .form-row label,
|
||||
.hedge-plan-page-wrap .form-row select,
|
||||
.hedge-plan-page-wrap .form-row input,
|
||||
|
||||
Reference in New Issue
Block a user