From a58be23a29a9de478696076d3a3db6d4b61cce72 Mon Sep 17 00:00:00 2001 From: ZhouYongyou <128128010+zhouyongyou@users.noreply.github.com> Date: Sun, 2 Nov 2025 00:23:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=E7=9B=88=E4=BA=8F?= =?UTF-8?q?=E7=99=BE=E5=88=86=E6=AF=94=E8=AE=A1=E7=AE=97=E9=94=99=E8=AF=AF?= =?UTF-8?q?=EF=BC=88=E6=9C=AA=E8=80=83=E8=99=91=E6=9D=A0=E6=9D=86=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: - 旧算法只计算价格变化百分比,未考虑杠杆倍数 - 例:10倍杠杆,价格涨1% → 显示+1%(错误),实际应该是+10% - 导致 AI 收到错误的盈亏数据,影响决策 修复: - 使用实际盈亏除以保证金计算百分比 - 公式:pnlPct = (unrealizedPnl / marginUsed) * 100 - 优点: ✓ 考虑杠杆倍数 ✓ 使用 API 提供的实际盈亏(含手续费、资金费率) ✓ 更准确反映真实盈亏百分比 示例对比: - 入场:100,000,当前:101,000(+1%),10倍杠杆 - 旧算法:显示 +1%(错误) - 新算法:显示 +10%(正确) 感谢用户反馈 @1711z 🤖 Generated with Claude Code --- trader/auto_trader.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/trader/auto_trader.go b/trader/auto_trader.go index e6ac3076..19b00865 100644 --- a/trader/auto_trader.go +++ b/trader/auto_trader.go @@ -484,20 +484,18 @@ func (at *AutoTrader) buildTradingContext() (*decision.Context, error) { unrealizedPnl := pos["unRealizedProfit"].(float64) liquidationPrice := pos["liquidationPrice"].(float64) - // 计算盈亏百分比 - pnlPct := 0.0 - if side == "long" { - pnlPct = ((markPrice - entryPrice) / entryPrice) * 100 - } else { - pnlPct = ((entryPrice - markPrice) / entryPrice) * 100 - } - // 计算占用保证金(估算) leverage := 10 // 默认值,实际应该从持仓信息获取 if lev, ok := pos["leverage"].(float64); ok { leverage = int(lev) } marginUsed := (quantity * markPrice) / float64(leverage) + + // 计算盈亏百分比(基于实际盈亏和保证金) + pnlPct := 0.0 + if marginUsed > 0 { + pnlPct = (unrealizedPnl / marginUsed) * 100 + } totalMarginUsed += marginUsed // 跟踪持仓首次出现时间