Add hedge history delete/detail modal and typed stats cards.

History shows contract names with clickable fill details; stats split perp vs options plans for win rate, profit factor, max win/loss, and drawdown.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-14 14:04:48 +08:00
parent e6907dfbbe
commit f6ef06f659
8 changed files with 700 additions and 51 deletions
+37 -4
View File
@@ -490,7 +490,11 @@ def register_hedge_plan_routes(app: Flask, cfg: dict[str, Any]) -> None:
@app.route("/api/hedge-plan/history")
@lr
def api_hedge_history():
from lib.hedge_plan.hedge_plan_db import init_hedge_plan_tables, list_plans
from lib.hedge_plan.hedge_plan_db import (
attach_legs_to_plans,
init_hedge_plan_tables,
list_plans,
)
conn = cfg["get_db"]()
try:
@@ -498,10 +502,11 @@ def register_hedge_plan_routes(app: Flask, cfg: dict[str, Any]) -> None:
rows = list_plans(conn, status="closed", limit=100)
failed = list_plans(conn, status="failed", limit=50)
cancelled = list_plans(conn, status="cancelled", limit=50)
merged = attach_legs_to_plans(conn, rows + failed + cancelled)
conn.commit()
finally:
conn.close()
return jsonify({"ok": True, "plans": rows + failed + cancelled})
return jsonify({"ok": True, "plans": merged})
@app.route("/api/hedge-plan/stats")
@lr
@@ -520,7 +525,12 @@ def register_hedge_plan_routes(app: Flask, cfg: dict[str, Any]) -> None:
@app.route("/api/hedge-plan/<int:plan_id>")
@lr
def api_hedge_detail(plan_id: int):
from lib.hedge_plan.hedge_plan_db import get_plan, get_plan_legs, init_hedge_plan_tables
from lib.hedge_plan.hedge_plan_db import (
get_plan,
get_plan_legs,
init_hedge_plan_tables,
legs_contract_summary,
)
conn = cfg["get_db"]()
try:
@@ -532,7 +542,30 @@ def register_hedge_plan_routes(app: Flask, cfg: dict[str, Any]) -> None:
conn.commit()
finally:
conn.close()
return jsonify({"ok": True, "plan": plan, "legs": legs})
return jsonify(
{
"ok": True,
"plan": plan,
"legs": legs,
"contracts_summary": legs_contract_summary(legs),
}
)
@app.route("/api/hedge-plan/<int:plan_id>", methods=["DELETE"])
@lr
def api_hedge_delete(plan_id: int):
from lib.hedge_plan.hedge_plan_db import delete_plan, init_hedge_plan_tables
conn = cfg["get_db"]()
try:
init_hedge_plan_tables(conn)
out = delete_plan(conn, plan_id)
if not out.get("ok"):
return jsonify(out), 400
conn.commit()
finally:
conn.close()
return jsonify(out)
@app.route("/api/hedge-plan/monitor-tick", methods=["POST"])
@lr