Hide synthetic dedupe/reconcile rows from trade list count.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -357,6 +357,7 @@ def _trades_where(
|
||||
account_id: Optional[int] = None,
|
||||
machine_id: Optional[int] = None,
|
||||
open_only: bool = False,
|
||||
hide_synthetic: bool = False,
|
||||
) -> tuple[str, list[Any]]:
|
||||
where: list[str] = []
|
||||
params: list[Any] = []
|
||||
@@ -368,6 +369,15 @@ def _trades_where(
|
||||
params.append(machine_id)
|
||||
if open_only:
|
||||
where.append("(t.close_time IS NULL OR t.close_time='')")
|
||||
if hide_synthetic:
|
||||
# 对账/去重产生的影子记录不进交易列表
|
||||
where.append(
|
||||
"("
|
||||
"json_extract(COALESCE(t.snapshot_json, '{}'), '$.event') IS NULL "
|
||||
"OR json_extract(COALESCE(t.snapshot_json, '{}'), '$.event') "
|
||||
"NOT IN ('dedupe_closed', 'reconcile_closed')"
|
||||
")"
|
||||
)
|
||||
clause = (" WHERE " + " AND ".join(where)) if where else ""
|
||||
return clause, params
|
||||
|
||||
@@ -377,8 +387,11 @@ def count_trades(
|
||||
account_id: Optional[int] = None,
|
||||
machine_id: Optional[int] = None,
|
||||
open_only: bool = False,
|
||||
hide_synthetic: bool = False,
|
||||
) -> int:
|
||||
clause, params = _trades_where(account_id, machine_id, open_only=open_only)
|
||||
clause, params = _trades_where(
|
||||
account_id, machine_id, open_only=open_only, hide_synthetic=hide_synthetic
|
||||
)
|
||||
sql = f"SELECT COUNT(*) AS c FROM trades t{clause}"
|
||||
row = conn.execute(sql, tuple(params)).fetchone()
|
||||
return int(row["c"] if row else 0)
|
||||
@@ -391,8 +404,11 @@ def list_trades(
|
||||
machine_id: Optional[int] = None,
|
||||
offset: int = 0,
|
||||
open_only: bool = False,
|
||||
hide_synthetic: bool = False,
|
||||
) -> list[dict]:
|
||||
clause, params = _trades_where(account_id, machine_id, open_only=open_only)
|
||||
clause, params = _trades_where(
|
||||
account_id, machine_id, open_only=open_only, hide_synthetic=hide_synthetic
|
||||
)
|
||||
if open_only:
|
||||
# 持仓列表:同一账户+单号只显示最新一条
|
||||
sql = f"""
|
||||
|
||||
+9
-1
@@ -907,7 +907,14 @@ def register_routes(app: Flask) -> None:
|
||||
account_id = None if u["role"] == "admin" else u.get("account_id")
|
||||
machines, machine_id = _resolve_machine_filter(u, machine_raw)
|
||||
with database.get_db() as conn:
|
||||
total = database.count_trades(conn, account_id=account_id, machine_id=machine_id)
|
||||
database.scrub_synthetic_trade_profits(conn)
|
||||
database.scrub_duplicate_ticket_profits(conn)
|
||||
total = database.count_trades(
|
||||
conn,
|
||||
account_id=account_id,
|
||||
machine_id=machine_id,
|
||||
hide_synthetic=True,
|
||||
)
|
||||
total_pages = max(1, (total + per_page - 1) // per_page)
|
||||
if page > total_pages:
|
||||
page = total_pages
|
||||
@@ -918,6 +925,7 @@ def register_routes(app: Flask) -> None:
|
||||
account_id=account_id,
|
||||
machine_id=machine_id,
|
||||
offset=offset,
|
||||
hide_synthetic=True,
|
||||
)
|
||||
for t in trades:
|
||||
_annotate_trade_times(t)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{% block title %}交易复盘 · {{ app_name }}{% endblock %}
|
||||
{% block content %}
|
||||
<h2 style="margin:0 0 6px">交易记录与复盘</h2>
|
||||
<p class="muted" style="margin:0 0 10px">按机器筛选 · 每页 {{ per_page }} 条 · 时间均为北京时间</p>
|
||||
<p class="muted" style="margin:0 0 10px">按机器筛选 · 每页 {{ per_page }} 条 · 时间均为北京时间 · 已隐藏对账/去重影子记录</p>
|
||||
|
||||
<div style="display:flex;gap:8px;margin-bottom:14px;flex-wrap:wrap">
|
||||
<a class="btn" href="{{ url_for('records_page', machine_id=selected_machine_id) if selected_machine_id else url_for('records_page') }}">交易列表</a>
|
||||
|
||||
Reference in New Issue
Block a user