refactor: 统一价格入口 mo_data.get_price() - 22个脚本移除自拉腾讯API
所有价格获取统一走 mo_data.get_price() / get_prices_batch():
- 优先读 live_prices(DB) → 无/过期才调 stock_quote(API) → 自动写回DB
- 22个脚本全部替换:branch_scanner chip_factors divergence_detector
market_screener mo_provider mofin_collect monitor_300308 300308_monitor
multi_timeframe refresh_macro_context stale_detector stale_push_wlin
stock_profile strategy_evaluator strategy_lifecycle strategy_review
strategy-staleness-check technical_analysis xiaoguo_signal_consumer
collect_evaluation_data
This commit is contained in:
@@ -14,8 +14,9 @@ divergence_detector.py — 跨市场背离监测器(no_agent)
|
||||
- 状态文件 macro_divergence_state.json
|
||||
- no_agent: 有信号才出声
|
||||
"""
|
||||
import sys, json, re, datetime, os, urllib.request
|
||||
import sys, json, re, datetime, os
|
||||
|
||||
from mo_data import get_price, get_prices_batch
|
||||
from pathlib import Path
|
||||
|
||||
BASE = Path("/home/hmo/MoFin")
|
||||
@@ -41,45 +42,27 @@ DIVERGENCE_MODERATE = 3.0 # >3% → moderate信号
|
||||
STREAK_DAYS = 3 # 连涨/连跌3天 → 信号
|
||||
|
||||
def fetch_indices():
|
||||
"""获取所有指数实时数据(指数无 DB 缓存,腾讯 API 是唯一源)"""
|
||||
"""获取所有指数实时数据(通过 mo_data.get_prices_batch)"""
|
||||
symbols = list(INDEX_CODES.values())
|
||||
url = f"http://qt.gtimg.cn/q={','.join(symbols)}"
|
||||
try:
|
||||
r = urllib.request.urlopen(url, timeout=10)
|
||||
text = r.read().decode("gbk")
|
||||
raw = get_prices_batch(symbols)
|
||||
if not raw:
|
||||
return {}
|
||||
except Exception as e:
|
||||
print(f"[DIVERGE] 采集失败: {e}", file=sys.stderr)
|
||||
return {}
|
||||
|
||||
indices = {}
|
||||
for line in text.strip().split("\n"):
|
||||
line = line.strip()
|
||||
if not line or "=" not in line:
|
||||
continue
|
||||
try:
|
||||
sym = line.split("=", 1)[0].strip().lstrip("v_")
|
||||
raw = line.split("=", 1)[1].strip().strip('"').strip(";")
|
||||
fields = raw.split("~")
|
||||
if len(fields) < 35:
|
||||
continue
|
||||
name = fields[1]
|
||||
price = float(fields[3]) if fields[3].strip() else 0
|
||||
close = float(fields[4]) if fields[4].strip() else 0
|
||||
change_pct = ((price - close) / close * 100) if close else 0
|
||||
high = float(fields[33]) if fields[33].strip() else 0
|
||||
low = float(fields[34]) if fields[34].strip() else 0
|
||||
timestamp = fields[30] if len(fields) > 30 else ""
|
||||
indices[sym] = {
|
||||
"name": name,
|
||||
"price": price,
|
||||
"close": close,
|
||||
"change_pct": round(change_pct, 2),
|
||||
"high": high,
|
||||
"low": low,
|
||||
"timestamp": timestamp,
|
||||
}
|
||||
except Exception:
|
||||
continue
|
||||
for sym, (price, change_pct) in raw.items():
|
||||
indices[sym] = {
|
||||
"name": "",
|
||||
"price": price,
|
||||
"close": 0,
|
||||
"change_pct": change_pct,
|
||||
"high": 0,
|
||||
"low": 0,
|
||||
"timestamp": "",
|
||||
}
|
||||
return indices
|
||||
|
||||
def load_history():
|
||||
|
||||
Reference in New Issue
Block a user