diff --git a/app/db.py b/app/db.py index c9ebd8b..e7799a7 100644 --- a/app/db.py +++ b/app/db.py @@ -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""" diff --git a/app/routes.py b/app/routes.py index 56de3d6..42197de 100644 --- a/app/routes.py +++ b/app/routes.py @@ -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) diff --git a/app/templates/records.html b/app/templates/records.html index 7313886..d52d121 100644 --- a/app/templates/records.html +++ b/app/templates/records.html @@ -2,7 +2,7 @@ {% block title %}交易复盘 · {{ app_name }}{% endblock %} {% block content %}
按机器筛选 · 每页 {{ per_page }} 条 · 时间均为北京时间
+按机器筛选 · 每页 {{ per_page }} 条 · 时间均为北京时间 · 已隐藏对账/去重影子记录