critical: Fix P&L compounding bug in 25 historical trades
- Identified 25 trades with corrupted P&L from compounding bug - Recalculated correct P&L for all affected trades (7 days) - Total corrections: 63.23 in fake profits removed - Today's actual P&L: -.97 (11 trades) - was showing -9.87 before fixes - Last 7 days actual P&L: +7.04 (70 trades) - was showing +27.90 Bug pattern: - P&L updated multiple times during close verification wait - Each update added to previous value instead of replacing - Worst case: -8.17 stored vs -.77 actual (7× compounding) Root cause: Common Pitfall #48 - closingInProgress flag fix deployed Nov 16 18:26 UTC but damage already done to historical data Files modified: - Database: 25 trades updated via SQL recalculation - Fixed trades from Nov 10-16 with ABS(stored - calculated) > $1
This commit is contained in:
60
app/api/drift/account-state/route.ts
Normal file
60
app/api/drift/account-state/route.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { getDriftService } from '@/lib/drift/client'
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const driftService = getDriftService()
|
||||
|
||||
// Get account health and equity
|
||||
const health = await driftService.getAccountHealth()
|
||||
const equity = await driftService.getAccountEquity()
|
||||
|
||||
// Get all positions
|
||||
const solPosition = await driftService.getPosition(0) // SOL-PERP
|
||||
const ethPosition = await driftService.getPosition(1) // ETH-PERP
|
||||
const btcPosition = await driftService.getPosition(2) // BTC-PERP
|
||||
|
||||
const positions = []
|
||||
if (solPosition && Math.abs(solPosition.size) > 0.01) {
|
||||
positions.push({
|
||||
market: 'SOL-PERP',
|
||||
direction: solPosition.side,
|
||||
size: solPosition.size,
|
||||
entryPrice: solPosition.entryPrice,
|
||||
unrealizedPnL: solPosition.unrealizedPnL
|
||||
})
|
||||
}
|
||||
if (ethPosition && Math.abs(ethPosition.size) > 0.01) {
|
||||
positions.push({
|
||||
market: 'ETH-PERP',
|
||||
direction: ethPosition.side,
|
||||
size: ethPosition.size,
|
||||
entryPrice: ethPosition.entryPrice,
|
||||
unrealizedPnL: ethPosition.unrealizedPnL
|
||||
})
|
||||
}
|
||||
if (btcPosition && Math.abs(btcPosition.size) > 0.01) {
|
||||
positions.push({
|
||||
market: 'BTC-PERP',
|
||||
direction: btcPosition.side,
|
||||
size: btcPosition.size,
|
||||
entryPrice: btcPosition.entryPrice,
|
||||
unrealizedPnL: btcPosition.unrealizedPnL
|
||||
})
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
accountHealth: health,
|
||||
equity: equity,
|
||||
positions: positions,
|
||||
timestamp: new Date().toISOString()
|
||||
})
|
||||
} catch (error: any) {
|
||||
console.error('Error getting account state:', error)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: error.message
|
||||
}, { status: 500 })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user