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:
mindesbunister
2025-07-29 18:04:27 +02:00
parent 158cd1741b
commit b930f02362
4 changed files with 124 additions and 16 deletions

View File

@@ -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;