Files
trading_bot_v3/test-trading-history.js
mindesbunister b91d35ad60 Fix timeframe selection bug and syntax errors
- Fixed critical timeframe mapping bug where '4h' was interpreted as '4 minutes'
- Now prioritizes minute values: '4h' -> ['240', '240m', '4h', '4H']
- Added fallback mechanism to enter exact minutes (240) in custom interval input
- Fixed multiple syntax errors in tradingview-automation.ts:
  * Missing closing parentheses in console.log statements
  * Missing parentheses in writeFile and JSON.parse calls
  * Fixed import statements for fs and path modules
  * Added missing utility methods (fileExists, markCaptchaDetected, etc.)
- Enhanced timeframe selection with comprehensive hour mappings (1h, 2h, 4h, 6h, 12h)
- Added detailed logging for debugging timeframe selection
- Application now builds successfully without syntax errors
- Interval selection should work correctly for all common timeframes

Key improvements:
 4h chart selection now works correctly (240 minutes, not 4 minutes)
 All TypeScript compilation errors resolved
 Enhanced debugging output for timeframe mapping
 Robust fallback mechanisms for interval selection
 Docker integration and manual CAPTCHA handling maintained
2025-07-13 13:57:35 +02:00

56 lines
2.1 KiB
JavaScript

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()