Files
trading_bot_v3/app/api/automation/learning-status/route.js
mindesbunister d5bf485e72 fix: Complete automation v2 page runtime error fixes
- Fixed ES modules error by converting automation-with-learning-v2.js to pure ES6
- Fixed singleton pattern in automation-singleton.js for proper async handling
- Fixed EnhancedAILearningPanel to handle recommendation objects correctly
- Updated API routes to use correct import paths (../../../../lib/)
- Created proper db.js utility with ES6 exports
- Fixed simplified-stop-loss-learner imports and exports

 Automation v2 page now loads without errors
 AI learning system fully integrated and operational
 Learning status API working with detailed reports
 Recommendation rendering fixed for object structure
2025-07-27 12:38:32 +02:00

72 lines
2.3 KiB
JavaScript

// API route to get detailed learning system status and visibility
import { NextResponse } from 'next/server';
// Import the automation instance to get learning status
async function getAutomationInstance() {
try {
// Import the singleton automation instance
const { getAutomationInstance } = await import('../../../../lib/automation-singleton.js');
return getAutomationInstance();
} catch (error) {
console.error('❌ Could not get automation instance:', error);
return null;
}
}
export async function GET() {
try {
const automation = await getAutomationInstance();
if (!automation) {
return NextResponse.json({
success: false,
message: 'Automation instance not available'
}, { status: 503 });
}
// Check if automation has learning capabilities
if (typeof automation.getLearningStatus !== 'function') {
return NextResponse.json({
success: true,
learningSystem: {
enabled: false,
message: 'Basic automation running - learning system not integrated',
recommendation: 'Restart automation to enable AI learning system'
}
});
}
// Get detailed learning status
const learningStatus = await automation.getLearningStatus();
const automationStatus = automation.getStatus();
return NextResponse.json({
success: true,
learningSystem: {
...learningStatus,
automationRunning: automationStatus.isActive || automationStatus.isRunning,
totalCycles: automationStatus.totalCycles || automationStatus.stats?.totalCycles || 0,
totalTrades: automationStatus.totalTrades || automationStatus.stats?.totalTrades || 0
},
visibility: {
decisionTrackingActive: learningStatus.activeDecisions > 0,
learningDatabaseConnected: learningStatus.enabled,
aiEnhancementsActive: learningStatus.learningActive,
lastUpdateTime: new Date().toISOString()
}
});
} catch (error) {
console.error('❌ Error getting learning system status:', error);
return NextResponse.json({
success: false,
error: error.message,
learningSystem: {
enabled: false,
error: 'Failed to retrieve learning status'
}
}, { status: 500 });
}
}