Fix empty recommend list when CTP ticks unavailable off-hours.

Fall back to daily prev_close for margin estimates; keep previous cache when refresh gets all no_price; stop re-fetching only for missing turnover.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-03 06:43:20 +08:00
parent 125cc60a3d
commit 16d90814a1
2 changed files with 40 additions and 4 deletions
+17 -2
View File
@@ -302,6 +302,21 @@ def list_product_recommendations(
quote = quote_fn(ths) or {}
price = quote.get("price")
main_code = (quote.get("ths_code") or "").strip()
daily: dict = {}
if main_code:
daily = analyze_product_daily(main_code)
if not price or float(price or 0) <= 0:
for key in ("prev_close", "today_open", "price"):
val = daily.get(key) if daily else None
if val in (None, "", 0):
continue
try:
px = float(val)
except (TypeError, ValueError):
continue
if px > 0:
price = px
break
row = assess_product_for_capital(
product, capital, price,
max_margin_pct=max_margin_pct,
@@ -311,8 +326,8 @@ def list_product_recommendations(
margin_used=margin_used,
)
row["main_code"] = main_code
if main_code:
row.update(analyze_product_daily(main_code))
if daily:
row.update(daily)
_attach_turnover(row)
return row
except Exception as exc: