feat: options stats profit/loss totals and history delete

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-07 10:31:09 +08:00
parent 5fdfc67438
commit 2d52bfac80
4 changed files with 77 additions and 8 deletions
+25
View File
@@ -573,15 +573,40 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
win_rate = round(len(wins) / total_closed * 100, 2) if total_closed else 0
avg_win = sum(wins) / len(wins) if wins else None
avg_loss = sum(losses) / len(losses) if losses else None
total_profit = round(sum(wins), 4) if wins else 0.0
total_loss = round(abs(sum(losses)), 4) if losses else 0.0
return jsonify(
{
"ok": True,
"total_closed": total_closed,
"win_rate": win_rate,
"profit_loss_ratio": profit_loss_ratio_from_averages(avg_win, avg_loss),
"total_profit": total_profit,
"total_loss": total_loss,
}
)
@app.route("/api/options/history/<int:trade_id>", methods=["DELETE"])
@lr
def api_options_history_delete(trade_id: int):
ex, err = _require_options_ex(cfg)
if ex is None:
return jsonify({"ok": False, "msg": err})
conn = cfg["get_db"]()
try:
init_options_tables(conn)
row = conn.execute(
"SELECT id, status FROM options_trades WHERE id = ?",
(trade_id,),
).fetchone()
if not row:
return jsonify({"ok": False, "msg": "记录不存在"})
conn.execute("DELETE FROM options_trades WHERE id = ?", (trade_id,))
conn.commit()
finally:
conn.close()
return jsonify({"ok": True})
def _start_monitor_thread(app: Flask, cfg: dict[str, Any]) -> None:
if app.extensions.get("options_monitor_started"):