const { driftTradingService } = require('./lib/drift-trading') async function testTradingHistory() { console.log('๐Ÿงช Testing improved trading history functionality...') try { // Test login first console.log('1. Testing login...') const loginResult = await driftTradingService.login() console.log('Login result:', loginResult) if (!loginResult.isLoggedIn) { console.error('โŒ Login failed, cannot test trading history') return } // Test trading history console.log('\n2. Testing trading history...') const tradingHistory = await driftTradingService.getTradingHistory(20) console.log(`\n๐Ÿ“Š Trading History Results:`) console.log(`Found ${tradingHistory.length} trades`) if (tradingHistory.length > 0) { console.log('\n๐Ÿ“‹ Trade Details:') tradingHistory.forEach((trade, index) => { console.log(`${index + 1}. ${trade.symbol} ${trade.side} ${trade.amount} @ $${trade.price.toFixed(2)} | P&L: ${trade.pnl ? `$${trade.pnl.toFixed(2)}` : 'N/A'} | ${trade.executedAt}`) }) // Calculate total P&L const totalPnL = tradingHistory.reduce((sum, trade) => sum + (trade.pnl || 0), 0) console.log(`\n๐Ÿ’ฐ Total P&L: $${totalPnL.toFixed(2)}`) // Count positive and negative trades const positiveTrades = tradingHistory.filter(trade => (trade.pnl || 0) > 0) const negativeTrades = tradingHistory.filter(trade => (trade.pnl || 0) < 0) console.log(`๐Ÿ“ˆ Positive P&L trades: ${positiveTrades.length}`) console.log(`๐Ÿ“‰ Negative P&L trades: ${negativeTrades.length}`) console.log(`โš–๏ธ Zero P&L trades: ${tradingHistory.length - positiveTrades.length - negativeTrades.length}`) } else { console.log('โš ๏ธ No trading history found') console.log('This could mean:') console.log('- No trades have been made on this account') console.log('- Drift APIs are not accessible') console.log('- Account data is not available via public endpoints') } } catch (error) { console.error('โŒ Test failed:', error.message) } } testTradingHistory()