diff --git a/.env b/.env index 4763b71..6840adf 100644 --- a/.env +++ b/.env @@ -390,7 +390,7 @@ NEW_RELIC_LICENSE_KEY= USE_TRAILING_STOP=true TRAILING_STOP_PERCENT=0.5 TRAILING_STOP_ACTIVATION=0.4 -MIN_SIGNAL_QUALITY_SCORE=81 +MIN_SIGNAL_QUALITY_SCORE=91 SOLANA_ENABLED=true SOLANA_POSITION_SIZE=100 SOLANA_LEVERAGE=15 diff --git a/app/api/settings/route.ts b/app/api/settings/route.ts index cf7eab4..5124eac 100644 --- a/app/api/settings/route.ts +++ b/app/api/settings/route.ts @@ -52,10 +52,13 @@ function updateEnvFile(updates: Record) { fs.writeFileSync(ENV_FILE_PATH, content, 'utf-8') - // Also update in-memory environment so running process sees new values immediately + // Note: Changes to .env require container restart to take full effect + // In-memory updates below are temporary and may not persist across all modules Object.entries(updates).forEach(([key, value]) => { - process.env[key] = value + process.env[key] = value.toString() }) + + console.log('⚠️ Settings updated in .env file. Container restart recommended for all changes to take effect.') return true } catch (error) { console.error('Failed to write .env file:', error) diff --git a/lib/trading/position-manager.ts b/lib/trading/position-manager.ts index 148f445..b2a6f78 100644 --- a/lib/trading/position-manager.ts +++ b/lib/trading/position-manager.ts @@ -547,6 +547,13 @@ export class PositionManager { trade: ActiveTrade, currentPrice: number ): Promise { + // CRITICAL FIX (Nov 23, 2025): Check if trade still in monitoring + // Prevents duplicate processing when async operations remove trade during loop + if (!this.activeTrades.has(trade.id)) { + console.log(`⏭️ Skipping ${trade.symbol} - already removed from monitoring`) + return + } + // CRITICAL: Update lastPrice FIRST so /status always shows current price // (even if function returns early due to position checks) trade.lastPrice = currentPrice