Bug: Trade #8 (SHORT SOL-PERP) sent 13 duplicate 'POSITION CLOSED' notifications - P&L compounded: $11.50 → $38.56 → $64.70 → ... → $155.05 - Root cause: Layer 2 ghost detection (failureCount > 20) didn't check closingInProgress flag - Called handleExternalClosure() every 2 seconds during rate limit storm (6,581 failures) - Each call sent Telegram notification with compounding P&L Fix: - Added closingInProgress check before Layer 2 ghost detection - Mark trade as closing BEFORE calling handleExternalClosure() - Prevents duplicate processing during async database updates Location: lib/trading/position-manager.ts lines 1477-1490 Prevents: Common Pitfall #49 (P&L compounding) in Layer 2 death spiral scenario Related: Common Pitfall #40 (ghost death spiral), #48 (closingInProgress flag) Impact: No more duplicate notifications, accurate P&L reporting
75 KiB
75 KiB