import { NextResponse } from 'next/server' import { driftTradingService } from '../../../../lib/drift-trading' export async function GET(request: Request) { try { const { searchParams } = new URL(request.url) const limit = parseInt(searchParams.get('limit') || '50') console.log('📊 API: Getting Drift trading history...') const tradingHistory = await driftTradingService.getTradingHistory(limit) // If no trades found, provide helpful message if (tradingHistory.length === 0) { console.log('⚠️ No trading history found') return NextResponse.json({ success: true, trades: [], count: 0, message: 'No trading history found. If you recently closed positions, they may take some time to appear in history.' }) } console.log(`✅ Successfully fetched ${tradingHistory.length} trades`) return NextResponse.json({ success: true, trades: tradingHistory, count: tradingHistory.length, message: `Found ${tradingHistory.length} trade(s)` }) } catch (error: any) { console.error('❌ API: Error getting trading history:', error) return NextResponse.json( { success: false, error: error.message, trades: [], count: 0, message: 'Failed to fetch trading history. Please try again.' }, { status: 500 } ) } }