fix: Enable virtual trading & AI learning - UI improvements and setup guide

- Add comprehensive setup guide (VIRTUAL_TRADING_SETUP_GUIDE.md)
- Improve UI to clearly show required steps for AI learning
- Make auto-execute toggle always visible with clear instructions
- Add blue info panel explaining the learning setup process
- User can now easily enable: Continuous Learning + Auto-Execute
- Virtual trades will execute automatically and AI will learn from outcomes

Resolves issue: AI analyzing without learning due to missing virtual trade execution
This commit is contained in:
mindesbunister
2025-08-05 10:23:12 +02:00
parent 53e8faf903
commit d7de856ce0
15 changed files with 2474 additions and 1481 deletions

View File

@@ -1,46 +1,44 @@
// Import singleton automation manager
async function getAutomationInstance() {
try {
const { getAutomationInstance } = await import('../../../../lib/automation-singleton.js');
return await getAutomationInstance();
} catch (error) {
console.error('❌ Could not get automation instance:', error);
return null;
}
}
import { NextResponse } from 'next/server'
import { automationService } from '@/lib/automation-service-simple'
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
export async function POST() {
try {
console.log('🛑 AUTOMATION STOP: Request received');
console.log('🛑 Stop automation request received')
const automation = await getAutomationInstance();
let result = { success: false, message: 'No automation instance available' };
// Stop the automation service
console.log('🛑 Calling automationService.stopAutomation()')
const success = await automationService.stopAutomation()
console.log('🛑 Stop automation result:', success)
if (automation) {
result = await automation.stop();
// Check if learning system was active
if (typeof automation.getLearningStatus === 'function') {
const learningStatus = await automation.getLearningStatus();
console.log('🧠 LEARNING SYSTEM: Stopped with', learningStatus.activeDecisions, 'active decisions');
// Also update all active automation sessions in database to INACTIVE
console.log('🛑 Updating database sessions to STOPPED')
const updateResult = await prisma.automationSession.updateMany({
where: {
status: 'ACTIVE'
},
data: {
status: 'STOPPED', // Use STOPPED instead of INACTIVE for clarity
updatedAt: new Date()
}
}
})
// Additional cleanup
try {
const { execSync } = require('child_process');
execSync('pkill -f "chrome|chromium" 2>/dev/null || true');
console.log('✅ Additional cleanup completed');
} catch (cleanupError) {
console.error('Cleanup error:', cleanupError.message);
console.log('🛑 Database update result:', updateResult)
console.log('🛑 All automation sessions marked as STOPPED in database')
if (success) {
return NextResponse.json({ success: true, message: 'Automation stopped successfully' })
} else {
return NextResponse.json({ success: false, error: 'Failed to stop automation' }, { status: 500 })
}
return Response.json(result);
} catch (error) {
console.error('Stop automation error:', error);
return Response.json({
success: false,
message: error.message
}, { status: 500 });
console.error('Stop automation error:', error)
return NextResponse.json({
success: false,
error: 'Internal server error',
message: error.message
}, { status: 500 })
}
}