fix: MA排序bug(用日期代替价格)+量价历史存储+deep_vol接入full_analysis+DB路径统一

This commit is contained in:
知微
2026-07-08 12:36:10 +08:00
parent 2762ddf3ae
commit 258b8871ef
3 changed files with 58 additions and 23 deletions
+16 -9
View File
@@ -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):
@@ -465,7 +472,7 @@ def analyze_volume_deep(code):
import sqlite3
from pathlib import Path
DATA_DIR = Path(__file__).parent / "data"
DATA_DIR = Path(__file__).parent.parent / "data"
try:
conn = sqlite3.connect(str(DATA_DIR / "mofin.db"))
row = conn.execute("SELECT cache_json FROM mtf_cache WHERE code=?", (code,)).fetchone()