币本位 env 隐藏门控 USDC 倍数项,USDC 模式隐藏币本位倍数

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-25 09:29:46 +08:00
parent e38039d99a
commit 081afeba76
2 changed files with 57 additions and 15 deletions
+27 -13
View File
@@ -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}