Add machine filter on trade records and review list.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user