fix(realtime_indicators): 用live_prices实时价格替代stock_daily收盘价,确保今日数据写入

This commit is contained in:
xxm
2026-08-21 11:40:16 +08:00
parent 7075bd47d2
commit 34992de898
@@ -17,6 +17,15 @@ def calc_realtime_indicators(code, price, date_str=None):
conn = sqlite3.connect(DB, timeout=30) 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需要) # 读最近60日K线(计算MA/RSI/bias60需要)
rows = conn.execute( rows = conn.execute(
"SELECT date, close FROM stock_daily WHERE code=? ORDER BY date DESC LIMIT 60", "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 return None
closes = [r[1] for r in rows if r[1]] closes = [r[1] for r in rows if r[1]]
if latest_price:
closes = [latest_price] + closes # 实时价格在最前
if not closes: if not closes:
conn.close() conn.close()
return None return None