fix: 信号-仓位一致性校验(观望/卖出→0%, 关注≤5%)
This commit is contained in:
@@ -149,20 +149,27 @@ def parse_response(text):
|
|||||||
nums = re.findall(r'[\d.]+', l)
|
nums = re.findall(r'[\d.]+', l)
|
||||||
pct = ""
|
pct = ""
|
||||||
if nums:
|
if nums:
|
||||||
# 取第一个合理的百分比(1-100之间)
|
|
||||||
for n in nums:
|
for n in nums:
|
||||||
f = float(n)
|
f = float(n)
|
||||||
if 1 <= f <= 100:
|
if 1 <= f <= 100:
|
||||||
pct = f"{f:.0f}%"
|
pct = f"{f:.0f}%"
|
||||||
break
|
break
|
||||||
# 如果没有百分比,用文字描述映射到百分比
|
|
||||||
raw = l.replace("建议仓位","").strip()
|
raw = l.replace("建议仓位","").strip()
|
||||||
if not pct:
|
if not pct:
|
||||||
if "轻仓" in raw: pct = "3%"
|
if "轻仓" in raw: pct = "3%"
|
||||||
elif "中" in raw and "仓" in raw: pct = "5%"
|
elif "中" in raw and "仓" in raw: pct = "5%"
|
||||||
elif "重仓" in raw: pct = "10%"
|
elif "重仓" in raw: pct = "10%"
|
||||||
elif "清仓" in raw or "零仓" in raw: pct = "0%"
|
elif "清仓" in raw or "零仓" in raw or "不参与" in raw: pct = "0%"
|
||||||
else: pct = "5%"
|
else: pct = "5%"
|
||||||
|
# 信号与仓位一致性校验
|
||||||
|
if result["signal"] in ("观望", "卖出"):
|
||||||
|
pct = "0%"
|
||||||
|
elif result["signal"] == "关注":
|
||||||
|
# 关注信号仓位不超过5%
|
||||||
|
if pct and pct != "0%":
|
||||||
|
pct_num = int(pct.replace("%",""))
|
||||||
|
if pct_num > 5:
|
||||||
|
pct = "5%"
|
||||||
result["position"] = pct
|
result["position"] = pct
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user