Spaces:
Build error
Build error
File size: 1,727 Bytes
f5138a5 |
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
export default function handler(req, res) {
const generateRandomPrice = (base, volatility = 0.02) => {
return base * (1 + (Math.random() - 0.5) * volatility)
}
const generateChange = () => {
return (Math.random() - 0.48) * 10
}
const stocks = [
{ symbol: 'AAPL', name: 'Apple Inc.', basePrice: 178.50 },
{ symbol: 'MSFT', name: 'Microsoft', basePrice: 378.85 },
{ symbol: 'GOOGL', name: 'Alphabet', basePrice: 139.62 },
{ symbol: 'AMZN', name: 'Amazon', basePrice: 145.78 },
{ symbol: 'META', name: 'Meta Platforms', basePrice: 312.45 },
{ symbol: 'TSLA', name: 'Tesla', basePrice: 248.50 },
{ symbol: 'NVDA', name: 'NVIDIA', basePrice: 485.09 },
{ symbol: 'NFLX', name: 'Netflix', basePrice: 445.03 },
]
const stocksData = stocks.map(stock => {
const price = generateRandomPrice(stock.basePrice)
const change = generateChange()
const changePercent = (change / stock.basePrice) * 100
return {
...stock,
price: price.toFixed(2),
change: change.toFixed(2),
changePercent: changePercent.toFixed(2),
volume: Math.floor(Math.random() * 100000000) + 10000000,
marketCap: (price * 1000000000).toFixed(0),
}
})
const marketOverview = {
sp500: {
value: 4514.02,
change: 15.36,
changePercent: 0.34
},
nasdaq: {
value: 14113.70,
change: 123.45,
changePercent: 0.88
},
dow: {
value: 35430.42,
change: -45.12,
changePercent: -0.13
},
vix: {
value: 14.82,
change: -0.45,
changePercent: -2.95
}
}
res.status(200).json({
stocks: stocksData,
marketOverview,
timestamp: new Date().toISOString()
})
} |