Merge OKX dual APIs into one OKX_API_* account for perp and options.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-05 21:28:33 +08:00
parent 22e6b68e6d
commit 09a763e47d
26 changed files with 166 additions and 473 deletions
+1 -1
View File
@@ -284,7 +284,7 @@
setSettingsSubTabInUrl("transfer");
return "transfer";
}
if (path.indexOf("/api/options/transfer") >= 0 || path.indexOf("/api/options/cross-transfer") >= 0) {
if (path.indexOf("/api/options/transfer") >= 0) {
setSettingsSubTabInUrl("options_transfer");
return "options_transfer";
}
+2 -78
View File
@@ -6,7 +6,6 @@
const SWAP_BTNS = ["opt-set-swap-btn", "opt-set-swap-all-btn"];
const INT_BTNS = ["opt-set-int-btn", "opt-set-int-all-btn"];
const CROSS_BTNS = ["opt-set-cross-btn", "opt-set-cross-all-btn"];
async function apiJson(url, opts) {
const r = await fetch(url, Object.assign({ credentials: "same-origin" }, opts || {}));
@@ -269,80 +268,6 @@
});
}
async function submitCrossTransfer(amount) {
setButtonsBusy(CROSS_BTNS, true, "划转中…");
setMsg("opt-set-cross-msg", "划转中…", false);
try {
const d = await apiJson("/api/options/cross-transfer", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
ccy: document.getElementById("opt-set-cross-ccy").value,
amount: amount,
from_account: document.getElementById("opt-set-cross-from").value,
to_account: document.getElementById("opt-set-cross-to").value,
direction: document.getElementById("opt-set-cross-dir").value,
}),
});
if (d.ok) {
setMsg("opt-set-cross-msg", "划转成功", false);
refreshFundsAfterMutation();
} else {
setMsg("opt-set-cross-msg", "划转失败:" + (d.msg || "未知错误"), true);
}
return d;
} catch (e) {
setMsg("opt-set-cross-msg", "划转失败:" + (e.message || "网络错误"), true);
return { ok: false };
} finally {
setButtonsBusy(CROSS_BTNS, false);
}
}
const crossBtn = document.getElementById("opt-set-cross-btn");
if (crossBtn) {
crossBtn.addEventListener("click", async function () {
const amount = parseFloat(document.getElementById("opt-set-cross-amount").value);
if (!amount || amount <= 0) {
setMsg("opt-set-cross-msg", "请输入有效数量", true);
return;
}
await submitCrossTransfer(amount);
});
}
const crossAllBtn = document.getElementById("opt-set-cross-all-btn");
if (crossAllBtn) {
crossAllBtn.addEventListener("click", async function () {
try {
const ccy = document.getElementById("opt-set-cross-ccy").value;
const from = document.getElementById("opt-set-cross-from").value;
const to = document.getElementById("opt-set-cross-to").value;
const direction = document.getElementById("opt-set-cross-dir").value;
const scope = direction === "sub_to_main" ? "sub" : "main";
const sideLabel = direction === "sub_to_main" ? "子账户" : "主账户";
const amount = await resolveMaxAmount(from, ccy, scope);
if (!amount) {
setMsg("opt-set-cross-msg", sideLabel + "划出账户可用余额不足", true);
return;
}
const msg =
"确认全部划转?\n\n" +
"方向:" + (direction === "main_to_sub" ? "主 → 子" : "子 → 主") + "\n" +
"币种:" + ccy + "\n" +
"划出:" + sideLabel + " · " + accountLabel(from) + "\n" +
"划入:" + (direction === "main_to_sub" ? "子账户" : "主账户") + " · " + accountLabel(to) + "\n" +
"金额:" + fmtAmt(amount, ccy) + "\n\n" +
"将划转该账户全部可用余额。";
if (!confirmOk(msg)) return;
document.getElementById("opt-set-cross-amount").value = String(amount);
await submitCrossTransfer(amount);
} catch (e) {
setMsg("opt-set-cross-msg", "划转失败:" + (e.message || "余额拉取失败"), true);
}
});
}
function hardenAmountAutofill(ids) {
ids.forEach(function (id) {
const el = document.getElementById(id);
@@ -366,7 +291,7 @@
}
// 全部划转/兑换前去掉 readonly,避免写不进数量
["opt-set-swap-all-btn", "opt-set-int-all-btn", "opt-set-cross-all-btn"].forEach(function (btnId) {
["opt-set-swap-all-btn", "opt-set-int-all-btn"].forEach(function (btnId) {
const btn = document.getElementById(btnId);
if (!btn) return;
btn.addEventListener(
@@ -375,7 +300,6 @@
const map = {
"opt-set-swap-all-btn": "opt-set-swap-amount",
"opt-set-int-all-btn": "opt-set-int-amount",
"opt-set-cross-all-btn": "opt-set-cross-amount",
};
const input = document.getElementById(map[btnId]);
if (input) input.removeAttribute("readonly");
@@ -384,5 +308,5 @@
);
});
hardenAmountAutofill(["opt-set-swap-amount", "opt-set-int-amount", "opt-set-cross-amount"]);
hardenAmountAutofill(["opt-set-swap-amount", "opt-set-int-amount"]);
})();