Add stats trading calendar and fix CTP position avg/sync.
Calendar shows daily closed trade count and PnL with emotion-day highlighting; day click loads review-first trade list. Use exchange-only entry average and improve vnpy position sync after CTP reconnect.
This commit is contained in:
@@ -13,7 +13,7 @@ import sqlite3
|
||||
import time
|
||||
import threading
|
||||
import requests
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import date, datetime, timedelta
|
||||
from typing import Optional
|
||||
from functools import wraps
|
||||
from zoneinfo import ZoneInfo
|
||||
@@ -45,7 +45,14 @@ from fee_specs import (
|
||||
purge_non_ctp_fee_rates,
|
||||
)
|
||||
from nav_settings import NAV_TOGGLES, get_nav_items, nav_enabled, save_nav_items
|
||||
from stats_engine import STATS_VIEWS, build_all_stats, load_stats_cache, refresh_stats_cache
|
||||
from stats_engine import (
|
||||
STATS_VIEWS,
|
||||
build_all_stats,
|
||||
get_calendar_day,
|
||||
get_calendar_month,
|
||||
load_stats_cache,
|
||||
refresh_stats_cache,
|
||||
)
|
||||
from kline_store import ensure_kline_tables
|
||||
from kline_stream import kline_hub, sse_format
|
||||
from kline_chart import generate_review_kline_chart, fetch_market_klines, MARKET_PERIODS
|
||||
@@ -1635,6 +1642,40 @@ def api_stats_refresh():
|
||||
return jsonify(data)
|
||||
|
||||
|
||||
@app.route("/api/stats/calendar")
|
||||
@login_required
|
||||
def api_stats_calendar():
|
||||
now = datetime.now(TZ)
|
||||
year = request.args.get("year", type=int) or now.year
|
||||
month = request.args.get("month", type=int) or now.month
|
||||
if month < 1 or month > 12:
|
||||
return jsonify({"error": "invalid month"}), 400
|
||||
conn = get_db()
|
||||
try:
|
||||
data = get_calendar_month(conn, year, month)
|
||||
finally:
|
||||
conn.close()
|
||||
return jsonify(data)
|
||||
|
||||
|
||||
@app.route("/api/stats/calendar/day")
|
||||
@login_required
|
||||
def api_stats_calendar_day():
|
||||
day = (request.args.get("date") or "").strip()
|
||||
if not day:
|
||||
return jsonify({"error": "date required"}), 400
|
||||
try:
|
||||
date.fromisoformat(day)
|
||||
except ValueError:
|
||||
return jsonify({"error": "invalid date"}), 400
|
||||
conn = get_db()
|
||||
try:
|
||||
data = get_calendar_day(conn, day)
|
||||
finally:
|
||||
conn.close()
|
||||
return jsonify(data)
|
||||
|
||||
|
||||
_dashboard_sync_tick = {"n": 0}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user