Require real ask depth for options and hedge opens.
Block mark-as-ask opens, show reference mark when no depth, cap sheets to ask size; leave close paths unchanged. Document in docs/更新文档.md. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -701,7 +701,7 @@
|
||||
const targetLevEl = document.getElementById("opt-est-leverage");
|
||||
const targetEl = document.getElementById("opt-target-idx");
|
||||
const q = state.orderQuote;
|
||||
if (!q || !q.ok) {
|
||||
if (!q || !q.ok || !q.can_open) {
|
||||
if (levEl) levEl.textContent = "—";
|
||||
if (valueEl) valueEl.textContent = "—";
|
||||
if (profitEl) {
|
||||
@@ -905,14 +905,31 @@
|
||||
function fillOrderPanel(d) {
|
||||
state.orderQuote = d && d.ok ? d : null;
|
||||
const sz = d.sizing || {};
|
||||
const canOpen = !!(d && d.ok && d.can_open);
|
||||
document.getElementById("opt-order-inst").textContent = d.inst_id || state.selectedInst || "";
|
||||
document.getElementById("opt-order-ask").textContent = fmtPxSz(d.ask, d.ask_sz);
|
||||
const askEl = document.getElementById("opt-order-ask");
|
||||
if (askEl) {
|
||||
askEl.textContent = canOpen ? fmtPxSz(d.ask, d.ask_sz) : "—";
|
||||
}
|
||||
const bidEl = document.getElementById("opt-order-bid");
|
||||
if (bidEl) bidEl.textContent = fmtPxSz(d.bid, d.bid_sz);
|
||||
document.getElementById("opt-order-sheets").textContent = sz.sheets != null ? sz.sheets : "—";
|
||||
document.getElementById("opt-order-eth").textContent = sz.eth_amount != null ? sz.eth_amount : "—";
|
||||
const refEl = document.getElementById("opt-order-ref-ask");
|
||||
if (refEl) {
|
||||
if (canOpen) {
|
||||
refEl.textContent = "—";
|
||||
} else if (d.ref_ask != null && !Number.isNaN(Number(d.ref_ask))) {
|
||||
refEl.textContent = fmtPxSz(d.ref_ask, null, true) + " (不可开仓)";
|
||||
} else if (d.mark != null && !Number.isNaN(Number(d.mark))) {
|
||||
refEl.textContent = fmtPxSz(d.mark, null, true) + " (不可开仓)";
|
||||
} else {
|
||||
refEl.textContent = "—";
|
||||
}
|
||||
}
|
||||
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();
|
||||
document.getElementById("opt-order-premium").textContent = sz.total_premium != null ? fmtUsdc(sz.total_premium) + " USDC" : "—";
|
||||
document.getElementById("opt-order-premium").textContent =
|
||||
canOpen && sz.total_premium != null ? fmtUsdc(sz.total_premium) + " USDC" : "—";
|
||||
const beEl = document.getElementById("opt-order-expiry-be");
|
||||
const distEl = document.getElementById("opt-order-dist-be");
|
||||
if (beEl) {
|
||||
@@ -922,13 +939,31 @@
|
||||
distEl.textContent = fmtDist(d.dist_expiry_be);
|
||||
distEl.className = "v " + distBeClass(d.dist_expiry_be);
|
||||
}
|
||||
const openBtn = document.getElementById("opt-open-btn");
|
||||
if (openBtn) {
|
||||
openBtn.disabled = !canOpen || sz.ok === false;
|
||||
openBtn.textContent = canOpen ? "限价买入 @ 卖一" : "暂无卖一深度,无法开仓";
|
||||
}
|
||||
const msgEl = document.getElementById("opt-order-msg");
|
||||
if (!d.ok) {
|
||||
msgEl.textContent = d.msg || "报价失败";
|
||||
msgEl.classList.add("opt-error");
|
||||
} else if (!canOpen) {
|
||||
const ref = d.ref_ask != null ? d.ref_ask : d.mark;
|
||||
let tip = d.msg || d.open_block_msg || "当前无卖一深度,无法按卖一限价买入";
|
||||
if (ref != null && !Number.isNaN(Number(ref))) {
|
||||
tip += "。参考标记价 ~" + Number(ref).toFixed(4).replace(/\.?0+$/, "") + "(仅供参考,不可用于开仓)";
|
||||
} else {
|
||||
tip += "。无可用参考标记价";
|
||||
}
|
||||
msgEl.textContent = tip;
|
||||
msgEl.classList.add("opt-error");
|
||||
} else if (sz.ok === false) {
|
||||
msgEl.textContent = sz.msg || "";
|
||||
msgEl.classList.add("opt-error");
|
||||
} else if (sz.ask_depth_capped) {
|
||||
msgEl.textContent = sz.msg || "已按卖一深度限制张数";
|
||||
msgEl.classList.remove("opt-error");
|
||||
} else {
|
||||
msgEl.textContent = "";
|
||||
msgEl.classList.remove("opt-error");
|
||||
@@ -1051,6 +1086,15 @@
|
||||
alert("请先选择合约");
|
||||
return;
|
||||
}
|
||||
const q = state.orderQuote;
|
||||
if (!q || !q.ok || !q.can_open) {
|
||||
alert((q && (q.msg || q.open_block_msg)) || "暂无卖一深度,无法按卖一开仓");
|
||||
return;
|
||||
}
|
||||
if (q.sizing && q.sizing.ok === false) {
|
||||
alert(q.sizing.msg || "张数无效");
|
||||
return;
|
||||
}
|
||||
const btn = document.getElementById("opt-open-btn");
|
||||
btn.disabled = true;
|
||||
try {
|
||||
@@ -1091,7 +1135,9 @@
|
||||
alert(d.msg || "下单失败");
|
||||
}
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
const latest = state.orderQuote;
|
||||
btn.disabled = !(latest && latest.ok && latest.can_open && !(latest.sizing && latest.sizing.ok === false));
|
||||
btn.textContent = (latest && latest.can_open) ? "限价买入 @ 卖一" : "暂无卖一深度,无法开仓";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user