- 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
84 lines
2.7 KiB
TypeScript
84 lines
2.7 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
import { automationService } from '../../../../lib/automation-service-simple'
|
|
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
console.log('🧪 Testing Automation Service Connection...')
|
|
|
|
// Test configuration
|
|
const testConfig = {
|
|
userId: 'test-user-123',
|
|
mode: 'SIMULATION' as const,
|
|
symbol: 'SOLUSD',
|
|
timeframe: '1h',
|
|
selectedTimeframes: ['1h'],
|
|
tradingAmount: 10, // $10 for simulation
|
|
maxLeverage: 2,
|
|
stopLossPercent: 2,
|
|
takeProfitPercent: 6,
|
|
maxDailyTrades: 5,
|
|
riskPercentage: 1,
|
|
dexProvider: 'DRIFT' as const
|
|
}
|
|
|
|
console.log('📋 Config:', testConfig)
|
|
|
|
// Check for open positions before starting test automation
|
|
console.log('\n🔍 Checking for open positions...')
|
|
try {
|
|
const hasPositions = await automationService.hasOpenPositions();
|
|
if (hasPositions) {
|
|
console.log('⏸️ Test aborted - open positions detected');
|
|
return NextResponse.json({
|
|
success: false,
|
|
error: 'Cannot test automation while positions are open',
|
|
message: 'Please close existing positions before running automation tests'
|
|
}, { status: 400 });
|
|
}
|
|
console.log('✅ No open positions, proceeding with test...')
|
|
} catch (error) {
|
|
console.error('⚠️ Error checking positions, continuing test anyway:', error);
|
|
}
|
|
|
|
// Test starting automation
|
|
console.log('\n🚀 Starting automation...')
|
|
const startResult = await automationService.startAutomation(testConfig)
|
|
console.log('✅ Start result:', startResult)
|
|
|
|
// Test getting status
|
|
console.log('\n📊 Getting status...')
|
|
const status = await automationService.getStatus()
|
|
console.log('✅ Status:', status)
|
|
|
|
// Test getting learning insights
|
|
console.log('\n🧠 Getting learning insights...')
|
|
const insights = await automationService.getLearningInsights(testConfig.userId)
|
|
console.log('✅ Learning insights:', insights)
|
|
|
|
// Test stopping
|
|
console.log('\n🛑 Stopping automation...')
|
|
const stopResult = await automationService.stopAutomation()
|
|
console.log('✅ Stop result:', stopResult)
|
|
|
|
console.log('\n🎉 All automation tests passed!')
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
message: 'Automation service connection test passed!',
|
|
results: {
|
|
startResult,
|
|
status,
|
|
insights,
|
|
stopResult
|
|
}
|
|
})
|
|
|
|
} catch (error) {
|
|
console.error('❌ Test failed:', error)
|
|
return NextResponse.json({
|
|
success: false,
|
|
error: error instanceof Error ? error.message : 'Unknown error'
|
|
}, { status: 500 })
|
|
}
|
|
}
|