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:
dekun
2026-07-17 17:09:53 +08:00
parent 82d16a73e8
commit fd1bf9982c
8 changed files with 150 additions and 4 deletions
+11 -1
View File
@@ -187,6 +187,8 @@ 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):
@@ -205,13 +207,21 @@ def settings_page_context(page: str, *, instance_base_dir: str | None = None, **
if p not in ("settings", "risk_policy", "env_config"):
return {}
display = kwargs.pop("display", None)
exchange_key = str(kwargs.get("exchange_key") or "")
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
exchange_key = str(kwargs.get("exchange_key") or "")
env_path = os.path.join(instance_base_dir, ".env")
example_path = os.path.join(instance_base_dir, ".env.example")
ctx["env_config_groups"] = build_env_ui_payload(exchange_key, example_path, env_path)