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
+6 -5
View File
@@ -280,25 +280,26 @@ def register_routes(app: Flask) -> None:
t["hold_duration"] = t["hold_duration"] + "(持仓中)"
def _dashboard_payload(u: dict) -> dict:
# 总览只看当前持仓(未平仓),历史成交在「交易复盘」
with database.get_db() as conn:
if u["role"] == "admin":
accounts = database.list_accounts(conn)
trades = database.list_trades(conn, 40)
trades = database.list_trades(conn, 100, open_only=True)
else:
accounts = [
a
for a in database.list_accounts(conn)
if a["id"] == u.get("account_id")
]
trades = database.list_trades(conn, 40, account_id=u.get("account_id"))
trades = database.list_trades(
conn, 100, account_id=u.get("account_id"), open_only=True
)
machines = database.list_machines_for_user(conn, u)
online_machines = [m for m in machines if m.get("online")]
for m in machines:
m["last_seen_fmt"] = _fmt_ts(m.get("last_seen_at"))
for t in trades:
t["time_fmt"] = _fmt_ts(
t.get("close_time") or t.get("open_time") or t.get("created_at")
)
t["time_fmt"] = _fmt_ts(t.get("open_time") or t.get("created_at"))
return {
"accounts": accounts,
"machines": machines,