import { NextResponse } from 'next/server' export async function GET(request: Request) { try { const { searchParams } = new URL(request.url); const symbol = searchParams.get('symbol'); // Get REAL price data from CoinGecko let coinGeckoId = 'solana'; // Default if (symbol) { const symbolMap: { [key: string]: string } = { 'SOL': 'solana', 'SOLUSD': 'solana', 'BTC': 'bitcoin', 'ETH': 'ethereum' }; coinGeckoId = symbolMap[symbol.toUpperCase()] || 'solana'; } const response = await fetch( `https://api.coingecko.com/api/v3/simple/price?ids=${coinGeckoId}&vs_currencies=usd&include_24hr_change=true&include_market_cap=true&include_24hr_vol=true` ); if (!response.ok) { throw new Error('CoinGecko API failed'); } const data = await response.json(); const coinData = data[coinGeckoId]; if (!coinData) { throw new Error('No price data found'); } const priceData = { symbol: symbol || 'SOL', price: coinData.usd, change24h: coinData.usd_24h_change || 0, volume24h: coinData.usd_24h_vol || 0, marketCap: coinData.usd_market_cap || 0, lastUpdated: new Date().toISOString(), source: 'COINGECKO_API' }; return NextResponse.json(priceData); } catch (error) { return NextResponse.json({ error: 'Failed to fetch prices', message: error instanceof Error ? error.message : 'Unknown error' }, { status: 500 }) } }