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)
|
||||
|
||||
+16
-3
@@ -594,12 +594,25 @@ def register_routes(app: Flask) -> None:
|
||||
@login_required
|
||||
def records_page():
|
||||
u = current_user()
|
||||
machine_raw = (request.args.get("machine_id") or "").strip()
|
||||
machine_id = int(machine_raw) if machine_raw.isdigit() else None
|
||||
with database.get_db() as conn:
|
||||
machines = database.list_machines_for_user(conn, u)
|
||||
allowed_ids = {int(m["id"]) for m in machines}
|
||||
if machine_id is not None and machine_id not in allowed_ids:
|
||||
machine_id = None
|
||||
if u["role"] == "admin":
|
||||
trades = database.list_trades(conn, 300)
|
||||
trades = database.list_trades(conn, 300, machine_id=machine_id)
|
||||
else:
|
||||
trades = database.list_trades(conn, 300, account_id=u.get("account_id"))
|
||||
return render_template("records.html", trades=trades)
|
||||
trades = database.list_trades(
|
||||
conn, 300, account_id=u.get("account_id"), machine_id=machine_id
|
||||
)
|
||||
return render_template(
|
||||
"records.html",
|
||||
trades=trades,
|
||||
machines=machines,
|
||||
selected_machine_id=machine_id,
|
||||
)
|
||||
|
||||
@app.get("/records/<int:tid>")
|
||||
@login_required
|
||||
|
||||
@@ -2,7 +2,27 @@
|
||||
{% block title %}交易复盘 · {{ app_name }}{% endblock %}
|
||||
{% block content %}
|
||||
<h2 style="margin:0 0 6px">交易记录与复盘</h2>
|
||||
<p class="muted" style="margin:0 0 14px">参考 crypto_monitor 复盘流程:列表筛选 → 点开详情 → 四周期 K 线 + 入场形式标注。</p>
|
||||
<p class="muted" style="margin:0 0 14px">列表可按机器筛选 → 点开详情 → 四周期 K 线 + 入场形式标注。</p>
|
||||
|
||||
<div class="card" style="margin-bottom:14px">
|
||||
<form method="get" action="{{ url_for('records_page') }}" style="display:flex;gap:10px;align-items:center;flex-wrap:wrap">
|
||||
<label class="muted" for="machine_id">机器</label>
|
||||
<select name="machine_id" id="machine_id" style="min-width:200px">
|
||||
<option value="">全部机器</option>
|
||||
{% for m in machines %}
|
||||
<option value="{{ m.id }}" {% if selected_machine_id == m.id %}selected{% endif %}>
|
||||
{{ m.name }} #{{ m.id }}{% if m.online %} · 在线{% endif %}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<button type="submit" class="btn">筛选</button>
|
||||
{% if selected_machine_id %}
|
||||
<a class="btn secondary" href="{{ url_for('records_page') }}">清除</a>
|
||||
{% endif %}
|
||||
<span class="muted">共 {{ trades|length }} 条</span>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<table>
|
||||
<thead>
|
||||
@@ -29,7 +49,7 @@
|
||||
<td><a href="{{ url_for('record_detail', tid=t.id) }}">打开复盘</a></td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr><td colspan="11" class="muted">暂无数据。客户端上报成交后出现在此。</td></tr>
|
||||
<tr><td colspan="11" class="muted">暂无数据。{% if selected_machine_id %}当前机器下没有成交。{% else %}客户端上报成交后出现在此。{% endif %}</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
Reference in New Issue
Block a user