perf: embed shell soft nav, tab cache, and lighter options page boot

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-07 10:42:01 +08:00
parent 8913138dc3
commit 30e40dc34c
6 changed files with 150 additions and 31 deletions
+47 -18
View File
@@ -290,7 +290,7 @@ def resolve_path(path_value):
app = Flask(__name__)
app.secret_key = os.getenv("FLASK_SECRET_KEY", "crypto_monitor_2026_secret_key")
from lib.instance.instance_embed_lib import attach_embed_templates
from lib.instance.instance_embed_lib import attach_embed_templates, redirect_to_embed_shell_if_enabled
attach_embed_templates(app, _REPO_ROOT)
@@ -6510,7 +6510,11 @@ def render_main_page(page="trade", embed_mode=None):
options_trading_usdc = None
options_funding_usdc = None
options_funding_usdt = None
if OKX_OPTIONS_ENABLED and exchange_options.apiKey:
if (
OKX_OPTIONS_ENABLED
and exchange_options.apiKey
and embed_mode != "fragment"
):
try:
from lib.exchange.okx_options_lib import (
fetch_options_funding_usdc,
@@ -6601,22 +6605,29 @@ def render_main_page(page="trade", embed_mode=None):
hard_limit=DAILY_OPEN_HARD_LIMIT,
extra_blocks=not risk_status.get("can_trade", True),
)
key_rule_ctx = key_monitor_rule_template_context(
kline_timeframe=KLINE_TIMEFRAME,
key_breakout_amp_min_pct=KEY_BREAKOUT_AMP_MIN_PCT,
key_volume_ma_bars=KEY_VOLUME_MA_BARS,
key_volume_ratio_min=KEY_VOLUME_RATIO_MIN,
key_auto_min_planned_rr=KEY_AUTO_MIN_PLANNED_RR,
key_daily_volume_rank_max=KEY_DAILY_VOLUME_RANK_MAX,
key_confirm_breakout_bar=KEY_CONFIRM_BREAKOUT_BAR,
key_confirm_bar=KEY_CONFIRM_BAR,
key_alert_max_times=KEY_ALERT_MAX_TIMES,
key_alert_interval_minutes=KEY_ALERT_INTERVAL_MINUTES,
key_stop_outside_breakout_pct=KEY_STOP_OUTSIDE_BREAKOUT_PCT,
key_trend_stop_outside_pct=KEY_TREND_STOP_OUTSIDE_PCT,
false_breakout_validity_hours=FALSE_BREAKOUT_VALIDITY_HOURS,
trigger_entry_validity_hours=TRIGGER_ENTRY_VALIDITY_HOURS,
)
key_rule_ctx = {}
if page in ("key_monitor", "trade") or page in (
"strategy",
"strategy_trend",
"strategy_roll",
"strategy_records",
):
key_rule_ctx = key_monitor_rule_template_context(
kline_timeframe=KLINE_TIMEFRAME,
key_breakout_amp_min_pct=KEY_BREAKOUT_AMP_MIN_PCT,
key_volume_ma_bars=KEY_VOLUME_MA_BARS,
key_volume_ratio_min=KEY_VOLUME_RATIO_MIN,
key_auto_min_planned_rr=KEY_AUTO_MIN_PLANNED_RR,
key_daily_volume_rank_max=KEY_DAILY_VOLUME_RANK_MAX,
key_confirm_breakout_bar=KEY_CONFIRM_BREAKOUT_BAR,
key_confirm_bar=KEY_CONFIRM_BAR,
key_alert_max_times=KEY_ALERT_MAX_TIMES,
key_alert_interval_minutes=KEY_ALERT_INTERVAL_MINUTES,
key_stop_outside_breakout_pct=KEY_STOP_OUTSIDE_BREAKOUT_PCT,
key_trend_stop_outside_pct=KEY_TREND_STOP_OUTSIDE_PCT,
false_breakout_validity_hours=FALSE_BREAKOUT_VALIDITY_HOURS,
trigger_entry_validity_hours=TRIGGER_ENTRY_VALIDITY_HOURS,
)
strategy_extra = {}
if plan.strategy:
from lib.strategy.strategy_ui import strategy_render_extras
@@ -6768,36 +6779,54 @@ def index():
@app.route("/key_monitor")
@login_required
def key_monitor_page():
redir = redirect_to_embed_shell_if_enabled("key_monitor")
if redir is not None:
return redir
return render_main_page("key_monitor")
@app.route("/trade")
@login_required
def trade_page():
redir = redirect_to_embed_shell_if_enabled("trade")
if redir is not None:
return redir
return render_main_page("trade")
@app.route("/records")
@login_required
def records_page():
redir = redirect_to_embed_shell_if_enabled("records")
if redir is not None:
return redir
return render_main_page("records")
@app.route("/stats")
@login_required
def stats_page():
redir = redirect_to_embed_shell_if_enabled("stats")
if redir is not None:
return redir
return render_main_page("stats")
@app.route("/settings")
@login_required
def settings_page():
redir = redirect_to_embed_shell_if_enabled("settings")
if redir is not None:
return redir
return render_main_page("settings")
@app.route("/options")
@login_required
def options_main_page():
redir = redirect_to_embed_shell_if_enabled("options")
if redir is not None:
return redir
return render_main_page("options")