Files
trading_bot_v3/debug-pnl.js
mindesbunister 55cea00e5e 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.
2025-07-20 22:32:16 +02:00

26 lines
831 B
JavaScript

// Debug P&L calculation
const currentPrice = 175.82
// Example trade from database
const trade = {
side: 'BUY',
amount: 2.04,
price: 100.3703837088441,
status: 'COMPLETED'
}
console.log('=== P&L CALCULATION DEBUG ===')
console.log(`Trade: ${trade.side} ${trade.amount} @ $${trade.price}`)
console.log(`Current Price: $${currentPrice}`)
console.log(`Price Difference: $${currentPrice - trade.price}`)
console.log(`Expected P&L: $${(currentPrice - trade.price) * trade.amount}`)
// Check if logic is working
const priceChange = trade.side === 'BUY' ?
(currentPrice - trade.price) :
(trade.price - currentPrice)
const realizedPnL = trade.status === 'COMPLETED' ? priceChange * trade.amount : null
console.log(`Calculated P&L: $${realizedPnL}`)
console.log(`Should be profitable: ${realizedPnL > 0 ? 'YES' : 'NO'}`)