fix: keep exchange API only in env config, remove from system settings.
EOF Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -437,41 +437,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
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";
|
||||
@@ -501,16 +466,6 @@
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -528,8 +483,6 @@
|
||||
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() {
|
||||
|
||||
Vendored
-21
@@ -258,27 +258,6 @@ def ui_allowed_keys(exchange_key: str) -> frozenset[str]:
|
||||
return frozenset(keys)
|
||||
|
||||
|
||||
def build_exchange_api_group(
|
||||
exchange_key: str,
|
||||
example_path: str,
|
||||
env_path: str,
|
||||
) -> dict[str, Any]:
|
||||
"""系统设置「交易所 API」专用:仅交易所与实盘字段."""
|
||||
schema = _schema_field_map(example_path)
|
||||
values = env_get_all(read_env_lines(env_path))
|
||||
ex = (exchange_key or "").strip().lower()
|
||||
live_fields = _EXCHANGE_LIVE_FIELDS.get(ex, _EXCHANGE_LIVE_FIELDS["okx"])
|
||||
fields = [
|
||||
_build_field(key, label, note, schema, values)
|
||||
for key, label, note in live_fields
|
||||
]
|
||||
return {
|
||||
"title": "交易所 API",
|
||||
"fields": fields,
|
||||
"has_restart": any(f.get("restart_required") for f in fields),
|
||||
}
|
||||
|
||||
|
||||
def build_env_ui_payload(
|
||||
exchange_key: str,
|
||||
example_path: str,
|
||||
|
||||
@@ -21,7 +21,6 @@ DEFAULT_INSTANCE_DISPLAY: dict[str, bool] = {
|
||||
"show_settings_transfer": True,
|
||||
"show_settings_export": True,
|
||||
"show_settings_password": True,
|
||||
"show_settings_exchange_api": True,
|
||||
"show_settings_options_swap": True,
|
||||
"show_settings_options_transfer": True,
|
||||
}
|
||||
@@ -40,7 +39,6 @@ DISPLAY_LABELS: dict[str, str] = {
|
||||
"show_settings_transfer": "资金划转",
|
||||
"show_settings_export": "数据导出",
|
||||
"show_settings_password": "账户密码修改",
|
||||
"show_settings_exchange_api": "交易所 API",
|
||||
"show_settings_options_swap": "期权币种兑换",
|
||||
"show_settings_options_transfer": "期权资金划转",
|
||||
}
|
||||
@@ -120,7 +118,6 @@ def display_meta_for_ui() -> list[dict[str, Any]]:
|
||||
"show_nav_hedge_plan",
|
||||
]
|
||||
settings_keys = [
|
||||
"show_settings_exchange_api",
|
||||
"show_settings_transfer",
|
||||
"show_settings_export",
|
||||
"show_settings_password",
|
||||
|
||||
@@ -187,8 +187,6 @@ def build_settings_tabs(display: dict[str, Any] | None, instance_settings: dict[
|
||||
disp = display or {}
|
||||
inst = instance_settings or {}
|
||||
tabs: list[dict[str, str]] = [{"key": "nav", "title": "导航显示"}]
|
||||
if disp.get("show_settings_exchange_api", True):
|
||||
tabs.append({"key": "exchange_api", "title": "交易所 API"})
|
||||
if disp.get("show_settings_password", True):
|
||||
tabs.append({"key": "password", "title": "账户密码"})
|
||||
if inst.get("show_transfer") and disp.get("show_settings_transfer", True):
|
||||
@@ -211,14 +209,6 @@ def settings_page_context(page: str, *, instance_base_dir: str | None = None, **
|
||||
ctx: dict[str, Any] = {"instance_settings": build_instance_settings_view(**kwargs)}
|
||||
if p == "settings":
|
||||
ctx["settings_tabs"] = build_settings_tabs(display, ctx["instance_settings"])
|
||||
if instance_base_dir:
|
||||
from lib.env.env_ui_manifest import build_exchange_api_group
|
||||
|
||||
env_path = os.path.join(instance_base_dir, ".env")
|
||||
example_path = os.path.join(instance_base_dir, ".env.example")
|
||||
ctx["exchange_api_group"] = build_exchange_api_group(
|
||||
exchange_key, example_path, env_path
|
||||
)
|
||||
if p == "env_config" and instance_base_dir:
|
||||
from lib.env.env_ui_manifest import build_env_ui_payload
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ const ORDER_ENTRY_MODEL_CODE_TO_CATEGORY = {{ entry_model_code_to_category | toj
|
||||
<script>
|
||||
window.__INSTANCE_DISPLAY__ = {{ display | tojson }};
|
||||
</script>
|
||||
<script src="/static/instance_settings_prefs.js?v=17"></script>
|
||||
<script src="/static/instance_settings_prefs.js?v=18"></script>
|
||||
<script src="/static/instance_live.js?v=6"></script>
|
||||
<script src="/static/instance_embed.js?v=25"></script>
|
||||
</body>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<div class="env-config-head-row">
|
||||
<div>
|
||||
<h2>env 配置</h2>
|
||||
<p class="settings-env-hint env-config-head-hint">按分类修改,改完点保存.含「需重启」的项请用「保存并重启」.<strong>AI 配置</strong>请在中控 → 系统设置 → AI 配置统一维护.</p>
|
||||
<p class="settings-env-hint env-config-head-hint">按分类修改,改完点保存.含「需重启」的项请用「保存并重启」.交易所 API 在本页「交易所与实盘」.<strong>AI 配置</strong>请在中控 → 系统设置 → AI 配置统一维护.</p>
|
||||
</div>
|
||||
<div class="env-config-toolbar">
|
||||
<button type="button" class="btn-primary btn-sm" id="env-config-save">保存</button>
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
{# 系统设置 · 交易所 API(写入实例 .env,与 env 配置同源) #}
|
||||
<h2>交易所 API</h2>
|
||||
<p class="settings-subcard-desc">配置本所永续 API 与实盘开关,保存写入 <code>.env</code>.含「需重启」项请用「保存并重启」.</p>
|
||||
{% if exchange_api_group %}
|
||||
<div id="settings-exchange-api-panel" class="settings-exchange-api" data-exchange-api="1">
|
||||
{% if exchange_api_group.has_restart %}
|
||||
<p class="env-panel-hint">本组含需重启项,修改后请点「保存并重启」.</p>
|
||||
{% endif %}
|
||||
<div class="env-form-grid">
|
||||
{% for field in exchange_api_group.fields %}
|
||||
<div class="env-field-row{% if field.restart_required %} env-field-row--restart{% endif %}">
|
||||
<label class="env-field-label" for="set-api-{{ field.key }}">
|
||||
{{ field.label or field.key }}
|
||||
{% if field.restart_required %}<span class="env-restart-mark" title="需重启">*</span>{% endif %}
|
||||
</label>
|
||||
{% if field.note %}
|
||||
<div class="env-field-note muted">{{ field.note }}</div>
|
||||
{% endif %}
|
||||
{% if field.type == 'bool' %}
|
||||
<select class="env-field-input" id="set-api-{{ field.key }}" data-env-key="{{ field.key }}">
|
||||
{% set cur = (field.current or field.default or 'false')|lower %}
|
||||
<option value="true"{% if cur in ('true', '1', 'yes', 'on') %} selected{% endif %}>开启</option>
|
||||
<option value="false"{% if cur not in ('true', '1', 'yes', 'on') %} selected{% endif %}>关闭</option>
|
||||
</select>
|
||||
{% elif field.sensitive %}
|
||||
{% if field.has_value %}
|
||||
<div class="env-sensitive-current muted">已配置 <span class="env-masked-value">{{ field.masked }}</span></div>
|
||||
{% endif %}
|
||||
<input
|
||||
class="env-field-input"
|
||||
id="set-api-{{ field.key }}"
|
||||
type="password"
|
||||
data-env-key="{{ field.key }}"
|
||||
data-env-sensitive="1"
|
||||
data-env-dirty="0"
|
||||
data-lpignore="true"
|
||||
data-1p-ignore="true"
|
||||
data-form-type="other"
|
||||
autocomplete="new-password"
|
||||
placeholder="{% if field.has_value %}修改时填写新值,留空不修改{% else %}请输入{% endif %}"
|
||||
oninput="this.dataset.envDirty='1'"
|
||||
>
|
||||
{% else %}
|
||||
<input
|
||||
class="env-field-input"
|
||||
id="set-api-{{ field.key }}"
|
||||
type="text"
|
||||
data-env-key="{{ field.key }}"
|
||||
value="{{ field.current or field.default or '' }}"
|
||||
>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="settings-actions-row" style="margin-top:1rem;">
|
||||
<button type="button" class="btn-primary btn-sm" id="settings-exchange-api-save">保存</button>
|
||||
<button type="button" class="btn-secondary btn-sm" id="settings-exchange-api-save-restart">保存并重启</button>
|
||||
<span class="settings-status-line" id="settings-exchange-api-status"></span>
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<p class="muted">未能加载交易所 API 字段.</p>
|
||||
{% endif %}
|
||||
@@ -2020,6 +2020,6 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
});
|
||||
{% endif %}
|
||||
</script>
|
||||
<script src="/static/instance_settings_prefs.js?v=17"></script>
|
||||
<script src="/static/instance_settings_prefs.js?v=18"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -2,7 +2,7 @@
|
||||
<div class="settings-page full">
|
||||
<div class="env-config-head card">
|
||||
<h2>系统设置</h2>
|
||||
<p class="settings-env-hint env-config-head-hint">交易所 API、账户密码、划转与显示开关等在此维护.</p>
|
||||
<p class="settings-env-hint env-config-head-hint">账户密码、划转与显示开关等在此维护.交易所 API 请到 <strong>env配置</strong>.</p>
|
||||
</div>
|
||||
|
||||
{% if settings_tabs %}
|
||||
@@ -20,8 +20,6 @@
|
||||
<section class="env-panel env-panel--{{ loop.index0 }} settings-tab-panel" role="tabpanel">
|
||||
{% if tab.key == 'nav' %}
|
||||
{% include 'display_prefs_panel.html' %}
|
||||
{% elif tab.key == 'exchange_api' %}
|
||||
{% include 'exchange_api_settings_panel.html' %}
|
||||
{% elif tab.key == 'password' %}
|
||||
{% include 'password_settings_panel.html' %}
|
||||
{% elif tab.key == 'transfer' %}
|
||||
|
||||
Reference in New Issue
Block a user