diff --git a/lib/trading/position-manager.ts b/lib/trading/position-manager.ts index 99faaa5..148f445 100644 --- a/lib/trading/position-manager.ts +++ b/lib/trading/position-manager.ts @@ -1477,7 +1477,7 @@ export class PositionManager { // LAYER 2: Death spiral detector (Nov 15, 2025) // If we've failed 20+ times, check Drift API to see if it's a ghost position - if (trade.priceCheckCount > 20) { + if (trade.priceCheckCount > 20 && !trade.closingInProgress) { try { const driftService = getDriftService() const marketConfig = getMarketConfig(trade.symbol) @@ -1487,6 +1487,11 @@ export class PositionManager { if (!position || Math.abs(position.size) < 0.01) { console.log(`🔴 LAYER 2: Ghost detected after ${trade.priceCheckCount} failures`) console.log(` Drift shows position closed/missing - removing from monitoring`) + + // CRITICAL: Mark as closing to prevent duplicate processing + trade.closingInProgress = true + trade.closeConfirmedAt = Date.now() + await this.handleExternalClosure(trade, 'Layer 2: Ghost detected via Drift API') return } else {