Spaces:
Build error
Build error
File size: 1,026 Bytes
bd98be2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
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)
} |