修复bot前端
This commit is contained in:
@@ -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/<int:sid>")
|
||||
@@ -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/<int:kid>", methods=["POST"])
|
||||
|
||||
Reference in New Issue
Block a user