From b9a4bfcecaa0578e7d9c6291c617951501e507f0 Mon Sep 17 00:00:00 2001 From: ZhouYongyou <128128010+zhouyongyou@users.noreply.github.com> Date: Sun, 2 Nov 2025 21:26:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=B9=B3=E4=BB=93=E7=9B=88=E5=88=A9=E8=AE=A1=E7=AE=97=E9=94=99?= =?UTF-8?q?=E8=AF=AF=20=E9=97=AE=E9=A2=98=EF=BC=9A=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=B9=B3=E4=BB=93=E6=97=B6=EF=BC=8C=E5=8E=86=E5=8F=B2=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E6=98=BE=E7=A4=BA=E7=9A=84=E6=98=AF=E5=85=A8=E4=BB=93?= =?UTF-8?q?=E4=BD=8D=E7=9B=88=E5=88=A9=EF=BC=8C=E8=80=8C=E9=9D=9E=E5=AE=9E?= =?UTF-8?q?=E9=99=85=E5=B9=B3=E4=BB=93=E9=83=A8=E5=88=86=E7=9A=84=E7=9B=88?= =?UTF-8?q?=E5=88=A9=20=E6=A0=B9=E6=9C=AC=E5=8E=9F=E5=9B=A0=EF=BC=9A=20-?= =?UTF-8?q?=20AnalyzePerformance=20=E4=BD=BF=E7=94=A8=E5=BC=80=E4=BB=93?= =?UTF-8?q?=E6=80=BB=E6=95=B0=E9=87=8F=E8=AE=A1=E7=AE=97=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=B9=B3=E4=BB=93=E7=9A=84=E7=9B=88=E5=88=A9=20-=20=E5=BA=94?= =?UTF-8?q?=E8=AF=A5=E4=BD=BF=E7=94=A8=20action.Quantity=EF=BC=88=E5=AE=9E?= =?UTF-8?q?=E9=99=85=E5=B9=B3=E4=BB=93=E6=95=B0=E9=87=8F=EF=BC=89=E8=80=8C?= =?UTF-8?q?=E9=9D=9E=20openPos["quantity"]=EF=BC=88=E6=80=BB=E6=95=B0?= =?UTF-8?q?=E9=87=8F=EF=BC=89=20=E4=BF=AE=E5=A4=8D=EF=BC=9A=20-=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20actualQuantity=20=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E5=8C=BA=E5=88=86=E5=AE=8C=E6=95=B4=E5=B9=B3=E4=BB=93=E5=92=8C?= =?UTF-8?q?=E9=83=A8=E5=88=86=E5=B9=B3=E4=BB=93=20-=20partial=5Fclose=20?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=20action.Quantity=20-=20=E6=89=80=E6=9C=89?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E8=AE=A1=E7=AE=97=EF=BC=88PnL=E3=80=81Positi?= =?UTF-8?q?onValue=E3=80=81MarginUsed=EF=BC=89=E9=83=BD=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=20actualQuantity=20=E5=BD=B1=E5=93=8D=E8=8C=83=E5=9B=B4?= =?UTF-8?q?=EF=BC=9Alogger/decision=5Flogger.go:428-465=20Co-Authored-By:?= =?UTF-8?q?=20tinkle-community=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logger/decision_logger.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/logger/decision_logger.go b/logger/decision_logger.go index efa5ab74..746f58ad 100644 --- a/logger/decision_logger.go +++ b/logger/decision_logger.go @@ -409,18 +409,24 @@ func (l *DecisionLogger) AnalyzePerformance(lookbackCycles int) (*PerformanceAna quantity := openPos["quantity"].(float64) leverage := openPos["leverage"].(int) + // 对于 partial_close,使用实际平仓数量;否则使用完整仓位数量 + actualQuantity := quantity + if action.Action == "partial_close" { + actualQuantity = action.Quantity + } + // 计算实际盈亏(USDT) - // 合约交易 PnL 计算:quantity × 价格差 + // 合约交易 PnL 计算:actualQuantity × 价格差 // 注意:杠杆不影响绝对盈亏,只影响保证金需求 var pnl float64 if side == "long" { - pnl = quantity * (action.Price - openPrice) + pnl = actualQuantity * (action.Price - openPrice) } else { - pnl = quantity * (openPrice - action.Price) + pnl = actualQuantity * (openPrice - action.Price) } // 计算盈亏百分比(相对保证金) - positionValue := quantity * openPrice + positionValue := actualQuantity * openPrice marginUsed := positionValue / float64(leverage) pnlPct := 0.0 if marginUsed > 0 { @@ -431,7 +437,7 @@ func (l *DecisionLogger) AnalyzePerformance(lookbackCycles int) (*PerformanceAna outcome := TradeOutcome{ Symbol: symbol, Side: side, - Quantity: quantity, + Quantity: actualQuantity, Leverage: leverage, OpenPrice: openPrice, ClosePrice: action.Price,