feat: options UI scroll layout, stats card, funding balance, and cross-account transfer
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
optType: "C",
|
||||
chain: null,
|
||||
selectedInst: null,
|
||||
posTab: "live",
|
||||
};
|
||||
|
||||
function fmt(v, d) {
|
||||
@@ -289,7 +288,7 @@
|
||||
msgEl.textContent = d.ok ? "下单已提交,可在 OKX 委托中查看" : (d.msg || "失败");
|
||||
msgEl.classList.toggle("opt-error", !d.ok);
|
||||
if (d.ok) {
|
||||
refreshPositions();
|
||||
refreshAllPositions();
|
||||
if (typeof refreshAccountSnapshot === "function") refreshAccountSnapshot();
|
||||
} else {
|
||||
alert(d.msg || "下单失败");
|
||||
@@ -349,8 +348,7 @@
|
||||
} else {
|
||||
alert(r.msg || "平仓失败");
|
||||
}
|
||||
refreshPositions();
|
||||
refreshHistory();
|
||||
refreshAllPositions();
|
||||
if (typeof refreshAccountSnapshot === "function") refreshAccountSnapshot();
|
||||
} finally {
|
||||
if (btn) btn.disabled = false;
|
||||
@@ -380,6 +378,24 @@
|
||||
});
|
||||
}
|
||||
|
||||
async function refreshStats() {
|
||||
const d = await apiJson("/api/options/stats");
|
||||
const winEl = document.getElementById("opt-stats-winrate");
|
||||
const plrEl = document.getElementById("opt-stats-plr");
|
||||
const closedEl = document.getElementById("opt-stats-closed");
|
||||
if (!d.ok) {
|
||||
if (winEl) winEl.textContent = "—";
|
||||
if (plrEl) plrEl.textContent = "—";
|
||||
if (closedEl) closedEl.textContent = "—";
|
||||
return;
|
||||
}
|
||||
if (winEl) winEl.textContent = d.total_closed ? d.win_rate + "%" : "0%";
|
||||
if (plrEl) {
|
||||
plrEl.textContent = d.profit_loss_ratio != null ? String(d.profit_loss_ratio) : "—";
|
||||
}
|
||||
if (closedEl) closedEl.textContent = String(d.total_closed || 0);
|
||||
}
|
||||
|
||||
async function refreshHistory() {
|
||||
const d = await apiJson("/api/options/history");
|
||||
const tbody = document.getElementById("opt-history-tbody");
|
||||
@@ -405,14 +421,10 @@
|
||||
});
|
||||
}
|
||||
|
||||
function switchPosTab(tab) {
|
||||
state.posTab = tab;
|
||||
document.querySelectorAll(".opt-pos-tab").forEach(function (b) {
|
||||
b.classList.toggle("active", b.getAttribute("data-tab") === tab);
|
||||
});
|
||||
document.getElementById("opt-pos-live").hidden = tab !== "live";
|
||||
document.getElementById("opt-pos-history").hidden = tab !== "history";
|
||||
if (tab === "history") refreshHistory();
|
||||
function refreshAllPositions() {
|
||||
refreshPositions();
|
||||
refreshStats();
|
||||
refreshHistory();
|
||||
}
|
||||
|
||||
document.querySelectorAll(".opt-uly-btn").forEach(function (btn) {
|
||||
@@ -433,18 +445,9 @@
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelectorAll(".opt-pos-tab").forEach(function (btn) {
|
||||
btn.addEventListener("click", function () {
|
||||
switchPosTab(btn.getAttribute("data-tab"));
|
||||
});
|
||||
});
|
||||
|
||||
document.getElementById("opt-exp-select").addEventListener("change", renderStrikes);
|
||||
document.getElementById("opt-load-chain").addEventListener("click", loadChain);
|
||||
document.getElementById("opt-refresh-positions").addEventListener("click", function () {
|
||||
refreshPositions();
|
||||
if (state.posTab === "history") refreshHistory();
|
||||
});
|
||||
document.getElementById("opt-refresh-positions").addEventListener("click", refreshAllPositions);
|
||||
document.getElementById("opt-open-btn").addEventListener("click", openPosition);
|
||||
|
||||
document.querySelectorAll('input[name="opt-size-mode"]').forEach(function (r) {
|
||||
@@ -464,5 +467,5 @@
|
||||
|
||||
updateSizeInputs();
|
||||
loadChain();
|
||||
refreshPositions();
|
||||
refreshAllPositions();
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user