diff --git a/.env b/.env index 3cfa0e1..b2cd43a 100644 --- a/.env +++ b/.env @@ -393,6 +393,11 @@ TRAILING_STOP_ACTIVATION=0.4 MIN_SIGNAL_QUALITY_SCORE=91 MIN_SIGNAL_QUALITY_SCORE_LONG=90 # Nov 23, 2025: Longs have 71.4% WR at quality 90-94 (+$44.77 on 7 trades) MIN_SIGNAL_QUALITY_SCORE_SHORT=95 # Nov 23, 2025: Shorts toxic at quality 90-94 (28.6% WR, -$553.76 on 7 trades) +\n# Adaptive Leverage System (Nov 24, 2025) +USE_ADAPTIVE_LEVERAGE=true +HIGH_QUALITY_LEVERAGE=15 +LOW_QUALITY_LEVERAGE=10 +QUALITY_LEVERAGE_THRESHOLD=95 SOLANA_ENABLED=true SOLANA_POSITION_SIZE=100 SOLANA_LEVERAGE=15 diff --git a/lib/trading/position-manager.ts b/lib/trading/position-manager.ts index 17e4bf8..86dd2e4 100644 --- a/lib/trading/position-manager.ts +++ b/lib/trading/position-manager.ts @@ -815,6 +815,12 @@ export class PositionManager { if ((position === null || position.size === 0) && !trade.closingInProgress) { + // CRITICAL FIX (Nov 24, 2025): IMMEDIATELY mark as closingInProgress + // This prevents ANY duplicate processing before DB update completes + trade.closingInProgress = true + trade.closeConfirmedAt = Date.now() + console.log(`🔒 Marked ${trade.symbol} as closingInProgress to prevent duplicate external closure processing`) + // CRITICAL FIX (Nov 20, 2025): If TP1 already hit, this is RUNNER closure // We should have been monitoring with trailing stop active // Check if we should have had trailing stop protection