import { NextResponse } from 'next/server' import { getAllPaperTrades } from '../create-trade/route.js' export async function GET() { try { const trades = getAllPaperTrades() // Calculate stats const totalTrades = trades.length const totalValue = trades.reduce((sum, trade) => { return sum + (trade.side === 'BUY' ? -trade.amount : trade.amount) + trade.pnl }, 0) const buyTrades = trades.filter(t => t.side === 'BUY').length const sellTrades = trades.filter(t => t.side === 'SELL').length return NextResponse.json({ success: true, trades: trades, totalTrades, totalValue, buyTrades, sellTrades, timestamp: new Date().toISOString() }) } catch (error) { console.error('Error fetching paper trades:', error) return NextResponse.json({ success: false, message: 'Failed to fetch paper trades', error: error.message }, { status: 500 }) } }