Files
trading_bot_v3/lib/emergency-automation.ts
mindesbunister 1e4f305657 fix: emergency automation fix - stop runaway trading loops
- Replace automation service with emergency rate-limited version
- Add 5-minute minimum interval between automation starts
- Implement forced Chromium process cleanup on stop
- Backup broken automation service as .broken file
- Emergency service prevents multiple simultaneous automations
- Fixed 1400+ Chromium process accumulation issue
- Tested and confirmed: rate limiting works, processes stay at 0
2025-07-24 20:33:20 +02:00

51 lines
1.3 KiB
TypeScript

class EmergencyAutomation {
private static isRunning = false
private static lastStart = 0
private static readonly MIN_START_INTERVAL = 5 * 60 * 1000 // 5 minutes
static async start(config: any) {
const now = Date.now()
if (now - this.lastStart < this.MIN_START_INTERVAL) {
return {
success: false,
message: `Emergency rate limit: Wait ${Math.ceil((this.MIN_START_INTERVAL - (now - this.lastStart)) / 1000)} seconds`
}
}
if (this.isRunning) {
return { success: false, message: 'Automation already running' }
}
this.isRunning = true
this.lastStart = now
console.log('🛡️ EMERGENCY: Starting with rate limits')
return { success: true, message: 'Emergency safe mode activated' }
}
static async stop() {
this.isRunning = false
console.log('⛔ EMERGENCY: Stopped automation')
return { success: true, message: 'Emergency stop completed' }
}
static getStatus() {
return {
isActive: this.isRunning,
mode: 'EMERGENCY_SAFE',
symbol: 'SOLUSD',
timeframe: '1h',
totalTrades: 0,
successfulTrades: 0,
winRate: 0,
totalPnL: 0,
errorCount: 0,
nextAnalysisIn: 0,
analysisInterval: 3600,
currentCycle: 0
}
}
}
export const emergencyAutomation = EmergencyAutomation