From ab7f77163f6087c9320f7bdf59173106766de0c2 Mon Sep 17 00:00:00 2001 From: lookt Date: Tue, 15 Sep 2026 21:48:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AE=87=E5=AE=99=E4=B8=89=E7=BA=A7?= =?UTF-8?q?=E5=85=9C=E5=BA=95(=E8=B5=84=E9=87=91=E6=B5=81=E6=B4=BB?= =?UTF-8?q?=E8=B7=83=E8=82=A1)=20+=20=E8=AF=84=E5=88=86=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E5=8D=B3=E8=B7=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/quant/engine.py | 21 ++++++++++++++------- src/web/server.py | 4 ++-- 2 files changed, 16 insertions(+), 9 deletions(-) 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()