fix: parse_signal 兼容【仓位】字段+unit追踪+减幅计算+跟单建议
【背景】Jasonleo 9次BTC减仓信号,process_signal.py 的 size regex 只匹配【仓位大小】,不匹配【仓位】。导致推信号显示 size='?',无法算减幅,agent 推减仓建议全错位。 【修复】 1. parse_signal.py:67 - size regex 兼容【仓位(?:大小)?】 2. parse_signal.py:68 - 新增 unit 字段(BTC/USDT/张) 3. parse_signal.py:285 - 推信号时显示 size+unit 4. parse_signal.py:294 - 跟单建议: fetch 真实持仓+算大佬减幅+同比例跟单 5. signal_tracker.py:158 - format_comparison 智能显示整数/小数 + 减幅% 【测试】1450.719 BTC ✅, 49.958(无单位)✅, 10000 USDT ✅ 【验证】format_comparison 减幅 -7.1% 显示正确
This commit is contained in:
@@ -155,17 +155,28 @@ def format_comparison(trader, symbol, current_size):
|
||||
"""格式化对比信息"""
|
||||
last_size, desc = compare_position(trader, symbol, current_size)
|
||||
|
||||
# 智能显示: 整数直接显示, 小数保留 2-3 位
|
||||
def _fmt(n):
|
||||
if n is None:
|
||||
return "?"
|
||||
if n == int(n) and abs(n) >= 10:
|
||||
return f"{int(n):,}"
|
||||
return f"{n:,.2f}"
|
||||
|
||||
if last_size is None:
|
||||
return f"• {trader} {symbol}: 首次出现,仓位 {current_size:,.0f}"
|
||||
return f"• {trader} {symbol}: 首次出现,仓位 {_fmt(current_size)}"
|
||||
|
||||
if "不变" in desc:
|
||||
return f"• {trader} {symbol}: 仓位不变 {current_size:,.0f}"
|
||||
return f"• {trader} {symbol}: 仓位不变 {_fmt(current_size)}"
|
||||
elif "加仓" in desc:
|
||||
return f"• 📈 {trader} {symbol}: {last_size:,.0f} → {current_size:,.0f}({desc})"
|
||||
return f"• 📈 {trader} {symbol}: {_fmt(last_size)} → {_fmt(current_size)}({desc})"
|
||||
elif "减仓" in desc:
|
||||
return f"• 📉 {trader} {symbol}: {last_size:,.0f} → {current_size:,.0f}({desc})"
|
||||
delta_pct = 0
|
||||
if last_size and last_size > 0:
|
||||
delta_pct = (current_size - last_size) / last_size * 100
|
||||
return f"• 📉 {trader} {symbol}: {_fmt(last_size)} → {_fmt(current_size)}(减幅 {delta_pct:+.1f}%)"
|
||||
else:
|
||||
return f"• {trader} {symbol}: {last_size:,.0f} → {current_size:,.0f}({desc})"
|
||||
return f"• {trader} {symbol}: {_fmt(last_size)} → {_fmt(current_size)}({desc})"
|
||||
|
||||
# ─── 交易员统计 ──────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
Reference in New Issue
Block a user