feat: integrate AI learning system with trading automation
- AutomationWithLearning class with decision recording and outcome assessment - Enhanced API endpoints with learning status visibility - Singleton automation manager for seamless learning system integration - EnhancedAILearningPanel component for real-time learning visibility - Learning-enhanced trade execution with AI adjustments to SL/TP - Automatic decision tracking and outcome-based learning Key Features: - Records trading decisions before execution - Enhances analysis with learned patterns - Tracks trade outcomes for continuous improvement - Provides full visibility into AI decision-making process - Integrates SimplifiedStopLossLearner with real trading flow - Whether learning system is active - How many decisions are being tracked - Real-time learning statistics and insights - AI enhancements applied to trading decisions
This commit is contained in:
71
app/api/automation/learning-status/route.js
Normal file
71
app/api/automation/learning-status/route.js
Normal file
@@ -0,0 +1,71 @@
|
||||
// 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.isRunning,
|
||||
totalCycles: automationStatus.stats.totalCycles,
|
||||
totalTrades: automationStatus.stats.totalTrades
|
||||
},
|
||||
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 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user