修复币本位报价误走USDC,中控补资金账户并隐藏零币余额
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -926,18 +926,29 @@
|
||||
return Math.round(intrinsic * amt * 100) / 100;
|
||||
}
|
||||
|
||||
function estimateExpiryProfit(optType, strike, targetIdx, ethAmount, totalPremium) {
|
||||
function estimateExpiryProfit(optType, strike, targetIdx, ethAmount, totalPremium, indexPx) {
|
||||
const value = estimateExpiryValue(optType, strike, targetIdx, ethAmount);
|
||||
const prem = Number(totalPremium);
|
||||
let prem = Number(totalPremium);
|
||||
if (value == null || !Number.isFinite(prem)) return null;
|
||||
// 币本位权利金为币:与到期美元实值对比时先×指数
|
||||
if (isCoinMarginMode()) {
|
||||
const idx = Number(indexPx);
|
||||
if (!Number.isFinite(idx) || idx <= 0) return null;
|
||||
prem = prem * idx;
|
||||
}
|
||||
return Math.round((value - prem) * 100) / 100;
|
||||
}
|
||||
|
||||
/** 盈亏比 = 盈利金额 / 本合约权利金(目标位仅作到期实值参考). */
|
||||
function estimateProfitRr(profit, totalPremium) {
|
||||
function estimateProfitRr(profit, totalPremium, indexPx) {
|
||||
const pnl = Number(profit);
|
||||
const prem = Number(totalPremium);
|
||||
let prem = Number(totalPremium);
|
||||
if (!Number.isFinite(pnl) || !Number.isFinite(prem) || prem <= 0) return null;
|
||||
if (isCoinMarginMode()) {
|
||||
const idx = Number(indexPx);
|
||||
if (!Number.isFinite(idx) || idx <= 0) return null;
|
||||
prem = prem * idx;
|
||||
}
|
||||
return Math.round((pnl / prem) * 100) / 100;
|
||||
}
|
||||
|
||||
@@ -1033,18 +1044,22 @@
|
||||
}
|
||||
} else {
|
||||
const value = estimateExpiryValue(q.opt_type, q.strike, Number(targetRaw), ethAmount);
|
||||
const profit = estimateExpiryProfit(q.opt_type, q.strike, Number(targetRaw), ethAmount, premium);
|
||||
const rr = estimateProfitRr(profit, premium);
|
||||
const profit = estimateExpiryProfit(q.opt_type, q.strike, Number(targetRaw), ethAmount, premium, q.index_px);
|
||||
const rr = estimateProfitRr(profit, premium, q.index_px);
|
||||
if (value == null || Number.isNaN(value)) {
|
||||
valueEl.textContent = "—";
|
||||
} else {
|
||||
valueEl.textContent = fmtUsdc(value) + " USDC";
|
||||
valueEl.textContent = isCoinMarginMode()
|
||||
? (fmtUsdc(value) + " U(估)")
|
||||
: (fmtUsdc(value) + " USDC");
|
||||
}
|
||||
if (profit == null || Number.isNaN(profit)) {
|
||||
profitEl.textContent = "—";
|
||||
profitEl.className = "v";
|
||||
} else {
|
||||
profitEl.textContent = fmtUsdcSigned(profit);
|
||||
profitEl.textContent = isCoinMarginMode()
|
||||
? ((Number(profit) > 0 ? "+" : "") + fmtUsdc(profit) + " U(估)")
|
||||
: fmtUsdcSigned(profit);
|
||||
profitEl.className = "v " + pnlCls(profit);
|
||||
}
|
||||
if (rrEl) {
|
||||
@@ -1264,8 +1279,12 @@
|
||||
document.getElementById("opt-order-sheets").textContent = canOpen && sz.sheets != null ? sz.sheets : "—";
|
||||
document.getElementById("opt-order-eth").textContent = canOpen && sz.eth_amount != null ? sz.eth_amount : "—";
|
||||
updateUnderlyingLabel();
|
||||
const coinMode = isCoinMarginMode() || (d && d.options_margin_mode === "coin");
|
||||
const premCcy = (sz.premium_ccy || (coinMode ? ((d.inst_id || "").split("-")[0] || "ETH") : "USDC")).toUpperCase();
|
||||
document.getElementById("opt-order-premium").textContent =
|
||||
canOpen && sz.total_premium != null ? fmtUsdc(sz.total_premium) + " USDC" : "—";
|
||||
canOpen && sz.total_premium != null
|
||||
? (coinMode ? (fmt(sz.total_premium, 6) + " " + premCcy) : (fmtUsdc(sz.total_premium) + " USDC"))
|
||||
: "—";
|
||||
const beEl = document.getElementById("opt-order-expiry-be");
|
||||
const distEl = document.getElementById("opt-order-dist-be");
|
||||
if (beEl) {
|
||||
@@ -1278,10 +1297,12 @@
|
||||
const openBtn = document.getElementById("opt-open-btn");
|
||||
if (openBtn) {
|
||||
openBtn.disabled = !canOpen || sz.ok === false;
|
||||
const coinMode = (state.chain && state.chain.margin_mode === "coin") || (state.chain && state.chain.options_margin_mode === "coin");
|
||||
const bud = state.chain && state.chain.coin_budget && state.chain.coin_budget.budget_usdt;
|
||||
if (!canOpen) {
|
||||
openBtn.textContent = "暂无卖一深度,无法开仓";
|
||||
const bud = (d && d.coin_budget && d.coin_budget.budget_usdt) ||
|
||||
(state.chain && state.chain.coin_budget && state.chain.coin_budget.budget_usdt);
|
||||
if (!canOpen || sz.ok === false) {
|
||||
openBtn.textContent = coinMode
|
||||
? ((d && d.msg) || (sz && sz.msg) || "无法开仓")
|
||||
: "暂无卖一深度,无法开仓";
|
||||
} else if (coinMode) {
|
||||
openBtn.textContent =
|
||||
bud != null ? "买币并开仓(预算 ≈ " + Number(bud).toFixed(2) + " USDT)" : "买币并开仓 @ 卖一";
|
||||
@@ -1309,6 +1330,9 @@
|
||||
} else if (sz.ask_depth_capped) {
|
||||
msgEl.textContent = sz.msg || "已按卖一深度限制张数";
|
||||
msgEl.classList.remove("opt-error");
|
||||
} else if (coinMode && sz.est_note) {
|
||||
msgEl.textContent = sz.est_note;
|
||||
msgEl.classList.remove("opt-error");
|
||||
} else {
|
||||
msgEl.textContent = "";
|
||||
msgEl.classList.remove("opt-error");
|
||||
@@ -1504,8 +1528,20 @@
|
||||
return false;
|
||||
} finally {
|
||||
const latest = state.orderQuote;
|
||||
const coinMode = isCoinMarginMode() || (latest && latest.options_margin_mode === "coin");
|
||||
const bud = (latest && latest.coin_budget && latest.coin_budget.budget_usdt) ||
|
||||
(state.chain && state.chain.coin_budget && state.chain.coin_budget.budget_usdt);
|
||||
btn.disabled = !(latest && latest.ok && latest.can_open && !(latest.sizing && latest.sizing.ok === false));
|
||||
btn.textContent = (latest && latest.can_open) ? "限价买入 @ 卖一" : "暂无卖一深度,无法开仓";
|
||||
if (!(latest && latest.can_open) || (latest && latest.sizing && latest.sizing.ok === false)) {
|
||||
btn.textContent = coinMode
|
||||
? ((latest && (latest.msg || (latest.sizing && latest.sizing.msg))) || "无法开仓")
|
||||
: "暂无卖一深度,无法开仓";
|
||||
} else if (coinMode) {
|
||||
btn.textContent =
|
||||
bud != null ? "买币并开仓(预算 ≈ " + Number(bud).toFixed(2) + " USDT)" : "买币并开仓 @ 卖一";
|
||||
} else {
|
||||
btn.textContent = "限价买入 @ 卖一";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user