- Fix position-history API case sensitivity for WIN/LOSS outcomes - Update trade filtering to properly distinguish real vs simulation trades - Correct database record for real trade (6.13 profit, 100% win rate) - ai-learning-dashboard.js: Comprehensive AI intelligence report - analyze-learning-progress.js: Learning system progress analysis - analyze-decision-patterns.js: AI decision pattern analysis - analyze-learning-intelligence.js: Deep learning system insights - test-trade-data.js: Trade data validation and filtering tests - fix-real-trade.js: Utility to correct trade classifications - Dashboard now shows 1 real trade (previously 0) - 100% win rate with .13 total P&L - 9,767+ AI learning records properly separated from real trades - Real-time trading performance data vs analysis-only data Result: AI Learning System dashboard displays accurate real trading data
81 lines
2.5 KiB
JavaScript
81 lines
2.5 KiB
JavaScript
const { PrismaClient } = require('@prisma/client');
|
|
|
|
async function testTradeData() {
|
|
const prisma = new PrismaClient();
|
|
|
|
try {
|
|
console.log('🔍 Testing trade data queries...\n');
|
|
|
|
// Get all completed trades with profit/outcome
|
|
const allTrades = await prisma.trades.findMany({
|
|
where: {
|
|
status: 'COMPLETED',
|
|
profit: { not: null },
|
|
outcome: { not: null }
|
|
},
|
|
select: {
|
|
id: true,
|
|
tradingMode: true,
|
|
driftTxId: true,
|
|
profit: true,
|
|
outcome: true,
|
|
symbol: true
|
|
},
|
|
orderBy: { createdAt: 'desc' }
|
|
});
|
|
|
|
console.log(`📊 Found ${allTrades.length} completed trades with profit/outcome:`);
|
|
|
|
allTrades.forEach((trade, i) => {
|
|
console.log(`${i + 1}. ${trade.symbol} - ${trade.outcome}`);
|
|
console.log(` Mode: ${trade.tradingMode}`);
|
|
console.log(` TxId: ${trade.driftTxId}`);
|
|
console.log(` Profit: $${trade.profit}`);
|
|
|
|
// Apply the same filtering logic as the API
|
|
let isSimulation = false;
|
|
|
|
if (trade.driftTxId && trade.driftTxId.startsWith('SIM_')) {
|
|
isSimulation = true;
|
|
console.log(` 🚫 EXCLUDED: Simulation TxId`);
|
|
} else if (trade.tradingMode === 'SIMULATION') {
|
|
isSimulation = true;
|
|
console.log(` 🚫 EXCLUDED: Simulation Mode`);
|
|
} else {
|
|
console.log(` ✅ INCLUDED: Real trade`);
|
|
}
|
|
|
|
console.log('');
|
|
});
|
|
|
|
// Count real trades
|
|
const realTrades = allTrades.filter(trade => {
|
|
if (trade.driftTxId && trade.driftTxId.startsWith('SIM_')) return false;
|
|
if (trade.tradingMode === 'SIMULATION') return false;
|
|
return true;
|
|
});
|
|
|
|
console.log(`📈 Summary: ${realTrades.length} real trades out of ${allTrades.length} total`);
|
|
|
|
if (realTrades.length > 0) {
|
|
console.log('\n🎯 Real Trade Statistics:');
|
|
realTrades.forEach(trade => {
|
|
console.log(` ${trade.symbol}: ${trade.outcome} ($${trade.profit})`);
|
|
});
|
|
|
|
const wins = realTrades.filter(t => t.outcome.toUpperCase() === 'WIN');
|
|
const totalPnl = realTrades.reduce((sum, t) => sum + t.profit, 0);
|
|
|
|
console.log(`\n📊 Stats: ${wins.length} wins / ${realTrades.length} total = ${(wins.length/realTrades.length*100).toFixed(1)}% win rate`);
|
|
console.log(`💰 Total P&L: $${totalPnl.toFixed(2)}`);
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('❌ Error:', error.message);
|
|
} finally {
|
|
await prisma.$disconnect();
|
|
}
|
|
}
|
|
|
|
testTradeData();
|