Files
nofx/logger
ZhouYongyou 21ae77e7cc fix(stats): aggregate partial closes into single trade for accurate statistics
## Problem
Multiple partial_close actions on the same position were being counted as separate trades, inflating TotalTrades count and distorting win rate/profit factor statistics.
**Example of bug:**
- Open 1 BTC @ $100,000
- Partial close 30% @ $101,000 → Counted as trade #1 
- Partial close 50% @ $102,000 → Counted as trade #2 
- Close remaining 20% @ $103,000 → Counted as trade #3 
- **Result:** 3 trades instead of 1 
## Solution
### 1. Added tracking fields to openPositions map
- `remainingQuantity`: Tracks remaining position size
- `accumulatedPnL`: Accumulates PnL from all partial closes
- `partialCloseCount`: Counts number of partial close operations
- `partialCloseVolume`: Total volume closed partially
### 2. Modified partial_close handling logic
- Each partial_close:
  - Accumulates PnL into `accumulatedPnL`
  - Reduces `remainingQuantity`
  - **Does NOT increment TotalTrades++**
  - Keeps position in openPositions map
- Only when `remainingQuantity <= 0.0001`:
  - Records ONE TradeOutcome with aggregated PnL
  - Increments TotalTrades++ once
  - Removes from openPositions map
### 3. Updated full close handling
- If position had prior partial closes:
  - Adds `accumulatedPnL` to final close PnL
  - Reports total PnL in TradeOutcome
### 4. Fixed GetStatistics()
- Removed `partial_close` from TotalClosePositions count
- Only `close_long/close_short/auto_close` count as close operations
## Impact
-  Statistics now accurate: multiple partial closes = 1 trade
-  Win rate calculated correctly
-  Profit factor reflects true performance
-  Backward compatible: handles positions without tracking fields
## Testing
-  Compiles successfully
- ⚠️ Requires validation with live partial_close scenarios
## Code Changes
```
logger/decision_logger.go:
- Lines 420-430: Add tracking fields to openPositions
- Lines 441-534: Implement partial_close aggregation logic
- Lines 536-593: Update full close to include accumulated PnL
- Lines 246-250: Fix GetStatistics() to exclude partial_close
```
2025-11-04 18:58:20 +08:00
..