Fixed position size calculation: 00 investment now shows 00 position (was 04.76) Fixed token amount display: Now shows correct tokens (~0.996) for 00 investment (was 2.04) Corrected API route: /api/automation/analysis-details now returns 200 instead of 405 Technical changes: - Updated route calculation logic: tradingAmount / trade.price for correct token amounts - Fixed displayPositionSize to show intended investment amount - Used Docker Compose v2 for container management - Resolved Next.js module export issues The API now correctly displays trade details matching user investment intentions.
146 lines
5.8 KiB
JavaScript
146 lines
5.8 KiB
JavaScript
const { PrismaClient } = require('@prisma/client');
|
|
const prisma = new PrismaClient();
|
|
|
|
// Test the automation insights functionality
|
|
async function testAutomationInsights() {
|
|
try {
|
|
console.log('🧠 Testing Automation Insights for Manual Analysis Enhancement...\n');
|
|
|
|
const targetSymbol = 'SOLUSD';
|
|
|
|
// Get recent automation sessions for context
|
|
const sessions = await prisma.automationSession.findMany({
|
|
where: {
|
|
userId: 'default-user',
|
|
symbol: targetSymbol,
|
|
lastAnalysisData: { not: null }
|
|
},
|
|
orderBy: { createdAt: 'desc' },
|
|
take: 3
|
|
});
|
|
|
|
// Get top performing trades for pattern recognition
|
|
const successfulTrades = await prisma.trade.findMany({
|
|
where: {
|
|
userId: 'default-user',
|
|
symbol: targetSymbol,
|
|
status: 'COMPLETED',
|
|
profit: { gt: 0 }
|
|
},
|
|
orderBy: { profit: 'desc' },
|
|
take: 5
|
|
});
|
|
|
|
// Get recent market context
|
|
const allTrades = await prisma.trade.findMany({
|
|
where: {
|
|
userId: 'default-user',
|
|
symbol: targetSymbol,
|
|
status: 'COMPLETED'
|
|
},
|
|
orderBy: { createdAt: 'desc' },
|
|
take: 10
|
|
});
|
|
|
|
const recentPnL = allTrades.reduce((sum, t) => sum + (t.profit || 0), 0);
|
|
const winningTrades = allTrades.filter(t => (t.profit || 0) > 0);
|
|
const winRate = allTrades.length > 0 ? (winningTrades.length / allTrades.length * 100) : 0;
|
|
|
|
const automationContext = {
|
|
multiTimeframeSignals: sessions.map(s => ({
|
|
timeframe: s.timeframe,
|
|
decision: s.lastAnalysisData?.decision,
|
|
confidence: s.lastAnalysisData?.confidence,
|
|
sentiment: s.lastAnalysisData?.sentiment,
|
|
winRate: s.winRate,
|
|
totalPnL: s.totalPnL,
|
|
totalTrades: s.totalTrades
|
|
})),
|
|
topPatterns: successfulTrades.map(t => ({
|
|
side: t.side,
|
|
profit: t.profit,
|
|
confidence: t.confidence,
|
|
entryPrice: t.price,
|
|
exitPrice: t.exitPrice,
|
|
profitPercent: t.exitPrice ? ((t.exitPrice - t.price) / t.price * 100).toFixed(2) : null
|
|
})),
|
|
marketContext: {
|
|
recentPnL,
|
|
winRate: winRate.toFixed(1),
|
|
totalTrades: allTrades.length,
|
|
avgProfit: allTrades.length > 0 ? (recentPnL / allTrades.length).toFixed(2) : 0,
|
|
trend: sessions.length > 0 ? sessions[0].lastAnalysisData?.sentiment : 'NEUTRAL'
|
|
}
|
|
};
|
|
|
|
// Generate enhanced recommendation
|
|
function generateEnhancedRecommendation(automationContext) {
|
|
if (!automationContext) return null;
|
|
|
|
const { multiTimeframeSignals, topPatterns, marketContext } = automationContext;
|
|
|
|
// Multi-timeframe consensus
|
|
const signals = multiTimeframeSignals.filter(s => s.decision);
|
|
const bullishSignals = signals.filter(s => s.decision === 'BUY').length;
|
|
const bearishSignals = signals.filter(s => s.decision === 'SELL').length;
|
|
|
|
// Pattern strength
|
|
const avgWinRate = signals.length > 0 ?
|
|
signals.reduce((sum, s) => sum + (s.winRate || 0), 0) / signals.length : 0;
|
|
|
|
// Profitability insights
|
|
const avgProfit = topPatterns.length > 0 ?
|
|
topPatterns.reduce((sum, p) => sum + Number(p.profitPercent || 0), 0) / topPatterns.length : 0;
|
|
|
|
let recommendation = '🤖 AUTOMATION-ENHANCED: ';
|
|
|
|
if (bullishSignals > bearishSignals) {
|
|
recommendation += `BULLISH CONSENSUS (${bullishSignals}/${signals.length} timeframes)`;
|
|
if (avgWinRate > 60) recommendation += ` ✅ Strong pattern (${avgWinRate.toFixed(1)}% win rate)`;
|
|
if (avgProfit > 3) recommendation += ` 💰 High profit potential (~${avgProfit.toFixed(1)}%)`;
|
|
} else if (bearishSignals > bullishSignals) {
|
|
recommendation += `BEARISH CONSENSUS (${bearishSignals}/${signals.length} timeframes)`;
|
|
} else {
|
|
recommendation += 'NEUTRAL - Mixed signals across timeframes';
|
|
}
|
|
|
|
return recommendation;
|
|
}
|
|
|
|
const automationInsights = {
|
|
multiTimeframeConsensus: automationContext.multiTimeframeSignals.length > 0 ?
|
|
automationContext.multiTimeframeSignals[0].decision : null,
|
|
avgConfidence: automationContext.multiTimeframeSignals.length > 0 ?
|
|
(automationContext.multiTimeframeSignals.reduce((sum, s) => sum + (s.confidence || 0), 0) / automationContext.multiTimeframeSignals.length).toFixed(1) : null,
|
|
marketTrend: automationContext.marketContext.trend,
|
|
winRate: automationContext.marketContext.winRate + '%',
|
|
profitablePattern: automationContext.topPatterns.length > 0 ?
|
|
`${automationContext.topPatterns[0].side} signals with avg ${automationContext.topPatterns.reduce((sum, p) => sum + Number(p.profitPercent || 0), 0) / automationContext.topPatterns.length}% profit` : null,
|
|
recommendation: generateEnhancedRecommendation(automationContext)
|
|
};
|
|
|
|
console.log('🎯 ENHANCED MANUAL ANALYSIS INSIGHTS:');
|
|
console.log('=====================================');
|
|
console.log('Multi-timeframe Consensus:', automationInsights.multiTimeframeConsensus);
|
|
console.log('Average Confidence:', automationInsights.avgConfidence + '%');
|
|
console.log('Market Trend:', automationInsights.marketTrend);
|
|
console.log('Win Rate:', automationInsights.winRate);
|
|
console.log('Profitable Pattern:', automationInsights.profitablePattern);
|
|
console.log('Recommendation:', automationInsights.recommendation);
|
|
|
|
console.log('\n📊 RAW DATA:');
|
|
console.log('============');
|
|
console.log('Timeframe Signals:', automationContext.multiTimeframeSignals);
|
|
console.log('Top Patterns:', automationContext.topPatterns.slice(0, 3));
|
|
console.log('Market Context:', automationContext.marketContext);
|
|
|
|
await prisma.$disconnect();
|
|
console.log('\n✅ Test completed successfully!');
|
|
} catch (error) {
|
|
console.error('❌ Test failed:', error);
|
|
await prisma.$disconnect();
|
|
}
|
|
}
|
|
|
|
testAutomationInsights();
|