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:
25
debug-pnl.js
Normal file
25
debug-pnl.js
Normal file
@@ -0,0 +1,25 @@
|
||||
// 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'}`)
|
||||
Reference in New Issue
Block a user