修复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"])
|
||||
|
||||
@@ -205,14 +205,13 @@
|
||||
</div>
|
||||
<div class="top-nav">
|
||||
<a href="/trade" class="{% if page == 'trade' %}active{% endif %}">交易执行</a>
|
||||
<a href="/records" class="{% if page == 'records' %}active{% endif %}">交易记录</a>
|
||||
<a href="/plan_history" class="{% if page == 'plan_history' %}active{% endif %}">计划历史</a>
|
||||
<a href="/records" class="{% if page == 'records' %}active{% endif %}">交易记录与复盘</a>
|
||||
<a href="/stats" class="{% if page == 'stats' %}active{% endif %}">统计分析</a>
|
||||
</div>
|
||||
{% with msg=get_flashed_messages() %}{% if msg %}<div class="flash">{{ msg[0] }}</div>{% endif %}{% endwith %}
|
||||
|
||||
|
||||
{% if page in ('records', 'plan_history') %}
|
||||
{% if page == 'records' %}
|
||||
<div class="list-window-bar">
|
||||
<span style="color:#cfd3ef">列表筛选(<strong>UTC</strong>,默认当日):{{ list_window.label }}</span>
|
||||
<label>预设
|
||||
@@ -556,7 +555,7 @@
|
||||
|
||||
{% if page == 'records' %}
|
||||
<div class="card full records-card">
|
||||
<h2>交易记录 & 错过机会</h2>
|
||||
<h2>交易记录与复盘</h2>
|
||||
<div class="form-row" style="margin-bottom:10px;gap:8px">
|
||||
<label style="display:flex;align-items:center;gap:6px;font-size:.82rem;color:#cfd3ef">
|
||||
<input id="review-mode-toggle" type="checkbox">
|
||||
@@ -738,41 +737,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if page == 'plan_history' %}
|
||||
<div class="card full" style="margin-bottom:12px">
|
||||
<h2 style="margin-bottom:6px">已结束的趋势回调计划</h2>
|
||||
<div class="rule-tip" style="margin-bottom:8px">删除将同时移除 <code>trend_plan_id</code> 关联的「趋势回调」交易记录及该计划对应的预览快照归档。交易所平仓同步起点(北京日期):<strong>{{ exchange_sync_from_label }}</strong>(<code>EXCHANGE_POSITION_SYNC_FROM_BJ</code>)。</div>
|
||||
{% if plan_history and plan_history|length > 0 %}
|
||||
<div class="table-wrap">
|
||||
<table>
|
||||
<tr><th>ID</th><th>品种</th><th>方向</th><th>杠杆</th><th>状态</th><th>结束</th><th>开仓时间</th><th>计划保证金≈</th><th>操作</th></tr>
|
||||
{% for p in plan_history %}
|
||||
<tr>
|
||||
<td>{{ p.id }}</td>
|
||||
<td>{{ p.symbol }}</td>
|
||||
<td><span class="badge {{ 'direction-long' if p.direction == 'long' else 'direction-short' }}">{{ '做多' if p.direction == 'long' else '做空' }}</span></td>
|
||||
<td>{{ p.leverage }}x</td>
|
||||
<td>{{ p.status_label }}</td>
|
||||
<td>{{ p.message or '-' }}</td>
|
||||
<td>{{ (p.opened_at or '-')[:16] }}</td>
|
||||
<td>{% if p.plan_margin_capital is not none %}{{ money_fmt(p.plan_margin_capital) }}{% else %}-{% endif %}</td>
|
||||
<td>
|
||||
<form action="{{ url_for('delete_trend_plan_history', pid=p.id) }}" method="post" style="display:inline" onsubmit="return confirm('确定删除该计划历史及关联趋势交易记录?');">
|
||||
<button type="submit" class="table-del">删除</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="rule-tip" style="color:#8892b0">暂无已结束的计划</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="card full" style="margin-bottom:12px">
|
||||
<div class="card full" id="preview-snapshots" style="margin-bottom:12px">
|
||||
<h2 style="margin-bottom:6px">预览快照(自本版本起留存)</h2>
|
||||
<div class="rule-tip" style="margin-bottom:8px">每次「生成预览」自动归档;取消、过期或执行后仍可点开查看当时参数。执行后状态为「已执行」并带关联计划 ID。</div>
|
||||
{% if preview_snapshots and preview_snapshots|length > 0 %}
|
||||
@@ -797,7 +762,9 @@
|
||||
<div class="rule-tip" style="color:#8892b0">暂无预览快照(新版本生成预览后将出现在此)</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if page == 'stats' %}
|
||||
<div class="card stats-card full" id="stats-card">
|
||||
|
||||
Reference in New Issue
Block a user