diff --git a/lib/simple-automation.js b/lib/simple-automation.js index c9877fe..0d382ee 100644 --- a/lib/simple-automation.js +++ b/lib/simple-automation.js @@ -978,6 +978,19 @@ class SimpleAutomation { // Log the successful trade for live analysis panel try { const baseUrl = process.env.INTERNAL_API_URL || 'http://localhost:3000'; + + // Use actual execution data from the trade result + let actualEntryPrice = 0; + if (result.executionPrice) { + actualEntryPrice = result.executionPrice; + } else if (result.price) { + actualEntryPrice = result.price; + } else if (analysis.entry?.price) { + actualEntryPrice = analysis.entry.price; + } else if (analysis.currentPrice) { + actualEntryPrice = analysis.currentPrice; + } + await fetch(`${baseUrl}/api/automation/live-decisions`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, @@ -988,7 +1001,7 @@ class SimpleAutomation { blocked: false, executed: true, confidence: analysis.confidence || 0, - entryPrice: analysis.entry?.price || analysis.currentPrice || 0, + entryPrice: actualEntryPrice, stopLoss: stopLoss, takeProfit: takeProfit, leverage: optimalLeverage, @@ -1252,6 +1265,17 @@ class SimpleAutomation { // 📊 ALSO LOG TO LIVE DECISIONS API FOR DASHBOARD VISIBILITY try { const baseUrl = process.env.INTERNAL_API_URL || 'http://localhost:3000'; + + // Extract better entry price from analysis + let entryPrice = 0; + if (analysis.entry?.price) { + entryPrice = analysis.entry.price; + } else if (analysis.currentPrice) { + entryPrice = analysis.currentPrice; + } else if (analysis.entry && typeof analysis.entry === 'number') { + entryPrice = analysis.entry; + } + await fetch(`${baseUrl}/api/automation/live-decisions`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, @@ -1262,7 +1286,7 @@ class SimpleAutomation { blocked: !decisionContext.willExecute, executed: decisionContext.willExecute, confidence: decisionData.confidence, - entryPrice: decisionData.aiLevels.entry || 0, + entryPrice: entryPrice, stopLoss: decisionData.aiLevels.stopLoss, takeProfit: decisionData.aiLevels.takeProfit, reasoning: decisionData.reasoning, @@ -1271,7 +1295,7 @@ class SimpleAutomation { learningDecisionId: decisionId }) }); - console.log(`📊 AI Decision logged to live-decisions API: ${decisionData.decision}`); + console.log(`📊 AI Decision logged to live-decisions API: ${decisionData.decision} with entry: $${entryPrice}`); } catch (apiError) { console.warn('⚠️ Failed to log decision to live-decisions API:', apiError.message); } diff --git a/prisma/prisma/dev.db b/prisma/prisma/dev.db index f5be870..8dabb7a 100644 Binary files a/prisma/prisma/dev.db and b/prisma/prisma/dev.db differ