- Fixed analysis-details API to use stored profit field as fallback when exit prices missing - Updated UI to use Status API data instead of calculating from limited recent trades - Modified AI Learning Status to use real database trade data instead of demo numbers - Enhanced price monitor with automatic trade closing logic for TP/SL hits - Modified automation service to create trades with OPEN status for proper monitoring - Added test scripts for creating OPEN trades and validating monitoring system Key changes: - Status section now shows accurate 50% win rate from complete database - AI Learning Status shows consistent metrics based on real trading performance - Both sections display same correct P&L (8.62) from actual trade results - Real-time price monitor properly detects and tracks OPEN status trades - Fixed trade lifecycle: OPEN → monitoring → COMPLETED when TP/SL hit All trading performance metrics now display consistent, accurate data from the same source.
54 lines
1.6 KiB
JavaScript
54 lines
1.6 KiB
JavaScript
// Create a test open trade to demonstrate real-time monitoring
|
|
const { PrismaClient } = require('@prisma/client')
|
|
|
|
const prisma = new PrismaClient()
|
|
|
|
async function createTestOpenTrade() {
|
|
try {
|
|
const currentPrice = 190.50 // Simulated SOL price
|
|
const stopLoss = currentPrice * 0.98 // 2% below entry
|
|
const takeProfit = currentPrice * 1.06 // 6% above entry
|
|
|
|
const trade = await prisma.trade.create({
|
|
data: {
|
|
userId: 'default-user',
|
|
symbol: 'SOLUSD',
|
|
side: 'BUY',
|
|
amount: 0.5263, // ~$100 position
|
|
price: currentPrice,
|
|
entryPrice: currentPrice,
|
|
status: 'OPEN', // This is the key - OPEN status for monitoring
|
|
stopLoss: stopLoss,
|
|
takeProfit: takeProfit,
|
|
leverage: 1,
|
|
isAutomated: true,
|
|
tradingMode: 'SIMULATION',
|
|
confidence: 85,
|
|
marketSentiment: 'BULLISH',
|
|
timeframe: '1h',
|
|
createdAt: new Date()
|
|
}
|
|
})
|
|
|
|
console.log('✅ Created test open trade:', {
|
|
id: trade.id.slice(-8),
|
|
symbol: trade.symbol,
|
|
side: trade.side,
|
|
entryPrice: trade.entryPrice,
|
|
stopLoss: trade.stopLoss,
|
|
takeProfit: trade.takeProfit,
|
|
status: trade.status
|
|
})
|
|
|
|
console.log('📊 Price monitor should now detect this trade and start monitoring it!')
|
|
console.log('💡 Check the automation page - it should show under "Active Trades Monitor"')
|
|
|
|
} catch (error) {
|
|
console.error('❌ Error creating test trade:', error)
|
|
} finally {
|
|
await prisma.$disconnect()
|
|
}
|
|
}
|
|
|
|
createTestOpenTrade()
|