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"""
|
||||
|
||||
Reference in New Issue
Block a user