Add end-plan action; never show unfilled option legs as open.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-20 09:36:46 +08:00
parent 8597e47596
commit a43cb35d9a
6 changed files with 369 additions and 5 deletions
+49 -3
View File
@@ -1319,7 +1319,7 @@
role +
'">' +
label +
"</button>"
"</button> "
);
}
@@ -1339,6 +1339,42 @@
}
}
async function endActivePlan(planId) {
if (
!window.confirm(
"确认结束计划 #" +
planId +
"?\n不会自动平仓;未成交/待补腿将标为未成交取消。\n已有持仓请自行平掉。"
)
) {
return;
}
try {
const d = await apiJson("/api/hedge-plan/" + planId + "/end", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({}),
});
alert(d.msg || "计划已结束 #" + (d.plan_id || planId));
void loadActivePlans();
void loadHistory();
void loadGates();
} catch (e) {
alert(e.message || String(e));
}
}
function legStatusLabel(st) {
const map = {
open: "持仓中",
pending: "待补/未成交",
cancelled: "未成交取消",
canceled: "未成交取消",
closed: "已平仓",
};
return map[st] || st || "—";
}
async function loadActivePlans() {
const tbody = $("hp-active-tbody");
if (!tbody) return;
@@ -1375,7 +1411,10 @@
completeLegButtonHtml(p) +
'<button type="button" class="btn-secondary hp-btn-detail" data-id="' +
p.id +
'">成交细节</button></td>';
'">成交细节</button> ' +
'<button type="button" class="btn-secondary hp-btn-end" data-id="' +
p.id +
'">结束计划</button></td>';
tbody.appendChild(tr);
});
tbody.querySelectorAll(".hp-btn-detail").forEach(function (btn) {
@@ -1388,6 +1427,11 @@
void completeMissingLeg(Number(btn.getAttribute("data-id")));
});
});
tbody.querySelectorAll(".hp-btn-end").forEach(function (btn) {
btn.addEventListener("click", function () {
void endActivePlan(Number(btn.getAttribute("data-id")));
});
});
} catch (e) {
tbody.innerHTML = '<tr><td colspan="8" class="err">' + (e.message || e) + "</td></tr>";
}
@@ -1409,8 +1453,10 @@
hold_to_expiry: "持有至到期",
expiry: "到期",
manual: "人工结束",
manual_end: "人工结束",
partial_fail: "半腿失败",
cancelled: "已取消",
unfilled: "未成交",
};
return map[r] || r || "—";
}
@@ -1514,7 +1560,7 @@
html += "<td>" + fmt(leg.size, leg.leg_role === "perp" ? 4 : 0) + "</td>";
html += "<td>" + fmt(leg.avg_open, 4) + "</td>";
html += "<td>" + (leg.premium != null ? fmt(leg.premium, 4) : "—") + "</td>";
html += "<td>" + (leg.status || "—") + "</td>";
html += "<td>" + legStatusLabel(leg.status) + "</td>";
html += "<td>" + fmt(leg.realized_pnl, 4) + "</td>";
html += "<td><code class=\"hp-ord\">" + (leg.exchange_ord_id || "—") + "</code></td>";
html += "<td>" + reasonLabel(leg.close_reason) + "</td>";