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

28
test-api-fix.js Normal file
View File

@@ -0,0 +1,28 @@
const fetch = require('node-fetch')
async function testAPI() {
try {
const response = await fetch('http://localhost:3001/api/automation/analysis-details')
const data = await response.json()
console.log('=== API TEST RESULTS ===')
console.log(`Success: ${data.success}`)
console.log(`Total trades returned: ${data.data?.recentTrades?.length || 0}`)
console.log(`Total P&L: $${data.data?.session?.totalPnL || 0}`)
console.log(`Win Rate: ${((data.data?.session?.successfulTrades || 0) / (data.data?.session?.totalTrades || 1) * 100).toFixed(1)}%`)
console.log('\n=== RECENT TRADES ===')
data.data?.recentTrades?.slice(0, 5).forEach((trade, i) => {
console.log(`Trade ${i + 1}: ${trade.side} ${trade.amount} @ $${trade.price} = $${trade.positionSize} | P&L: $${trade.pnl} | Duration: ${trade.durationText}`)
})
if (data.data?.recentTrades?.length > 5) {
console.log(`... and ${data.data.recentTrades.length - 5} more trades`)
}
} catch (error) {
console.error('API Error:', error.message)
}
}
testAPI()