settings: add Exchange API tab for instance system settings.
Allow configuring perpetual API keys and live trading from Settings, reusing the existing env save API. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -416,6 +416,41 @@
|
||||
}
|
||||
}
|
||||
|
||||
function collectSettingsExchangeApiValues() {
|
||||
const panel = document.getElementById("settings-exchange-api-panel");
|
||||
const values = {};
|
||||
if (!panel) return values;
|
||||
panel.querySelectorAll(".env-field-input[data-env-key]").forEach((el) => {
|
||||
if (el.dataset.envSensitive === "1" && el.dataset.envDirty !== "1") {
|
||||
return;
|
||||
}
|
||||
values[el.dataset.envKey] = el.value;
|
||||
});
|
||||
return values;
|
||||
}
|
||||
|
||||
async function saveSettingsExchangeApi(restartAfter) {
|
||||
const status = document.getElementById("settings-exchange-api-status");
|
||||
setStatus(status, "保存中…");
|
||||
try {
|
||||
const data = await fetchJson("/api/settings/env", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ values: collectSettingsExchangeApiValues() }),
|
||||
});
|
||||
const needRestart = restartAfter || data.restart_required;
|
||||
if (needRestart) {
|
||||
setStatus(status, "已保存,正在重启实例…");
|
||||
await restartInstance();
|
||||
setStatus(status, "保存并重启完成,请刷新页面");
|
||||
} else {
|
||||
setStatus(status, "已保存(即时生效项已应用)");
|
||||
}
|
||||
} catch (e) {
|
||||
setStatus(status, e.message || "保存失败", true);
|
||||
}
|
||||
}
|
||||
|
||||
function installDelegatedHandlers() {
|
||||
if (document.documentElement.dataset.prefsDelegateBound === "1") return;
|
||||
document.documentElement.dataset.prefsDelegateBound = "1";
|
||||
@@ -445,6 +480,16 @@
|
||||
if (target.closest("#pwd-save-btn")) {
|
||||
ev.preventDefault();
|
||||
void savePassword();
|
||||
return;
|
||||
}
|
||||
if (target.closest("#settings-exchange-api-save")) {
|
||||
ev.preventDefault();
|
||||
void saveSettingsExchangeApi(false);
|
||||
return;
|
||||
}
|
||||
if (target.closest("#settings-exchange-api-save-restart")) {
|
||||
ev.preventDefault();
|
||||
void saveSettingsExchangeApi(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -462,6 +507,8 @@
|
||||
bindClickOnce("env-config-save-restart", () => saveEnvConfig(true));
|
||||
bindClickOnce("env-config-reload", () => loadEnvConfig(true));
|
||||
bindClickOnce("pwd-save-btn", savePassword);
|
||||
bindClickOnce("settings-exchange-api-save", () => saveSettingsExchangeApi(false));
|
||||
bindClickOnce("settings-exchange-api-save-restart", () => saveSettingsExchangeApi(true));
|
||||
}
|
||||
|
||||
function initPage() {
|
||||
|
||||
Reference in New Issue
Block a user