fix: always show OKX options nav tab and allow options page without redirect

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-07 08:33:23 +08:00
parent 806bb074ab
commit ae0c44e20d
5 changed files with 10 additions and 7 deletions
+1 -3
View File
@@ -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")
+1 -1
View File
@@ -36,7 +36,7 @@
{% endif %}
<a href="/records" data-embed-tab="records" class="{% if initial_tab == 'records' %}active{% endif %}">交易记录与复盘</a>
<a href="/stats" data-embed-tab="stats" class="{% if initial_tab == 'stats' %}active{% endif %}">统计分析</a>
{% if options_enabled %}
{% if options_nav_visible %}
<a href="/options" data-embed-tab="options" class="{% if initial_tab == 'options' %}active{% endif %}">期权</a>
{% endif %}
<a href="/settings" data-embed-tab="settings" class="{% if initial_tab == 'settings' %}active{% endif %}">系统设置</a>
+1 -1
View File
@@ -61,7 +61,7 @@
{% endif %}
<a href="/records" class="{% if page == 'records' %}active{% endif %}">交易记录与复盘</a>
<a href="/stats" class="{% if page == 'stats' %}active{% endif %}">统计分析</a>
{% if options_enabled %}
{% if options_nav_visible %}
<a href="/options" class="{% if page == 'options' %}active{% endif %}">期权</a>
{% endif %}
<a href="/settings" class="{% if page == 'settings' %}active{% endif %}">系统设置</a>
+4 -2
View File
@@ -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, ""
+3
View File
@@ -2,6 +2,9 @@
data-trade-budget="{{ options_trade_budget | default(10) }}"
data-default-underly="{{ options_default_underly | default('ETH') }}">
<h2>期权(USDⓈ 本位 · 仅买方)</h2>
{% if not options_enabled %}
<div class="flash" style="margin-bottom:12px">期权 API 未启用:请在 <code>crypto_monitor_okx/.env</code> 设置 <code>OKX_OPTIONS_ENABLED=true</code> 及主账户 <code>OKX_OPTIONS_API_*</code>,然后 <code>pm2 restart crypto_okx --update-env</code></div>
{% endif %}
<p class="muted options-hint">资金账户兑换 USDT→USDC 后,划转到交易账户即可买入。报价单位为每 1 ETH/BTC1 张 = 0.01 ETH/BTC。</p>
<div class="options-funds-grid">