Allow entering sheet counts for each options-options hedge leg.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -494,26 +494,64 @@
|
||||
}
|
||||
|
||||
function renderOoLegs() {
|
||||
const el = $("hp-oo-legs");
|
||||
if (!el) return;
|
||||
function one(tag, c) {
|
||||
if (!c) return tag + ": —";
|
||||
return (
|
||||
function fill(tag, c, infoId, sheetsId) {
|
||||
const info = $(infoId);
|
||||
const sheets = $(sheetsId);
|
||||
if (!info) return;
|
||||
if (!c) {
|
||||
info.textContent = tag + ": 尚未选用";
|
||||
if (sheets) {
|
||||
sheets.disabled = true;
|
||||
sheets.value = "1";
|
||||
}
|
||||
return;
|
||||
}
|
||||
info.innerHTML =
|
||||
tag +
|
||||
": " +
|
||||
": <strong>" +
|
||||
c.opt_type +
|
||||
" K" +
|
||||
c.strike +
|
||||
" " +
|
||||
"</strong> " +
|
||||
(c.moneyness_label || "") +
|
||||
" ask=" +
|
||||
" · 卖一 " +
|
||||
fmtPxSz(c.ask, c.ask_sz, c.ask_estimated, c.tick_sz) +
|
||||
" (" +
|
||||
" <code>" +
|
||||
c.inst_id +
|
||||
")"
|
||||
);
|
||||
"</code>";
|
||||
if (sheets) sheets.disabled = false;
|
||||
}
|
||||
el.innerHTML = one("腿A", state.legA) + "<br/>" + one("腿B", state.legB);
|
||||
fill("腿A", state.legA, "hp-oo-leg-a-info", "hp-oo-sheets-a");
|
||||
fill("腿B", state.legB, "hp-oo-leg-b-info", "hp-oo-sheets-b");
|
||||
updateOoPremiumLine();
|
||||
}
|
||||
|
||||
function ooSheets(id) {
|
||||
const n = Number(($(id) && $(id).value) || 1);
|
||||
return n > 0 ? n : 1;
|
||||
}
|
||||
|
||||
function updateOoPremiumLine() {
|
||||
const line = $("hp-oo-prem-line");
|
||||
if (!line) return;
|
||||
if (!state.legA && !state.legB) {
|
||||
line.textContent = "";
|
||||
return;
|
||||
}
|
||||
function prem(c, sheets) {
|
||||
if (!c) return 0;
|
||||
return Number(c.ask || 0) * sheets * Number(c.ct_mult || 0.01);
|
||||
}
|
||||
const a = prem(state.legA, ooSheets("hp-oo-sheets-a"));
|
||||
const b = prem(state.legB, ooSheets("hp-oo-sheets-b"));
|
||||
line.textContent =
|
||||
"预估权利金 A " +
|
||||
fmt(a, 4) +
|
||||
" + B " +
|
||||
fmt(b, 4) +
|
||||
" ≈ " +
|
||||
fmt(a + b, 4) +
|
||||
" USDC";
|
||||
}
|
||||
|
||||
function legPayload(c, sheets) {
|
||||
@@ -543,7 +581,15 @@
|
||||
if ($("hp-target")) $("hp-target").value = "";
|
||||
if ($("hp-sel-inst")) $("hp-sel-inst").textContent = "—";
|
||||
if ($("hp-premium-line")) $("hp-premium-line").textContent = "";
|
||||
if ($("hp-oo-legs")) $("hp-oo-legs").textContent = "尚未选用两腿";
|
||||
if ($("hp-oo-sheets-a")) {
|
||||
$("hp-oo-sheets-a").value = "1";
|
||||
$("hp-oo-sheets-a").disabled = true;
|
||||
}
|
||||
if ($("hp-oo-sheets-b")) {
|
||||
$("hp-oo-sheets-b").value = "1";
|
||||
$("hp-oo-sheets-b").disabled = true;
|
||||
}
|
||||
renderOoLegs();
|
||||
void refreshAll();
|
||||
}
|
||||
|
||||
@@ -561,8 +607,8 @@
|
||||
plan_type: "options_options",
|
||||
target_price: target,
|
||||
index_px: (state.chain && state.chain.index_px) || target,
|
||||
leg_a: legPayload(state.legA, 1),
|
||||
leg_b: legPayload(state.legB, 1),
|
||||
leg_a: legPayload(state.legA, ooSheets("hp-oo-sheets-a")),
|
||||
leg_b: legPayload(state.legB, ooSheets("hp-oo-sheets-b")),
|
||||
};
|
||||
} else {
|
||||
if (!state.selected) throw new Error("请选用期权腿");
|
||||
@@ -708,6 +754,10 @@
|
||||
if ($("hp-exp-select")) $("hp-exp-select").addEventListener("change", renderListStrikes);
|
||||
if ($("hp-oo-exp-select")) $("hp-oo-exp-select").addEventListener("change", renderTStrikes);
|
||||
if ($("hp-sheets")) $("hp-sheets").addEventListener("input", updatePremiumLine);
|
||||
["hp-oo-sheets-a", "hp-oo-sheets-b"].forEach(function (id) {
|
||||
const el = $(id);
|
||||
if (el) el.addEventListener("input", updateOoPremiumLine);
|
||||
});
|
||||
if ($("hp-preview-btn"))
|
||||
$("hp-preview-btn").addEventListener("click", function () {
|
||||
state.mode = "perp_options";
|
||||
|
||||
@@ -3234,6 +3234,26 @@ html[data-theme="light"] .opt-be-dist-down {
|
||||
.hedge-plan-page-wrap .hp-pnl-neg {
|
||||
color: #ff8a8a;
|
||||
}
|
||||
.hedge-plan-page-wrap .hp-oo-legs {
|
||||
margin-top: 8px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.hedge-plan-page-wrap .hp-oo-leg-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
padding: 8px 10px;
|
||||
border-radius: 8px;
|
||||
background: rgba(255, 255, 255, 0.03);
|
||||
border: 1px solid rgba(255, 255, 255, 0.06);
|
||||
}
|
||||
.hedge-plan-page-wrap .hp-oo-leg-row input[type="number"] {
|
||||
width: 72px;
|
||||
}
|
||||
.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