fix: S4改用腾讯外盘/内盘估算资金流向

This commit is contained in:
知微
2026-07-09 18:50:18 +08:00
parent cd05b1fba6
commit 81e100beb5
+35 -28
View File
@@ -168,49 +168,56 @@ def stage3_technical(code, name, klines):
# ── Stage 4: 资金性质分析 ── # ── Stage 4: 资金性质分析 ──
def stage4_capital_flow(code, name): def stage4_capital_flow(code, name):
"""第四关:资金流向 """第四关:资金性质(从腾讯实时行情提取外盘/内盘比)"""
东方财富资金流API
"""
raw = str(code).strip() raw = str(code).strip()
if raw.startswith(("6", "9")): if raw.startswith(("6", "9")):
secid = f"1.{raw}" prefix = "sh"
elif raw.startswith(("0", "3")): elif raw.startswith(("0", "3")):
secid = f"0.{raw}" prefix = "sz"
else: else:
return False, 0, "非A股" return False, 0, "非A股"
url = (f"https://push2his.eastmoney.com/api/qt/stock/fflow/daykline/get?" import subprocess as _sp
f"secid={secid}&fields1=f1,f2,f3&fields2=f51,f52,f53,f54,f55&lmt=3") url = f"http://qt.gtimg.cn/q={prefix}{raw}"
try: try:
import subprocess as _sp r = _sp.run(["curl", "-s", url], capture_output=True, timeout=10)
curl_cmd = ["curl", "-s", "-H", "Referer: https://quote.eastmoney.com/", text = r.stdout.decode("gbk", errors="ignore")
"-H", "User-Agent: Mozilla/5.0", url] parts = text.split("~")
r = _sp.run(curl_cmd, capture_output=True, text=True, timeout=15) if len(parts) < 40:
data = json.loads(r.stdout) return False, 0, "数据不足"
klines = data.get("data", {}).get("klines", [])
if not klines: # 腾讯字段:[7]=外盘(主动买,股),[8]=内盘(主动卖,股)
return False, 0, "无资金流数据" try:
outer = int(float(parts[7])) if parts[7] else 0 # 外盘
inner = int(float(parts[8])) if parts[8] else 0 # 内盘
except:
return False, 0, "解析失败"
if outer <= 0 or inner <= 0:
return False, 0, "无盘口数据"
score = 0 score = 0
ratio = outer / inner if inner > 0 else 1
checks = [] checks = []
for k in klines:
parts = k.split(",")
if len(parts) >= 5:
# 超大单净流入
net_inflow = float(parts[4]) if parts[4] else 0
if net_inflow > 0:
score += 1
if score >= 2: if ratio > 1.3:
checks.append("多日资金净流入") score += 2
elif score >= 1: checks.append(f"外/内={ratio:.2f}")
checks.append("有资金流入迹象") elif ratio > 1.0:
score += 1
checks.append(f"买稍强{ratio:.2f}")
else: else:
checks.append("资金流出") checks.append(f"卖稍强{ratio:.2f}")
# 绝对量也说明资金活跃度
total = outer + inner
if total > 50000000: # >5000万股
score += 1
checks.append(f"活跃{total/10000:.0f}")
return score >= 1, score, "; ".join(checks) return score >= 1, score, "; ".join(checks)
except: except:
return False, 0, "资金流接口失败" return False, 0, "接口失败"
# ── Stage 5: 基本面 ── # ── Stage 5: 基本面 ──