feat: 市场抽象层market_config.py——市场判断/行情符号/市场配置唯一事实源,收敛6处散落实现(market_data/price_monitor x2/stale_push_wlin/technical_analysis/strategy_lab)。纯重构行为等价,为港股接入打底

This commit is contained in:
hmo
2026-08-14 15:56:47 +08:00
parent 442427b214
commit 4c2821aa67
6 changed files with 202 additions and 30 deletions
+6 -7
View File
@@ -11,6 +11,8 @@ import sqlite3
import urllib.request
from pathlib import Path
from market_config import kline_symbol
DB_PATH = Path("/home/hmo/MoFin/data/mofin.db")
UA = "Mozilla/5.0"
@@ -18,20 +20,17 @@ UA = "Mozilla/5.0"
def fetch_tx_klines(code, datalen=120):
"""腾讯前复权日Kqfq),与 stock_daily 数据零偏差,返回 [{date,open,close,high,low,volume}]"""
raw = str(code).strip()
if raw.startswith(("6", "9")):
prefix = "sh"
elif raw.startswith(("0", "3")):
prefix = "sz"
else:
sym = kline_symbol(raw)
if sym is None:
return None
url = f"http://ifzq.gtimg.cn/appstock/app/fqkline/get?param={prefix}{raw},day,,,{datalen},qfq"
url = f"http://ifzq.gtimg.cn/appstock/app/fqkline/get?param={sym},day,,,{datalen},qfq"
try:
req = urllib.request.Request(url, headers={"User-Agent": UA})
opener = urllib.request.build_opener(urllib.request.ProxyHandler({}))
with opener.open(req, timeout=8) as r:
text = r.read().decode("utf-8", errors="replace").strip()
data = json.loads(text)
node = data.get("data", {}).get(f"{prefix}{raw}", {})
node = data.get("data", {}).get(sym, {})
bars = node.get("qfqday") or node.get("day") or []
if not bars or len(bars) < 70:
return None