From c11a11849ffab1021715633c27704fc91cf980c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=A5=E5=BE=AE?= Date: Wed, 8 Jul 2026 12:30:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=AD=96=E7=95=A5=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=B7=B1=E5=BA=A6=E9=87=8F=E4=BB=B7=E5=88=86?= =?UTF-8?q?=E6=9E=90(=E6=94=BE=E9=87=8F=E5=BB=BA=E4=BB=93/=E5=87=BA?= =?UTF-8?q?=E8=B4=A7/=E6=B4=97=E7=9B=98=E6=A3=80=E6=B5=8B)=20=E2=80=94=20?= =?UTF-8?q?=E7=BB=93=E6=9D=9F=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/technical_analysis.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/scripts/technical_analysis.py b/scripts/technical_analysis.py index 27426959..1f3037d9 100644 --- a/scripts/technical_analysis.py +++ b/scripts/technical_analysis.py @@ -55,14 +55,7 @@ def _market_prefix(code): def get_quote(code): - """获取行情数据。DB 优先(price_monitor 维护),腾讯 API fallback""" - # DB 优先 - try: - from mofin_db import get_price_from_db - p, chg = get_price_from_db(code) - if p: return {"code": code, "price": p, "change_pct": chg or 0} - except: pass - # Fallback: 腾讯 API + """获取行情数据。先拿DB的价格和涨跌幅,再调腾讯API拿HLC全量数据""" import time _cache = get_quote.__dict__.get("_cache", {}) now = time.time() @@ -70,6 +63,18 @@ def get_quote(code): if cached and (now - cached["ts"]) < 60: return cached["data"] + # 先从DB拿基础价格(快速,不阻塞) + db_price = None + db_chg = None + try: + from mofin_db import get_price_from_db + p, chg = get_price_from_db(code) + if p: + db_price, db_chg = p, chg + except: + pass + + # 腾讯API获取全量HLC数据 raw = str(code).split("_")[0] prefix = _market_prefix(code) url = f"http://qt.gtimg.cn/q={prefix}{raw}" @@ -77,6 +82,8 @@ def get_quote(code): r = urllib.request.urlopen(url, timeout=5) fields = r.read().decode("gbk").split('"')[1].split("~") except Exception as e: + if db_price: + return {"code": code, "price": db_price, "change_pct": db_chg or 0} return {"code": code, "error": str(e)} def get(i):