diff --git a/crypto_monitor_gate_bot/app.py b/crypto_monitor_gate_bot/app.py index 5e5f331..1805bf0 100644 --- a/crypto_monitor_gate_bot/app.py +++ b/crypto_monitor_gate_bot/app.py @@ -5208,12 +5208,12 @@ def render_main_page(page="trade"): order_list = [] for o in raw_order_list: order_list.append(enrich_order_item(row_to_dict(o), current_capital)) - if page in ("trade", "records", "plan_history"): + if page in ("trade", "records"): try: sync_trend_trade_records_from_exchange(conn) except Exception: pass - if page in ("records", "plan_history"): + if page == "records": raw_records = conn.execute( f"SELECT * FROM trade_records WHERE {sql_list_time_field('closed_at', 'created_at', 'opened_at')} >= ? " f"AND {sql_list_time_field('closed_at', 'created_at', 'opened_at')} <= ? ORDER BY id DESC LIMIT 2000", @@ -5240,21 +5240,11 @@ def render_main_page(page="trade"): "SELECT * FROM trend_pullback_plans WHERE status='active' ORDER BY id DESC" ).fetchall() trend_plans = [enrich_active_trend_plan_row(r) for r in trend_plans_raw] - plan_history = [] preview_snapshots = [] - if page == "plan_history": - plan_history_raw = conn.execute( - "SELECT * FROM trend_pullback_plans WHERE status != 'active' " - "AND COALESCE(opened_at, '') >= ? AND COALESCE(opened_at, '') <= ? ORDER BY id DESC LIMIT 500", - (start_bj, end_bj), - ).fetchall() - for pr in plan_history_raw: - pd = row_to_dict(pr) - pd["status_label"] = trend_plan_history_status_label(pd.get("status")) - plan_history.append(pd) + if page == "records": snap_rows = conn.execute( - "SELECT * FROM trend_pullback_preview_snapshots WHERE COALESCE(preview_created_at, '') >= ? " - "AND COALESCE(preview_created_at, '') <= ? ORDER BY id DESC LIMIT 500", + f"SELECT * FROM trend_pullback_preview_snapshots WHERE {sql_list_time_field('preview_created_at')} >= ? " + f"AND {sql_list_time_field('preview_created_at')} <= ? ORDER BY id DESC LIMIT 500", (start_bj, end_bj), ).fetchall() for sr in snap_rows: @@ -5324,7 +5314,6 @@ def render_main_page(page="trade"): max_active_positions=MAX_ACTIVE_POSITIONS, can_trade=can_trade, trend_plans=trend_plans, - plan_history=plan_history, preview_snapshots=preview_snapshots, exchange_sync_from_label=(EXCHANGE_POSITION_SYNC_FROM_BJ or "最近90天"), trend_pullback_dca_legs=TREND_PULLBACK_DCA_LEGS, @@ -5387,7 +5376,8 @@ def stats_page(): @app.route("/plan_history") @login_required def plan_history_page(): - return render_main_page("plan_history") + qs = list_window_redirect_query(session) + return redirect(f"/records?{qs}" if qs else "/records") @app.route("/api/preview_snapshot/") @@ -6450,18 +6440,18 @@ def delete_trend_plan_history(pid): if not row: conn.close() flash("计划不存在") - return redirect(request.referrer or url_for("plan_history_page")) + return redirect(request.referrer or url_for("records_page")) if (row["status"] or "").strip() == "active": conn.close() flash("运行中的计划请使用「结束计划」,不可从历史中删除") - return redirect(request.referrer or url_for("plan_history_page")) + return redirect(request.referrer or url_for("records_page")) conn.execute("DELETE FROM trade_records WHERE trend_plan_id=?", (pid,)) conn.execute("DELETE FROM trend_pullback_preview_snapshots WHERE executed_plan_id=?", (pid,)) conn.execute("DELETE FROM trend_pullback_plans WHERE id=?", (pid,)) conn.commit() conn.close() flash("已删除该计划历史及关联趋势交易记录(若有)") - return redirect(request.referrer or url_for("plan_history_page")) + return redirect(request.referrer or url_for("records_page")) @app.route("/delete_key_monitor/", methods=["POST"]) diff --git a/crypto_monitor_gate_bot/templates/index.html b/crypto_monitor_gate_bot/templates/index.html index b6c9077..a027b12 100644 --- a/crypto_monitor_gate_bot/templates/index.html +++ b/crypto_monitor_gate_bot/templates/index.html @@ -205,14 +205,13 @@ {% with msg=get_flashed_messages() %}{% if msg %}
{{ msg[0] }}
{% endif %}{% endwith %} - {% if page in ('records', 'plan_history') %} + {% if page == 'records' %}
列表筛选(UTC,默认当日):{{ list_window.label }}
- - {% if page == 'plan_history' %} -
-

已结束的趋势回调计划

-
删除将同时移除 trend_plan_id 关联的「趋势回调」交易记录及该计划对应的预览快照归档。交易所平仓同步起点(北京日期):{{ exchange_sync_from_label }}EXCHANGE_POSITION_SYNC_FROM_BJ)。
- {% if plan_history and plan_history|length > 0 %} -
- - - {% for p in plan_history %} - - - - - - - - - - - - {% endfor %} -
ID品种方向杠杆状态结束开仓时间计划保证金≈操作
{{ p.id }}{{ p.symbol }}{{ '做多' if p.direction == 'long' else '做空' }}{{ p.leverage }}x{{ p.status_label }}{{ p.message or '-' }}{{ (p.opened_at or '-')[:16] }}{% if p.plan_margin_capital is not none %}{{ money_fmt(p.plan_margin_capital) }}{% else %}-{% endif %} -
- -
-
-
- {% else %} -
暂无已结束的计划
- {% endif %} -
-
+

预览快照(自本版本起留存)

每次「生成预览」自动归档;取消、过期或执行后仍可点开查看当时参数。执行后状态为「已执行」并带关联计划 ID。
{% if preview_snapshots and preview_snapshots|length > 0 %} @@ -797,7 +762,9 @@
暂无预览快照(新版本生成预览后将出现在此)
{% endif %}
- {% endif %} + + {% endif %} +
{% if page == 'stats' %}