Fix automated trading display calculations

Fixed position size calculation: 00 investment now shows 00 position (was 04.76)
 Fixed token amount display: Now shows correct tokens (~0.996) for 00 investment (was 2.04)
 Corrected API route: /api/automation/analysis-details now returns 200 instead of 405

Technical changes:
- Updated route calculation logic: tradingAmount / trade.price for correct token amounts
- Fixed displayPositionSize to show intended investment amount
- Used Docker Compose v2 for container management
- Resolved Next.js module export issues

The API now correctly displays trade details matching user investment intentions.
This commit is contained in:
mindesbunister
2025-07-20 22:32:16 +02:00
parent 6ce4f364a9
commit 55cea00e5e
22 changed files with 1180 additions and 189 deletions

119
test-cleanup-improvements.js Executable file
View File

@@ -0,0 +1,119 @@
#!/usr/bin/env node
/**
* Test script to validate the cleanup improvements
* This will simulate the analysis workflow and verify cleanup occurs properly
*/
console.log('🧪 Testing cleanup improvements...')
async function testCleanupWorkflow() {
try {
console.log('\n1⃣ Initial process check...')
await checkProcesses()
console.log('\n2⃣ Running enhanced screenshot analysis...')
const config = {
symbol: 'BTCUSD',
timeframe: '60',
layouts: ['ai'],
analyze: true
}
// Simulate API call
const response = await fetch('http://localhost:3000/api/enhanced-screenshot', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(config)
})
const result = await response.json()
console.log('📊 Analysis result:', {
success: result.success,
sessionId: result.sessionId,
screenshots: result.screenshots?.length || 0,
analysis: !!result.analysis
})
console.log('\n3⃣ Waiting 10 seconds for cleanup to complete...')
await new Promise(resolve => setTimeout(resolve, 10000))
console.log('\n4⃣ Checking processes after cleanup...')
await checkProcesses()
console.log('\n5⃣ Checking system process monitoring endpoint...')
const processResponse = await fetch('http://localhost:3000/api/system/processes')
const processInfo = await processResponse.json()
console.log('📊 Process monitoring:', processInfo)
console.log('\n6⃣ Running manual cleanup if needed...')
const cleanupResponse = await fetch('http://localhost:3000/api/system/processes', {
method: 'POST'
})
const cleanupResult = await cleanupResponse.json()
console.log('🧹 Manual cleanup result:', cleanupResult)
console.log('\n7⃣ Final process check...')
await checkProcesses()
console.log('\n✅ Cleanup test completed!')
} catch (error) {
console.error('❌ Test failed:', error)
process.exit(1)
}
}
async function checkProcesses() {
try {
const { exec } = require('child_process')
const { promisify } = require('util')
const execAsync = promisify(exec)
// Check for chromium processes
try {
const { stdout } = await execAsync('ps aux | grep -E "(chromium|chrome)" | grep -v grep | wc -l')
const processCount = parseInt(stdout.trim()) || 0
console.log(`🔍 Browser processes: ${processCount}`)
if (processCount > 0) {
const { stdout: details } = await execAsync('ps aux | grep -E "(chromium|chrome)" | grep -v grep')
console.log('📋 Process details:')
details.split('\n').forEach((line, index) => {
if (line.trim()) {
const parts = line.split(/\s+/)
const pid = parts[1]
const cpu = parts[2]
const mem = parts[3]
console.log(` ${index + 1}. PID: ${pid}, CPU: ${cpu}%, MEM: ${mem}%`)
}
})
}
} catch (error) {
console.log('✅ No browser processes found')
}
// Check memory usage
try {
const { stdout: memInfo } = await execAsync('free -h | head -2')
console.log('💾 Memory:')
memInfo.split('\n').forEach(line => {
if (line.trim()) console.log(` ${line}`)
})
} catch (error) {
console.log('Warning: Could not get memory info')
}
} catch (error) {
console.error('Error checking processes:', error)
}
}
// Run the test
if (require.main === module) {
testCleanupWorkflow()
}
module.exports = { testCleanupWorkflow, checkProcesses }