Hide coin/USDC options env fields by margin mode.
Also toggle close-gate and compound subfields so the settings page only shows relevant controls. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Vendored
+65
-10
@@ -480,7 +480,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_section_hidden(fields)
|
||||
groups.append({
|
||||
"title": sec["title"],
|
||||
"fields": fields,
|
||||
@@ -489,18 +489,68 @@ def build_env_ui_payload(
|
||||
return groups
|
||||
|
||||
|
||||
def _mark_compound_budget_hidden(fields: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
||||
"""全仓复利开启时标记单笔预算为 hidden(供 SSR/前端隐藏;切换开关仍可再显示)."""
|
||||
compound_on = True
|
||||
# 币本位专属 / USDC 专属(配置页互斥隐藏)
|
||||
_COIN_ONLY_ENV_KEYS = frozenset({
|
||||
"OKX_OPTIONS_COIN_COMPOUND",
|
||||
"OKX_OPTIONS_COIN_BUDGET_USDT",
|
||||
"OKX_OPTIONS_COIN_MAX_USDT_ENABLED",
|
||||
"OKX_OPTIONS_COIN_MAX_USDT",
|
||||
"OKX_OPTIONS_COIN_SPOT_BUY_BUFFER",
|
||||
"OKX_OPTIONS_CLOSE_RECYCLE_MULT_COIN",
|
||||
})
|
||||
_USDC_ONLY_ENV_KEYS = frozenset({
|
||||
"OKX_OPTIONS_TRADE_BUDGET_USDC",
|
||||
"OKX_OPTIONS_COMPOUND_FULL_ENABLED",
|
||||
"OKX_OPTIONS_COMPOUND_FULL_CAP_ENABLED",
|
||||
"OKX_OPTIONS_COMPOUND_FULL_CAP_USDC",
|
||||
"OKX_OPTIONS_CLOSE_RECYCLE_MULT",
|
||||
})
|
||||
|
||||
|
||||
def _field_current(fields: list[dict[str, Any]], key: str, default: str = "") -> str:
|
||||
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
|
||||
if f.get("key") == key:
|
||||
return str(f.get("current") or f.get("default") or default).strip()
|
||||
return default
|
||||
|
||||
|
||||
def _mark_options_section_hidden(fields: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
||||
"""按本位/门控模式/全仓复利标记 hidden(供 SSR/前端;切换开关仍可再显示)."""
|
||||
margin = (_field_current(fields, "OKX_OPTIONS_MARGIN_MODE", "coin") or "coin").lower()
|
||||
is_coin = margin != "usdc"
|
||||
gate_mode = (_field_current(fields, "OKX_OPTIONS_CLOSE_GATE_MODE", "premium") or "premium").lower()
|
||||
compound_on = _env_truthy(_field_current(fields, "OKX_OPTIONS_COMPOUND_FULL_ENABLED", "true"))
|
||||
coin_compound_on = _env_truthy(_field_current(fields, "OKX_OPTIONS_COIN_COMPOUND", "true"))
|
||||
coin_max_on = _env_truthy(_field_current(fields, "OKX_OPTIONS_COIN_MAX_USDT_ENABLED", "false"))
|
||||
compound_cap_on = _env_truthy(
|
||||
_field_current(fields, "OKX_OPTIONS_COMPOUND_FULL_CAP_ENABLED", "false")
|
||||
)
|
||||
|
||||
out: list[dict[str, Any]] = []
|
||||
for f in fields:
|
||||
if f.get("key") == "OKX_OPTIONS_TRADE_BUDGET_USDC":
|
||||
key = str(f.get("key") or "")
|
||||
hide = False
|
||||
if is_coin and key in _USDC_ONLY_ENV_KEYS:
|
||||
hide = True
|
||||
elif (not is_coin) and key in _COIN_ONLY_ENV_KEYS:
|
||||
hide = True
|
||||
elif key == "OKX_OPTIONS_CLOSE_RECYCLE_MULT" and gate_mode != "premium":
|
||||
hide = True
|
||||
elif key == "OKX_OPTIONS_CLOSE_RECYCLE_MULT_COIN" and gate_mode != "premium":
|
||||
hide = True
|
||||
elif key == "OKX_OPTIONS_CLOSE_NET_PNL_MIN_USDT" and gate_mode != "net_pnl":
|
||||
hide = True
|
||||
elif key == "OKX_OPTIONS_TRADE_BUDGET_USDC" and compound_on:
|
||||
hide = True
|
||||
elif key == "OKX_OPTIONS_COMPOUND_FULL_CAP_ENABLED" and not compound_on:
|
||||
hide = True
|
||||
elif key == "OKX_OPTIONS_COMPOUND_FULL_CAP_USDC" and not (compound_on and compound_cap_on):
|
||||
hide = True
|
||||
elif key == "OKX_OPTIONS_COIN_BUDGET_USDT" and coin_compound_on:
|
||||
hide = True
|
||||
elif key == "OKX_OPTIONS_COIN_MAX_USDT" and not coin_max_on:
|
||||
hide = True
|
||||
if hide:
|
||||
item = dict(f)
|
||||
item["hidden"] = True
|
||||
out.append(item)
|
||||
@@ -509,6 +559,11 @@ def _mark_compound_budget_hidden(fields: list[dict[str, Any]]) -> list[dict[str,
|
||||
return out
|
||||
|
||||
|
||||
def _mark_compound_budget_hidden(fields: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
||||
"""兼容旧调用名."""
|
||||
return _mark_options_section_hidden(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}
|
||||
|
||||
Reference in New Issue
Block a user