b31f861596
Co-authored-by: Cursor <cursoragent@cursor.com>
26 lines
880 B
Python
26 lines
880 B
Python
"""实例数据统计:复盘 KPI + 已实现盈亏曲线 API."""
|
|
from __future__ import annotations
|
|
|
|
from typing import Any, Callable
|
|
|
|
from flask import Flask, jsonify, request
|
|
|
|
|
|
def install_instance_data_stats(app: Flask, app_module: Any) -> None:
|
|
get_db: Callable = app_module.get_db
|
|
login_required = app_module.login_required
|
|
|
|
@app.route("/api/instance/cash_curve")
|
|
@login_required
|
|
def api_instance_cash_curve():
|
|
from lib.instance.instance_cash_sample_lib import query_realized_pnl_series_with_db
|
|
|
|
range_key = (request.args.get("range") or "7d").strip()
|
|
conn = get_db()
|
|
try:
|
|
return jsonify(query_realized_pnl_series_with_db(conn, range_key=range_key))
|
|
except Exception as e:
|
|
return jsonify({"ok": False, "msg": f"加载盈亏曲线失败: {e}"}), 500
|
|
finally:
|
|
conn.close()
|