fix: 品种推荐改为最大手数并补算旧缓存。

- 最大手数 = floor(权益×保证金上限%÷1手保证金)
- 加载与 SSE 推送时实时补算,旧缓存缺字段时自动刷新

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-25 12:24:10 +08:00
parent 9875ee6d44
commit 074551490f
7 changed files with 109 additions and 23 deletions
+12 -4
View File
@@ -10,7 +10,13 @@ from typing import Callable, Optional
from db_conn import connect_db
from kline_stream import sse_format
from recommend_store import load_recommend_cache, recommend_cache_stale, refresh_recommend_cache
from recommend_store import (
load_recommend_cache,
recommend_cache_stale,
recommend_payload,
refresh_recommend_cache,
rows_missing_max_lots,
)
logger = logging.getLogger(__name__)
@@ -72,13 +78,15 @@ def start_recommend_worker(
mode = get_mode_fn() if get_mode_fn else "simulation"
max_pct = float(get_max_margin_pct_fn()) if get_max_margin_pct_fn else 30.0
cached = load_recommend_cache(conn)
if recommend_cache_stale(cached.get("updated_at")):
if recommend_cache_stale(cached.get("updated_at")) or rows_missing_max_lots(
cached.get("rows") or [],
):
refresh_recommend_cache(
conn, capital, quote_fn, trading_mode=mode, max_margin_pct=max_pct,
)
cached = load_recommend_cache(conn)
logger.info("品种推荐每日刷新完成,capital=%.2f rows=%d", capital, len(cached.get("rows") or []))
payload = {**cached, "capital": capital}
logger.info("品种推荐刷新完成,capital=%.2f rows=%d", capital, len(cached.get("rows") or []))
payload = recommend_payload(conn, live_capital=capital, max_margin_pct=max_pct)
finally:
conn.close()
recommend_hub.broadcast("recommend", {"ok": True, **payload})