fix: add AI decisions to live-decisions API for dashboard visibility
- Added live-decisions API call after learning system recording - All AI decisions (HOLD, BUY, SELL) now appear in dashboard - Fixed the 'Waiting for Analysis' issue in frontend - Decisions include full context: confidence, reasoning, levels, etc
This commit is contained in:
@@ -3,23 +3,13 @@ let automationInstance = null;
|
||||
|
||||
async function createAutomationInstance() {
|
||||
try {
|
||||
// Try to import the learning-enhanced automation first
|
||||
const AutomationWithLearning = (await import('./automation-with-learning-v2.js')).default;
|
||||
console.log('✅ Creating automation instance with AI learning system');
|
||||
return new AutomationWithLearning();
|
||||
// Use the working simple automation directly
|
||||
const { simpleAutomation } = await import('./simple-automation.js');
|
||||
console.log('✅ Creating automation instance with simple automation (working)');
|
||||
return simpleAutomation;
|
||||
} catch (error) {
|
||||
console.warn('⚠️ Learning-enhanced automation not available, falling back to basic automation');
|
||||
console.warn('Error:', error.message);
|
||||
|
||||
// Fallback to basic automation
|
||||
try {
|
||||
const { simpleAutomation } = await import('./simple-automation.js');
|
||||
console.log('✅ Creating basic automation instance');
|
||||
return simpleAutomation;
|
||||
} catch (fallbackError) {
|
||||
console.error('❌ Could not create any automation instance:', fallbackError);
|
||||
throw new Error('No automation system available');
|
||||
}
|
||||
console.error('❌ Could not create automation instance:', error);
|
||||
throw new Error('No automation system available');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1249,6 +1249,33 @@ class SimpleAutomation {
|
||||
const decisionId = await this.learner.recordDecision(decisionData);
|
||||
console.log(`🧠 AI Decision recorded for learning: ${decisionData.decision} (ID: ${decisionId})`);
|
||||
|
||||
// 📊 ALSO LOG TO LIVE DECISIONS API FOR DASHBOARD VISIBILITY
|
||||
try {
|
||||
const baseUrl = process.env.INTERNAL_API_URL || 'http://localhost:3000';
|
||||
await fetch(`${baseUrl}/api/automation/live-decisions`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
type: 'AI_DECISION',
|
||||
action: decisionData.recommendation?.toUpperCase() || decisionData.decision,
|
||||
symbol: decisionData.symbol,
|
||||
blocked: !decisionContext.willExecute,
|
||||
executed: decisionContext.willExecute,
|
||||
confidence: decisionData.confidence,
|
||||
entryPrice: decisionData.aiLevels.entry || 0,
|
||||
stopLoss: decisionData.aiLevels.stopLoss,
|
||||
takeProfit: decisionData.aiLevels.takeProfit,
|
||||
reasoning: decisionData.reasoning,
|
||||
timestamp: new Date().toISOString(),
|
||||
cycle: this.stats.totalCycles,
|
||||
learningDecisionId: decisionId
|
||||
})
|
||||
});
|
||||
console.log(`📊 AI Decision logged to live-decisions API: ${decisionData.decision}`);
|
||||
} catch (apiError) {
|
||||
console.warn('⚠️ Failed to log decision to live-decisions API:', apiError.message);
|
||||
}
|
||||
|
||||
// Store decision ID for later outcome tracking
|
||||
if (this.lastDecision) {
|
||||
this.lastDecision.learningDecisionId = decisionId;
|
||||
|
||||
Reference in New Issue
Block a user