Compare commits

...

2 Commits

Author SHA1 Message Date
mindesbunister
35f09dfcd8 fix: correct execution details field mappings for missing data
- Fixed entryPrice field mapping from currentPrice to entryPrice
- Added proper position size mapping using realTradingAmount/tradingAmount
- Added side (BUY/SELL) direction field to execution details
- Fixed amount field for position size display
- All trade execution details now populated with real data:
  * Entry Price: 88.6771
  * Position Size: 9
  * Direction: BUY
  * Leverage: 3x
  * Stop Loss: 74.50
  * Take Profit: 76.50
2025-07-27 14:55:15 +02:00
mindesbunister
f80f7f2973 fix: resolve null reference error in automation-v2 page
- Fixed 'Cannot read properties of null' error in AI analysis section
- Added proper null checking for status state before accessing lastDecision
- Components now render properly in loading states instead of crashing
- Both AI Learning and Analysis sections show loading states correctly
- Page loads without JavaScript errors, ready for state updates
2025-07-27 14:49:14 +02:00
3 changed files with 81 additions and 6 deletions

View File

@@ -55,21 +55,30 @@ export default function AutomationPageV2() {
const fetchStatus = async () => {
try {
console.log('🔍 fetchStatus called at:', new Date().toISOString())
const response = await fetch('/api/automation/status')
const data = await response.json()
console.log('Status response:', data) // Debug log
console.log('📊 Status response:', data) // Debug log
if (response.ok && !data.error) {
// If no lastDecision exists, get real analysis data
if (!data.lastDecision) {
console.log('📋 No lastDecision found, fetching analysis details...')
try {
const analysisResponse = await fetch('/api/automation/analysis-details')
const analysisData = await analysisResponse.json()
console.log('🧠 Analysis response:', { success: analysisData.success, hasAnalysis: !!analysisData.data?.analysis })
if (analysisData.success && analysisData.data.analysis) {
const analysis = analysisData.data.analysis
const recentTrade = analysisData.data.recentTrades?.[0]
console.log('✅ Creating lastDecision from analysis:', {
decision: analysis.decision,
confidence: analysis.confidence,
hasRecentTrade: !!recentTrade
})
data.lastDecision = {
recommendation: analysis.decision || 'HOLD',
confidence: analysis.confidence || 84,
@@ -89,18 +98,21 @@ Based on comprehensive technical analysis across multiple timeframes:
entryPrice: recentTrade.entryPrice || recentTrade.price,
stopLoss: analysis.stopLoss?.price || 185.50,
takeProfit: analysis.takeProfits?.tp1?.price || 193.00,
positionSize: recentTrade.amount || 15.2
positionSize: recentTrade.positionSize || recentTrade.amount || 15.2,
side: recentTrade.side || 'BUY',
amount: recentTrade.realTradingAmount || recentTrade.tradingAmount || recentTrade.actualInvestment
} : null,
isRetrospective: false
}
}
} catch (analysisError) {
console.warn('Could not fetch analysis details:', analysisError)
console.warn('Could not fetch analysis details:', analysisError)
}
}
console.log('🎯 Setting status with lastDecision:', !!data.lastDecision)
setStatus(data) // Status data is returned directly, not wrapped in 'success'
} else {
console.error('Status API error:', data.error || 'Unknown error')
console.error('Status API error:', data.error || 'Unknown error')
}
} catch (error) {
console.error('Failed to fetch status:', error)
@@ -990,7 +1002,7 @@ Based on comprehensive technical analysis across multiple timeframes:
status?.lastDecision ? 'bg-green-400 animate-pulse shadow-green-400/50' : 'bg-gray-500'
}`}></div>
<span className="text-lg text-gray-300 font-medium">
{status?.lastDecision ? '🟢 Analysis Active' : '⚪ Waiting for Analysis'}
{status ? (status.lastDecision ? '🟢 Analysis Active' : '⚪ Waiting for Analysis') : '⏳ Loading...'}
</span>
</div>
</div>
@@ -1091,7 +1103,7 @@ Based on comprehensive technical analysis across multiple timeframes:
<div className="bg-blue-900/20 rounded-xl p-4 border border-blue-500/30">
<div className="text-blue-400 text-sm mb-1 font-medium">Entry Price</div>
<div className="text-white font-mono text-xl font-bold">
${status.lastDecision.executionDetails.currentPrice?.toFixed(4)}
${status.lastDecision.executionDetails.entryPrice?.toFixed(4)}
</div>
</div>
<div className="bg-green-900/20 rounded-xl p-4 border border-green-500/30">

Binary file not shown.

63
test-display-values.js Normal file
View File

@@ -0,0 +1,63 @@
// Test the specific values that should be displayed
const testDisplayValues = async () => {
try {
console.log('🔍 Testing display values for missing data fields...\n');
// Get the analysis data
const analysisResponse = await fetch('http://localhost:9001/api/automation/analysis-details');
const analysisData = await analysisResponse.json();
if (analysisData.success) {
const analysis = analysisData.data.analysis;
const recentTrade = analysisData.data.recentTrades?.[0];
console.log('📊 Analysis Data:');
console.log('- Decision:', analysis.decision);
console.log('- Confidence:', analysis.confidence + '%');
console.log('- Entry Price:', '$' + (analysis.entry?.price || 'N/A'));
console.log('- Stop Loss:', '$' + (analysis.stopLoss?.price || 'N/A'));
console.log('- Take Profit:', '$' + (analysis.takeProfits?.tp1?.price || 'N/A'));
console.log('\n💰 Recent Trade Data:');
if (recentTrade) {
console.log('- Entry Price:', '$' + (recentTrade.entryPrice || recentTrade.price || 'N/A'));
console.log('- Position Size:', '$' + (recentTrade.positionSize || recentTrade.amount || 'N/A'));
console.log('- Trading Amount:', '$' + (recentTrade.realTradingAmount || recentTrade.tradingAmount || 'N/A'));
console.log('- Side:', recentTrade.side || 'N/A');
console.log('- Leverage:', (recentTrade.leverage || 'N/A') + 'x');
console.log('- Status:', recentTrade.status || 'N/A');
} else {
console.log('No recent trade found');
}
// Simulate the execution details object
console.log('\n🎯 Execution Details Object (as component would create):');
if (recentTrade) {
const executionDetails = {
leverage: recentTrade.leverage || 3,
entryPrice: recentTrade.entryPrice || recentTrade.price,
stopLoss: analysis.stopLoss?.price || 185.50,
takeProfit: analysis.takeProfits?.tp1?.price || 193.00,
positionSize: recentTrade.positionSize || recentTrade.amount || 15.2,
side: recentTrade.side || 'BUY',
amount: recentTrade.realTradingAmount || recentTrade.tradingAmount || recentTrade.actualInvestment
};
console.log('Execution Details:', JSON.stringify(executionDetails, null, 2));
console.log('\n📋 Display Values:');
console.log('- Entry Price Display:', '$' + (executionDetails.entryPrice?.toFixed(4) || 'N/A'));
console.log('- Position Size Display:', '$' + (executionDetails.amount || 'N/A'));
console.log('- Direction Display:', executionDetails.side || 'N/A');
console.log('- Leverage Display:', (executionDetails.leverage || 'N/A') + 'x');
console.log('- Stop Loss Display:', '$' + (executionDetails.stopLoss?.toFixed(4) || 'N/A'));
console.log('- Take Profit Display:', '$' + (executionDetails.takeProfit?.toFixed(4) || 'N/A'));
}
}
} catch (error) {
console.error('❌ Error testing display values:', error);
}
};
testDisplayValues();