Show okx_sim/okx_live and gate live API fields by matching mode.

In sim, hide LIVE/API keys and expose simulated fund settings in env UI.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-14 18:35:08 +08:00
parent bd742a2e43
commit e7aa724a3b
9 changed files with 150 additions and 20 deletions
+16 -1
View File
@@ -5046,11 +5046,18 @@ def render_main_page(page="options", embed_mode=None):
options_funding_usdt = None
options_trading_usdt = None
_sim_mode_for_header = False
_exchange_display_for_header = EXCHANGE_DISPLAY_NAME
try:
from lib.sim.mode_lib import exchange_mode_label as _exchange_mode_label
from lib.sim.mode_lib import is_sim_mode as _is_sim_mode_fn
_sim_mode_for_header = bool(_is_sim_mode_fn(get_db))
_exchange_display_for_header = _exchange_mode_label(
is_sim=_sim_mode_for_header, exchange_key="okx"
)
except Exception:
_sim_mode_for_header = False
_exchange_display_for_header = EXCHANGE_DISPLAY_NAME
if (
OKX_OPTIONS_ENABLED
and embed_mode != "fragment"
@@ -5258,7 +5265,7 @@ def render_main_page(page="options", embed_mode=None):
key_rule_ctx=key_rule_ctx,
funds_fmt=format_funds_u,
options_funding_label=options_funding_label,
exchange_display=EXCHANGE_DISPLAY_NAME,
exchange_display=_exchange_display_for_header,
options_enabled=OKX_OPTIONS_ENABLED,
trading_mode=("sim" if _sim_mode_for_header else "live"),
is_sim_mode=_sim_mode_for_header,
@@ -5532,10 +5539,18 @@ def api_account_snapshot():
except Exception:
options_unrealized_pnl = None
_show_perp_funds = show_perp_funds_enabled(exchange_key="okx")
try:
from lib.sim.mode_lib import exchange_mode_label as _ex_mode_label
from lib.sim.mode_lib import is_sim_mode as _is_sim
_snapshot_mode_label = _ex_mode_label(is_sim=_is_sim(get_db), exchange_key="okx")
except Exception:
_snapshot_mode_label = EXCHANGE_DISPLAY_NAME
return jsonify({
"funding_usdt": funding_usdt,
"current_capital": current_capital,
"show_perp_funds": _show_perp_funds,
"exchange_mode_label": _snapshot_mode_label,
"options_funding_usdc": options_funding_usdc,
"options_funding_usdt": options_funding_usdt,
"options_trading_usdc": options_trading_usdc,