Show okx_sim/okx_live and gate live API fields by matching mode.

In sim, hide LIVE/API keys and expose simulated fund settings in env UI.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-14 18:35:08 +08:00
parent bd742a2e43
commit e7aa724a3b
9 changed files with 150 additions and 20 deletions
+45 -12
View File
@@ -386,28 +386,61 @@
}
function bindTradeModeAutoRefresh(body) {
const modeSel = body.querySelector('.env-field-input[data-env-key="OKX_TRADE_MODE"]');
if (!modeSel || modeSel.dataset.modeRefreshBound === "1") return;
modeSel.dataset.modeRefreshBound = "1";
bindEnvSelectAutoRefresh(
body,
"OKX_TRADE_MODE",
"切换交易模式并刷新配置…",
"交易模式已切换为当前选项,配置区已刷新",
"modeRefreshBound",
true
);
bindEnvSelectAutoRefresh(
body,
"SIM_DEFAULT_MODE",
"切换撮合模式并刷新配置…",
"撮合模式已切换,配置区已刷新(sim 隐藏 API / live 显示实盘项)",
"simModeRefreshBound",
false
);
}
function bindEnvSelectAutoRefresh(body, key, pendingMsg, okMsg, flag, jumpModeSection) {
const modeSel = body && body.querySelector('.env-field-input[data-env-key="' + key + '"]');
if (!modeSel || modeSel.dataset[flag] === "1") return;
modeSel.dataset[flag] = "1";
modeSel.addEventListener("change", async () => {
const status = document.getElementById("env-config-status");
const nextMode = modeSel.value;
setStatus(status, "切换交易模式并刷新配置…");
setStatus(status, pendingMsg);
try {
const payload = { values: {} };
payload.values[key] = nextMode;
await fetchJson("/api/settings/env", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ values: { OKX_TRADE_MODE: nextMode } }),
body: JSON.stringify(payload),
});
await loadEnvConfig(true);
const page = envConfigRoot() || document.querySelector(".env-config-page");
const newBody = page && page.querySelector("#env-config-body");
const idx = newBody && newBody.dataset.envModeSectionIdx;
if (idx != null) {
const radio = document.getElementById("env-sec-" + idx);
if (radio) radio.checked = true;
if (jumpModeSection) {
const page = envConfigRoot() || document.querySelector(".env-config-page");
const newBody = page && page.querySelector("#env-config-body");
const idx = newBody && newBody.dataset.envModeSectionIdx;
if (idx != null) {
const radio = document.getElementById("env-sec-" + idx);
if (radio) radio.checked = true;
}
}
setStatus(status, okMsg);
if (typeof global.refreshAccountSnapshot === "function") {
global.refreshAccountSnapshot({ force: true, silent: true });
}
// 顶栏交易所名:okx_sim / okx_live
const label = nextMode === "sim" ? "okx_sim" : nextMode === "live" ? "okx_live" : "";
if (label) {
document.querySelectorAll('[data-funds-field="exchange-mode-label"]').forEach((el) => {
el.textContent = label;
});
}
setStatus(status, "交易模式已切换为当前选项,配置区已刷新");
} catch (e) {
setStatus(status, e.message || "切换失败", true);
}