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,