Add daily trend status to product recommendations with breakout priority

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-25 17:25:34 +08:00
parent aba67a3d16
commit 04b6f5e72d
6 changed files with 209 additions and 10 deletions
+11
View File
@@ -9,6 +9,7 @@ from typing import Callable, Optional
from fee_specs import ensure_fee_rates_schema
from product_recommend import list_product_recommendations
from recommend_trend import sort_recommend_by_trend
logger = logging.getLogger(__name__)
@@ -38,6 +39,13 @@ def rows_missing_max_lots(rows: list[dict]) -> bool:
return any("max_lots" not in r for r in rows)
def rows_missing_trend(rows: list[dict]) -> bool:
"""缓存是否为旧版(缺少走势字段)。"""
if not rows:
return False
return any("trend" not in r for r in rows)
def recommend_cache_needs_refresh(
cached: dict,
*,
@@ -49,6 +57,8 @@ def recommend_cache_needs_refresh(
rows = cached.get("rows") or []
if rows_missing_max_lots(rows):
return True
if rows_missing_trend(rows):
return True
if float(capital or 0) > 0 and not rows:
return True
return False
@@ -214,6 +224,7 @@ def recommend_payload(
rows, cap, max_margin_pct=pct, trading_mode=trading_mode,
)
rows = filter_recommend_by_sizing(rows, sizing_mode=sizing_mode, fixed_lots=fixed_lots)
rows = sort_recommend_by_trend(rows)
payload["rows"] = rows
payload["needs_refresh"] = recommend_cache_needs_refresh(payload, capital=cap)
return payload