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 }) } }