Dashboard shows open positions only; closed trades stay in review.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-21 16:33:30 +08:00
parent 74cfb8b4aa
commit e68393fe5b
3 changed files with 28 additions and 19 deletions
+13 -3
View File
@@ -268,6 +268,7 @@ def resolve_web_user_for_activation(conn: sqlite3.Connection, act: dict) -> Opti
def _trades_where(
account_id: Optional[int] = None,
machine_id: Optional[int] = None,
open_only: bool = False,
) -> tuple[str, list[Any]]:
where: list[str] = []
params: list[Any] = []
@@ -277,6 +278,8 @@ def _trades_where(
if machine_id is not None:
where.append("t.machine_id=?")
params.append(machine_id)
if open_only:
where.append("(t.close_time IS NULL OR t.close_time='')")
clause = (" WHERE " + " AND ".join(where)) if where else ""
return clause, params
@@ -285,8 +288,9 @@ def count_trades(
conn: sqlite3.Connection,
account_id: Optional[int] = None,
machine_id: Optional[int] = None,
open_only: bool = False,
) -> int:
clause, params = _trades_where(account_id, machine_id)
clause, params = _trades_where(account_id, machine_id, open_only=open_only)
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)
@@ -298,15 +302,21 @@ def list_trades(
account_id: Optional[int] = None,
machine_id: Optional[int] = None,
offset: int = 0,
open_only: bool = False,
) -> list[dict]:
clause, params = _trades_where(account_id, machine_id)
clause, params = _trades_where(account_id, machine_id, open_only=open_only)
order = (
"ORDER BY COALESCE(t.open_time, t.created_at) DESC"
if open_only
else "ORDER BY COALESCE(t.close_time, t.open_time, t.created_at) DESC"
)
sql = f"""
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
{clause}
ORDER BY COALESCE(t.close_time, t.open_time, t.created_at) DESC
{order}
LIMIT ? OFFSET ?
"""
params.extend([limit, max(0, int(offset))])