diff --git a/deploy/profile-scripts/realtime_indicators.py b/deploy/profile-scripts/realtime_indicators.py index 7191dd82..8968f543 100644 --- a/deploy/profile-scripts/realtime_indicators.py +++ b/deploy/profile-scripts/realtime_indicators.py @@ -17,6 +17,15 @@ def calc_realtime_indicators(code, price, date_str=None): conn = sqlite3.connect(DB, timeout=30) + # 用 live_prices 的实时价格作为最新价(而非 stock_daily 的收盘价) + lp = conn.execute("SELECT price FROM live_prices WHERE code=?", (code,)).fetchone() + if lp and lp[0]: + latest_price = float(lp[0]) + else: + # fallback 到 stock_daily + dr = conn.execute("SELECT close FROM stock_daily WHERE code=? ORDER BY date DESC LIMIT 1", (code,)).fetchone() + latest_price = float(dr[0]) if dr and dr[0] else price + # 读最近60日K线(计算MA/RSI/bias60需要) rows = conn.execute( "SELECT date, close FROM stock_daily WHERE code=? ORDER BY date DESC LIMIT 60", @@ -27,6 +36,8 @@ def calc_realtime_indicators(code, price, date_str=None): return None closes = [r[1] for r in rows if r[1]] + if latest_price: + closes = [latest_price] + closes # 实时价格在最前 if not closes: conn.close() return None