Add machine filter on trade records and review list.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-17 22:15:22 +08:00
parent 7bf04e3c68
commit 3164a21348
3 changed files with 58 additions and 30 deletions
+20 -25
View File
@@ -251,32 +251,27 @@ def list_trades(
conn: sqlite3.Connection,
limit: int = 200,
account_id: Optional[int] = None,
machine_id: Optional[int] = None,
) -> list[dict]:
if account_id is None:
cur = conn.execute(
"""
SELECT t.*, a.name AS account_name, m.name AS machine_name
FROM trades t
LEFT JOIN accounts a ON a.id = t.account_id
LEFT JOIN machines m ON m.id = t.machine_id
ORDER BY COALESCE(t.close_time, t.open_time, t.created_at) DESC
LIMIT ?
""",
(limit,),
)
else:
cur = conn.execute(
"""
SELECT t.*, a.name AS account_name, m.name AS machine_name
FROM trades t
LEFT JOIN accounts a ON a.id = t.account_id
LEFT JOIN machines m ON m.id = t.machine_id
WHERE t.account_id=?
ORDER BY COALESCE(t.close_time, t.open_time, t.created_at) DESC
LIMIT ?
""",
(account_id, limit),
)
where: list[str] = []
params: list[Any] = []
if account_id is not None:
where.append("t.account_id=?")
params.append(account_id)
if machine_id is not None:
where.append("t.machine_id=?")
params.append(machine_id)
sql = """
SELECT t.*, a.name AS account_name, m.name AS machine_name
FROM trades t
LEFT JOIN accounts a ON a.id = t.account_id
LEFT JOIN machines m ON m.id = t.machine_id
"""
if where:
sql += " WHERE " + " AND ".join(where)
sql += " ORDER BY COALESCE(t.close_time, t.open_time, t.created_at) DESC LIMIT ?"
params.append(limit)
cur = conn.execute(sql, tuple(params))
rows = []
for r in cur.fetchall():
d = row_to_dict(r)