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:
@@ -6,31 +6,25 @@
|
||||
|
||||
每30分钟跑一次(交易日)
|
||||
"""
|
||||
import json, sqlite3, urllib.request, re, sys
|
||||
import json, sqlite3, sys
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
from mo_data import get_price
|
||||
|
||||
DB = Path("/home/hmo/MoFin/data/mofin.db")
|
||||
|
||||
def fetch_index(code, name):
|
||||
"""从腾讯API拿指数行情"""
|
||||
"""从统一入口获取指数行情"""
|
||||
try:
|
||||
url = f"http://qt.gtimg.cn/q={code}"
|
||||
req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})
|
||||
resp = urllib.request.urlopen(req, timeout=5)
|
||||
text = resp.read().decode("gbk")
|
||||
m = re.search(r'~([^~]*)~([^~]*)~([\d.]+)~([\d.]+)~([\d.]+)~([\d.]+)', text)
|
||||
if m:
|
||||
_, _, price, prev_close, open_p, high_low = m.groups()
|
||||
high = high_low.split("~")[0] if "~" in high_low else high_low[:8]
|
||||
low = high_low.split("~")[1] if "~" in high_low else "0"
|
||||
change_pct = (float(price) - float(prev_close)) / float(prev_close) * 100 if float(prev_close) else 0
|
||||
price, change_pct = get_price(code)
|
||||
if price is not None:
|
||||
return {
|
||||
"price": float(price),
|
||||
"change_pct": round(change_pct, 2),
|
||||
"high": float(high) if high else float(price),
|
||||
"low": float(low) if low else float(price)
|
||||
"price": price,
|
||||
"change_pct": round(change_pct or 0, 2),
|
||||
"high": price,
|
||||
"low": price,
|
||||
}
|
||||
return None
|
||||
except:
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user