fix: Resolve win rate and P&L discrepancies between Status and AI Learning sections

- 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.
This commit is contained in:
mindesbunister
2025-07-21 12:56:14 +02:00
parent aae715dd07
commit d7a1b96a80
9 changed files with 1454 additions and 75 deletions

47
remove-demo-trades.js Normal file
View File

@@ -0,0 +1,47 @@
const { PrismaClient } = require('@prisma/client')
const prisma = new PrismaClient()
async function removeDemoTrades() {
try {
console.log('🧹 Removing demo trades...')
// Remove demo trades
const deletedTrades = await prisma.trade.deleteMany({
where: {
userId: 'demo-user',
tradingMode: 'SIMULATION',
isAutomated: true
}
})
console.log(`✅ Removed ${deletedTrades.count} demo trades`)
// Optionally remove demo user if no other data
const remainingUserData = await prisma.trade.count({
where: { userId: 'demo-user' }
})
if (remainingUserData === 0) {
await prisma.user.delete({
where: { id: 'demo-user' }
})
console.log('✅ Removed demo user (no remaining data)')
} else {
console.log(` Demo user kept (has ${remainingUserData} other records)`)
}
console.log('🎉 Demo data cleanup completed!')
} catch (error) {
console.error('❌ Error removing demo trades:', error)
} finally {
await prisma.$disconnect()
}
}
if (require.main === module) {
removeDemoTrades()
}
module.exports = { removeDemoTrades }