From 3d7b9d8b568b7dcce4eada718fede0d26ac9a4af Mon Sep 17 00:00:00 2001 From: lookt Date: Tue, 15 Sep 2026 21:27:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AE=87=E5=AE=99=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E4=B8=89=E7=BA=A7=E5=85=9C=E5=BA=95=EF=BC=88=E6=96=B0=E6=B5=AA?= =?UTF-8?q?=E2=86=92=E4=B8=9C=E8=B4=A2=E2=86=92=E8=B5=84=E9=87=91=E6=B5=81?= =?UTF-8?q?=E8=A1=A8=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/quant/engine.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/quant/engine.py b/src/quant/engine.py index 44655a5..9ce6e66 100644 --- a/src/quant/engine.py +++ b/src/quant/engine.py @@ -42,16 +42,38 @@ class QuantEngine: def universe(self, n=UNIVERSE_N): import akshare as ak + # 1) 新浪全市场快照 try: df = ak.stock_zh_a_spot() df['amt'] = pd.to_numeric(df.get('成交额'), errors='coerce') df['code'] = df.get('代码').astype(str).str[-6:] df = df[df['code'].str[:2].isin(('60', '00', '30', '68'))] df = df.sort_values('amt', ascending=False).head(n) - return list(df['code']), dict(zip(df['code'], df['名称'].astype(str))) + pairs = list(zip(df['code'], df['名称'].astype(str))) + if pairs: + return [c for c, _ in pairs], dict(pairs) except Exception as e: - print('[quant] 宇宙获取失败:', e, flush=True) - return [], {} + print('[quant] 新浪宇宙失败,改用东财:', e, flush=True) + # 2) 东财全市场快照兜底 + try: + df = ak.stock_zh_a_spot_em() + df['amt'] = pd.to_numeric(df.get('成交额'), errors='coerce') + df['code'] = df.get('代码').astype(str).str[-6:] + df = df[df['code'].str[:2].isin(('60', '00', '30', '68'))] + df = df.sort_values('amt', ascending=False).head(n) + pairs = list(zip(df['code'], df['名称'].astype(str))) + if pairs: + return [c for c, _ in pairs], dict(pairs) + except Exception as e: + print('[quant] 东财宇宙失败:', e, flush=True) + # 3) 兜底:资金流表中的活跃股 + conn = self.fetcher._conn() + try: + rows = conn.execute("SELECT DISTINCT ts_code FROM money_flow LIMIT ?", + (n,)).fetchall() + return [r[0] for r in rows], {} + finally: + pass def _kline_worker(self): """后台轮询:持续刷新宇宙内 K 线(day 全量 + 30/5 分钟)"""