feat(evaluation): restore versioned strategy tracking tab

This commit is contained in:
hmo
2026-08-11 20:16:06 +00:00
parent 924ccb7968
commit 9d74ca9666
4 changed files with 262 additions and 84 deletions
+38 -1
View File
@@ -488,6 +488,43 @@ def api_watchlist():
return jsonify({"error": str(e)}), 500
@app.route("/api/tracking")
def get_tracking():
"""策略追踪评估:所有推荐的历史记录和结果"""
import sqlite3
conn = sqlite3.connect("/home/hmo/MoFin/data/mofin.db")
conn.row_factory = sqlite3.Row
rows = conn.execute("""
SELECT st.*, lp.price as current_price
FROM strategy_tracking st
LEFT JOIN live_prices lp ON st.code = lp.code
ORDER BY
CASE st.status WHEN 'active' THEN 0 WHEN 'hit_tp' THEN 1 WHEN 'hit_sl' THEN 2 ELSE 3 END,
st.tracked_at DESC
""").fetchall()
tracks = []
for r in rows:
d = dict(r)
# 理论盈亏:按买入区中值买入,当前价 vs 中值
if d.get('entry_mid') and d.get('current_price') and d.get('status') == 'active':
mid = float(d['entry_mid'])
price = float(d['current_price'])
d['theoretical_pnl'] = round((price - mid) / mid * 100, 2)
tracks.append(d)
conn.close()
return jsonify({
"tracks": tracks,
"stats": {
"total": len(tracks),
"active": sum(1 for r in tracks if r["status"] == "active"),
"hit_tp": sum(1 for r in tracks if r["status"] == "hit_tp"),
"hit_sl": sum(1 for r in tracks if r["status"] == "hit_sl"),
"expired": sum(1 for r in tracks if r["status"] == "expired"),
"manual": sum(1 for r in tracks if r["status"] == "manual_close"),
}
})
@app.route("/api/overview")
def api_overview():
"""概览数据"""
@@ -1692,4 +1729,4 @@ register_routes(app)
if __name__ == "__main__":
port = int(os.environ.get("PORT", 8899))
print(f"🚀 MoFin Dashboard → http://0.0.0.0:{port}")
app.run(host="0.0.0.0", port=port, debug=False)
app.run(host="0.0.0.0", port=port, debug=False)