diff --git a/lib/common/static/instance_settings_prefs.js b/lib/common/static/instance_settings_prefs.js index 7aabd12..ee87c25 100644 --- a/lib/common/static/instance_settings_prefs.js +++ b/lib/common/static/instance_settings_prefs.js @@ -351,6 +351,7 @@ body.dataset.envModeSectionIdx = String(modeSectionIdx); bindTradeModeAutoRefresh(body); bindCompoundBudgetVisibility(body); + bindMarginModeGateVisibility(body); return body; } @@ -362,6 +363,12 @@ return input ? input.closest(".env-field-row") : null; } + function setEnvRowHidden(row, hidden) { + if (!row) return; + row.hidden = !!hidden; + row.style.display = hidden ? "none" : ""; + } + function syncCompoundBudgetVisibility(body) { if (!body) return; const compoundSel = body.querySelector( @@ -370,8 +377,18 @@ const budgetRow = envFieldRowByKey(body, "OKX_OPTIONS_TRADE_BUDGET_USDC"); if (!budgetRow) return; const compoundOn = !compoundSel || String(compoundSel.value || "").toLowerCase() === "true"; - budgetRow.hidden = compoundOn; - budgetRow.style.display = compoundOn ? "none" : ""; + setEnvRowHidden(budgetRow, compoundOn); + } + + function syncMarginModeGateVisibility(body) { + if (!body) return; + const modeSel = body.querySelector( + '.env-field-input[data-env-key="OKX_OPTIONS_MARGIN_MODE"]' + ); + const mode = String((modeSel && modeSel.value) || "coin").toLowerCase(); + const coinMode = mode !== "usdc"; + setEnvRowHidden(envFieldRowByKey(body, "OKX_OPTIONS_CLOSE_RECYCLE_MULT_USDC"), coinMode); + setEnvRowHidden(envFieldRowByKey(body, "OKX_OPTIONS_CLOSE_RECYCLE_MULT_COIN"), !coinMode); } function bindCompoundBudgetVisibility(body) { @@ -385,6 +402,17 @@ compoundSel.addEventListener("change", () => syncCompoundBudgetVisibility(body)); } + function bindMarginModeGateVisibility(body) { + if (!body) return; + syncMarginModeGateVisibility(body); + const modeSel = body.querySelector( + '.env-field-input[data-env-key="OKX_OPTIONS_MARGIN_MODE"]' + ); + if (!modeSel || modeSel.dataset.marginGateBound === "1") return; + modeSel.dataset.marginGateBound = "1"; + modeSel.addEventListener("change", () => syncMarginModeGateVisibility(body)); + } + function bindTradeModeAutoRefresh(body) { const modeSel = body.querySelector('.env-field-input[data-env-key="OKX_TRADE_MODE"]'); if (!modeSel || modeSel.dataset.modeRefreshBound === "1") return; diff --git a/lib/env/env_ui_manifest.py b/lib/env/env_ui_manifest.py index 2db854c..1501925 100644 --- a/lib/env/env_ui_manifest.py +++ b/lib/env/env_ui_manifest.py @@ -537,7 +537,7 @@ def build_env_ui_payload( _build_field(key, label, note, schema, values) for key, label, note in sec["fields"] ] - fields = _mark_compound_budget_hidden(fields) + fields = _mark_options_env_field_visibility(fields) groups.append({ "title": sec["title"], "fields": fields, @@ -546,26 +546,40 @@ def build_env_ui_payload( return groups -def _mark_compound_budget_hidden(fields: list[dict[str, Any]]) -> list[dict[str, Any]]: - """全仓复利开启时标记单笔预算为 hidden(供 SSR/前端隐藏;切换开关仍可再显示).""" +def _mark_options_env_field_visibility(fields: list[dict[str, Any]]) -> list[dict[str, Any]]: + """按本位/全仓复利隐藏无关项(供 SSR/前端;切换开关仍可再显示).""" compound_on = True + margin_mode = "coin" for f in fields: - if f.get("key") == "OKX_OPTIONS_COMPOUND_FULL_ENABLED": - compound_on = _env_truthy(str(f.get("current") or f.get("default") or "true")) - break - if not compound_on: - return fields + key = f.get("key") + cur = str(f.get("current") or f.get("default") or "").strip() + if key == "OKX_OPTIONS_COMPOUND_FULL_ENABLED": + compound_on = _env_truthy(cur or "true") + elif key == "OKX_OPTIONS_MARGIN_MODE": + margin_mode = (cur or "coin").lower() + if margin_mode not in ("coin", "usdc"): + margin_mode = "coin" out: list[dict[str, Any]] = [] for f in fields: - if f.get("key") == "OKX_OPTIONS_TRADE_BUDGET_USDC": - item = dict(f) + item = dict(f) + key = item.get("key") + hide = False + if key == "OKX_OPTIONS_TRADE_BUDGET_USDC" and compound_on: + hide = True + if key == "OKX_OPTIONS_CLOSE_RECYCLE_MULT_USDC" and margin_mode == "coin": + hide = True + if key == "OKX_OPTIONS_CLOSE_RECYCLE_MULT_COIN" and margin_mode == "usdc": + hide = True + if hide: item["hidden"] = True - out.append(item) - else: - out.append(f) + out.append(item) return out +def _mark_compound_budget_hidden(fields: list[dict[str, Any]]) -> list[dict[str, Any]]: + """兼容旧调用名;实际走 _mark_options_env_field_visibility.""" + return _mark_options_env_field_visibility(fields) + def filter_updates_for_ui(exchange_key: str, updates: dict[str, str]) -> dict[str, str]: allowed = ui_allowed_keys(exchange_key) return {k: v for k, v in (updates or {}).items() if k in allowed}