import { NextResponse } from 'next/server' import { driftTradingService } from '../../../../lib/drift-trading' export async function POST(request: Request) { try { console.log('🔄 API: Manually syncing trades with Drift...') // Get current positions to check for any changes const positions = await driftTradingService.getPositions() // Check for recent closures that might not be in history yet const recentClosures = await driftTradingService.getRecentClosures(24) // Get existing trading history const existingTrades = await driftTradingService.getTradingHistory(100) console.log(`📊 Found ${positions.length} active positions`) console.log(`📊 Found ${recentClosures.length} recent closures`) console.log(`📊 Found ${existingTrades.length} existing trades`) return NextResponse.json({ success: true, message: 'Trade sync completed', data: { activePositions: positions.length, recentClosures: recentClosures.length, existingTrades: existingTrades.length, positions: positions, closures: recentClosures } }) } catch (error: any) { console.error('❌ API: Error syncing trades:', error) return NextResponse.json( { success: false, error: error.message, message: 'Failed to sync trades. Please try again.' }, { status: 500 } ) } }