fix: 统计日历服务端内嵌 bootstrap,首屏显示盈亏与笔数

与月统计同源 initial_calendar 写入页面,API 失败时仍渲染;四所日历路由独立注册并传入 get_db_fn。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-30 09:13:58 +08:00
parent 4f784d09ac
commit 3b687d17eb
15 changed files with 195 additions and 53 deletions
+17 -3
View File
@@ -1883,6 +1883,12 @@ def compute_stats_bundle(conn, trading_day, now_dt=None):
dm, wm, mm = slice_metrics("all")
from trade_stats_calendar_lib import build_initial_stats_calendar
initial_calendar = build_initial_stats_calendar(
pnls, now_dt, _pnl_row_matches_segment, reset_hour=TRADING_DAY_RESET_HOUR
)
return {
"trading_day": trading_day,
"total_opens_all": total_opens_all,
@@ -1891,6 +1897,7 @@ def compute_stats_bundle(conn, trading_day, now_dt=None):
"month": mm,
"segments": segments,
"stats_reset_hour": TRADING_DAY_RESET_HOUR,
"initial_calendar": initial_calendar,
}
@@ -9533,7 +9540,7 @@ try:
_repo_root = Path(__file__).resolve().parent.parent
if str(_repo_root) not in sys.path:
sys.path.insert(0, str(_repo_root))
from hub_bridge import install_on_app, register_trade_stats_calendar_route
from hub_bridge import install_on_app
install_on_app(
app,
@@ -9554,15 +9561,22 @@ try:
render_main_page_fn=render_main_page,
login_required_fn=login_required,
)
except Exception as _hub_err:
print(f"[hub_bridge] gate_bot: {_hub_err}")
try:
from hub_bridge import register_trade_stats_calendar_route
register_trade_stats_calendar_route(
app,
login_required_fn=login_required,
load_pnls_fn=_load_completed_trade_pnls,
row_matches_segment_fn=_pnl_row_matches_segment,
reset_hour=TRADING_DAY_RESET_HOUR,
get_db_fn=get_db,
)
except Exception as _hub_err:
print(f"[hub_bridge] gate_bot: {_hub_err}")
except Exception as _cal_err:
print(f"[stats calendar] gate_bot: {_cal_err}")
@app.route("/strategy")