From ae0c44e20ddb562a2a9d09cbcba258df788e7852 Mon Sep 17 00:00:00 2001 From: dekun Date: Tue, 7 Jul 2026 08:33:23 +0800 Subject: [PATCH] fix: always show OKX options nav tab and allow options page without redirect Co-authored-by: Cursor --- crypto_monitor_okx/app.py | 4 +--- lib/instance/templates/embed_shell.html | 2 +- lib/instance/templates/index.html | 2 +- lib/options/options_register.py | 6 ++++-- lib/options/templates/options_panel.html | 3 +++ 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/crypto_monitor_okx/app.py b/crypto_monitor_okx/app.py index 54f551c..8222161 100644 --- a/crypto_monitor_okx/app.py +++ b/crypto_monitor_okx/app.py @@ -6683,6 +6683,7 @@ def render_main_page(page="trade", embed_mode=None): funds_fmt=format_funds_u, exchange_display=EXCHANGE_DISPLAY_NAME, options_enabled=OKX_OPTIONS_ENABLED, + options_nav_visible=True, options_trade_budget=OKX_OPTIONS_TRADE_BUDGET_USDC, options_default_underly=OKX_OPTIONS_DEFAULT_UNDERLY, risk_status=risk_status, @@ -6767,9 +6768,6 @@ def settings_page(): @app.route("/options") @login_required def options_main_page(): - if not OKX_OPTIONS_ENABLED: - flash("期权模块未启用,请在 .env 设置 OKX_OPTIONS_ENABLED=true") - return redirect(url_for("trade_page")) return render_main_page("options") diff --git a/lib/instance/templates/embed_shell.html b/lib/instance/templates/embed_shell.html index 575d2ca..4ba7300 100644 --- a/lib/instance/templates/embed_shell.html +++ b/lib/instance/templates/embed_shell.html @@ -36,7 +36,7 @@ {% endif %} 交易记录与复盘 统计分析 - {% if options_enabled %} + {% if options_nav_visible %} 期权 {% endif %} 系统设置 diff --git a/lib/instance/templates/index.html b/lib/instance/templates/index.html index 080fb20..e1b3086 100644 --- a/lib/instance/templates/index.html +++ b/lib/instance/templates/index.html @@ -61,7 +61,7 @@ {% endif %} 交易记录与复盘 统计分析 - {% if options_enabled %} + {% if options_nav_visible %} 期权 {% endif %} 系统设置 diff --git a/lib/options/options_register.py b/lib/options/options_register.py index 82e6690..60ceca7 100644 --- a/lib/options/options_register.py +++ b/lib/options/options_register.py @@ -52,8 +52,8 @@ def install_options_trading(app: Flask, repo_root: str, app_module: Any) -> None attach_options_templates(app, repo_root) cfg = _build_cfg(app_module) app.extensions["options_cfg"] = cfg + register_options_routes(app, cfg) if enabled: - register_options_routes(app, cfg) _start_monitor_thread(app, cfg) @@ -102,10 +102,12 @@ def _build_cfg(app_module: Any) -> dict[str, Any]: def _require_options_ex(cfg: dict[str, Any]): + if not cfg.get("enabled"): + return None, "期权模块未启用,请在 .env 设置 OKX_OPTIONS_ENABLED=true 并重启 PM2" ex = cfg.get("exchange_options") ok, reason = cfg["options_api_ready"](ex) if not ok: - return None, reason + return None, reason or "期权 API 未配置" return ex, "" diff --git a/lib/options/templates/options_panel.html b/lib/options/templates/options_panel.html index bbd0ad4..3ed3dc6 100644 --- a/lib/options/templates/options_panel.html +++ b/lib/options/templates/options_panel.html @@ -2,6 +2,9 @@ data-trade-budget="{{ options_trade_budget | default(10) }}" data-default-underly="{{ options_default_underly | default('ETH') }}">

期权(USDⓈ 本位 · 仅买方)

+ {% if not options_enabled %} +
期权 API 未启用:请在 crypto_monitor_okx/.env 设置 OKX_OPTIONS_ENABLED=true 及主账户 OKX_OPTIONS_API_*,然后 pm2 restart crypto_okx --update-env
+ {% endif %}

资金账户兑换 USDT→USDC 后,划转到交易账户即可买入。报价单位为每 1 ETH/BTC;1 张 = 0.01 ETH/BTC。