diff --git a/src/quant/engine.py b/src/quant/engine.py index 4873af9..1a1f84e 100644 --- a/src/quant/engine.py +++ b/src/quant/engine.py @@ -66,14 +66,21 @@ class QuantEngine: return [c for c, _ in pairs], dict(pairs) except Exception as e: print('[quant] 东财宇宙失败:', e, flush=True) - # 3) 兜底:资金流表中的活跃股 - conn = self.fetcher._conn() + # 3) 兜底:资金流表中的活跃股(当日有资金流的股票即活跃宇宙) try: - rows = conn.execute("SELECT DISTINCT ts_code FROM money_flow LIMIT ?", - (n,)).fetchall() - return [r[0] for r in rows], {} - finally: - pass + conn = self.fetcher._conn() + try: + rows = conn.execute("SELECT DISTINCT ts_code FROM money_flow " + "ORDER BY trade_date DESC LIMIT ?", (n,)).fetchall() + finally: + conn.close() + codes = [r[0] for r in rows] + if codes: + print('[quant] 宇宙兜底: 资金流活跃股 {} 只'.format(len(codes)), flush=True) + return codes, {} + except Exception as e: + print('[quant] 资金流兜底失败:', e, flush=True) + return [], {} def _kline_count(self, tf): import sqlite3 diff --git a/src/web/server.py b/src/web/server.py index ee88d4c..791436d 100644 --- a/src/web/server.py +++ b/src/web/server.py @@ -70,13 +70,13 @@ async def collector_task(_app): quant.start() def _quant_loops(): + time.sleep(5) # 启动即先跑一轮打分(K线可能不足,引擎会自行跳过) while True: try: - time.sleep(SCORING_INTERVAL_S) quant.run_scoring_and_push() except Exception as e: print('[quant-loop]', e, flush=True) - time.sleep(60) + time.sleep(SCORING_INTERVAL_S) threading.Thread(target=_quant_loops, daemon=True, name='quant-scoring').start()