fix: eliminate excessive P&L calculations and restore CoinGecko price source

- Fixed Prisma table name errors in price-monitor.ts (trades vs trade, automation_sessions vs automationSession)
- Commented out excessive P&L calculation logging in analysis-details API that was processing all 69 trades
- Restored CoinGecko as primary price source (was falling back to Binance due to DB errors)
- Optimized analysis-details to skip P&L calculations for FAILED/EXECUTED trades
- Added comprehensive cleanup system for orphaned orders
- Performance improvement: eliminated unnecessary processing of old trade data

Result: Clean logs, efficient price fetching from CoinGecko, no excessive calculations
This commit is contained in:
mindesbunister
2025-07-28 13:45:17 +02:00
parent 3ba760df2d
commit 08970acc85
12 changed files with 1291 additions and 310 deletions

View File

@@ -92,14 +92,14 @@ export async function GET() {
const unrealizedPnL = trade.status === 'OPEN' ?
(priceChange * trade.amount * (actualTradingAmount / storedPositionValue)) : null
console.log(`💰 P&L Calculation for trade ${trade.id}:`, {
actualTradingAmount,
storedPositionValue: storedPositionValue.toFixed(2),
priceChange: priceChange.toFixed(2),
rawPnL: (priceChange * trade.amount).toFixed(2),
adjustedPnL: unrealizedPnL?.toFixed(2),
adjustment_ratio: (actualTradingAmount / storedPositionValue).toFixed(4)
})
// console.log(`💰 P&L Calculation for trade ${trade.id}:`, {
// actualTradingAmount,
// storedPositionValue: storedPositionValue.toFixed(2),
// priceChange: priceChange.toFixed(2),
// rawPnL: (priceChange * trade.amount).toFixed(2),
// adjustedPnL: unrealizedPnL?.toFixed(2),
// adjustment_ratio: (actualTradingAmount / storedPositionValue).toFixed(4)
// })
const entryTime = new Date(trade.createdAt)
const exitTime = trade.closedAt ? new Date(trade.closedAt) : null