feat: data-layering 第二批消费层读DB(divergence/staleness/accumulation/collect_eval/strategy_review/mo_provider/multi_timeframe/chip_factors)
This commit is contained in:
@@ -144,29 +144,32 @@ def evaluate_strategy(s, price):
|
||||
sl_recovery = False
|
||||
if tp > 0 or sl > 0:
|
||||
try:
|
||||
prefix = "sh" if code.startswith(('60','68','51','56','50')) else "sz" if code.startswith(('00','30','15')) else "hk"
|
||||
url = f"http://ifzq.gtimg.cn/appstock/app/fqkline/get?param={prefix}{code},day,,,60,qfq"
|
||||
import subprocess as sp
|
||||
r = sp.run(["curl", "-s", "--max-time", "3", url], capture_output=True, text=True, timeout=5)
|
||||
if r.returncode == 0 and r.stdout:
|
||||
data = json.loads(r.stdout)
|
||||
day_key = 'qfqday' if prefix != 'hk' else 'day'
|
||||
bars = data.get('data', {}).get(f'{prefix}{code}', {}).get(day_key, [])
|
||||
if bars:
|
||||
prices = [(float(b[2]), float(b[3]), b[0]) for b in bars if len(b) > 3] # (high, low, date)
|
||||
recent_high = max(p[0] for p in prices)
|
||||
recent_low = min(p[1] for p in prices)
|
||||
# 检查止损触发后的走势:是否后来反弹了?
|
||||
if sl > 0:
|
||||
# 找出价格低于SL的K线
|
||||
below_sl = [p for p in prices if p[1] <= sl]
|
||||
above_sl_later = [p for p in prices if p[1] > sl * 1.03]
|
||||
if below_sl and above_sl_later:
|
||||
# 曾跌破SL,但后来涨回去了 → 洗盘
|
||||
first_below = min(below_sl, key=lambda x: x[2])
|
||||
last_above = max(above_sl_later, key=lambda x: x[2])
|
||||
if last_above[2] > first_below[2]:
|
||||
sl_recovery = True
|
||||
# 读 stock_daily 近60根日K(2026-08-26 分层铁律:消费层不直连腾讯API)
|
||||
raw_code = str(code).split("_")[0]
|
||||
if raw_code.lower().startswith("hk"):
|
||||
raw_code = raw_code[2:]
|
||||
_conn = sqlite3.connect(str(DB_PATH), timeout=5)
|
||||
_bars = _conn.execute(
|
||||
"SELECT date, high, low FROM stock_daily WHERE code=? "
|
||||
"ORDER BY date DESC LIMIT 60", (raw_code,)
|
||||
).fetchall()
|
||||
_conn.close()
|
||||
if _bars:
|
||||
# 转为升序(旧→新),与 qfqday 时序一致
|
||||
prices = [(float(b[1]), float(b[2]), b[0]) for b in reversed(_bars) if b[1] and b[2]] # (high, low, date)
|
||||
recent_high = max(p[0] for p in prices)
|
||||
recent_low = min(p[1] for p in prices)
|
||||
# 检查止损触发后的走势:是否后来反弹了?
|
||||
if sl > 0:
|
||||
# 找出价格低于SL的K线
|
||||
below_sl = [p for p in prices if p[1] <= sl]
|
||||
above_sl_later = [p for p in prices if p[1] > sl * 1.03]
|
||||
if below_sl and above_sl_later:
|
||||
# 曾跌破SL,但后来涨回去了 → 洗盘
|
||||
first_below = min(below_sl, key=lambda x: x[2])
|
||||
last_above = max(above_sl_later, key=lambda x: x[2])
|
||||
if last_above[2] > first_below[2]:
|
||||
sl_recovery = True
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user