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:
@@ -1,26 +1,52 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { simpleAutomation } from '@/lib/simple-automation';
|
||||
|
||||
// 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);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(request) {
|
||||
try {
|
||||
const config = await request.json();
|
||||
|
||||
console.log('🚀 AUTOMATION START: Received config:', JSON.stringify(config, null, 2));
|
||||
console.log('🧠 LEARNING SYSTEM: Attempting to start with AI learning integration');
|
||||
|
||||
const result = await simpleAutomation.start(config);
|
||||
const automation = await getAutomationInstance();
|
||||
const result = await automation.start(config);
|
||||
|
||||
// Add learning system status to response
|
||||
const response = {
|
||||
...result,
|
||||
learningSystem: {
|
||||
integrated: typeof automation.getLearningStatus === 'function',
|
||||
type: automation.constructor.name
|
||||
}
|
||||
};
|
||||
|
||||
if (result.success) {
|
||||
return NextResponse.json(result);
|
||||
console.log('✅ AUTOMATION STARTED:', response.learningSystem.integrated ? 'With AI Learning' : 'Basic Mode');
|
||||
return NextResponse.json(response);
|
||||
} else {
|
||||
return NextResponse.json(result, { status: 400 });
|
||||
return NextResponse.json(response, { status: 400 });
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Start automation error:', error);
|
||||
console.error('❌ Start automation error:', error);
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: 'Internal server error',
|
||||
message: error.message
|
||||
message: error.message,
|
||||
learningSystem: {
|
||||
integrated: false,
|
||||
error: 'Failed to initialize'
|
||||
}
|
||||
}, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user