Spaces:
Build error
Build error
| export default function handler(req, res) { | |
| const { symbol } = req.query | |
| const days = 30 | |
| const generateHistoricalData = (basePrice) => { | |
| const data = [] | |
| let currentPrice = basePrice * 0.9 | |
| for (let i = days; i >= 0; i--) { | |
| const date = new Date() | |
| date.setDate(date.getDate() - i) | |
| const volatility = 0.03 | |
| const trend = i === 0 ? 1 : 1 + (Math.random() - 0.5) * volatility | |
| currentPrice = currentPrice * trend | |
| data.push({ | |
| date: date.toISOString().split('T')[0], | |
| price: parseFloat(currentPrice.toFixed(2)), | |
| volume: Math.floor(Math.random() * 50000000) + 10000000 | |
| }) | |
| } | |
| return data | |
| } | |
| const stockPrices = { | |
| 'AAPL': 178.50, | |
| 'MSFT': 378.85, | |
| 'GOOGL': 139.62, | |
| 'AMZN': 145.78, | |
| 'META': 312.45, | |
| 'TSLA': 248.50, | |
| 'NVDA': 485.09, | |
| 'NFLX': 445.03, | |
| } | |
| const basePrice = stockPrices[symbol] || 100 | |
| const chartData = generateHistoricalData(basePrice) | |
| res.status(200).json(chartData) | |
| } |