mvbhr commited on
Commit
bd98be2
·
verified ·
1 Parent(s): f5138a5

Upload pages/api/chart.js with huggingface_hub

Browse files
Files changed (1) hide show
  1. pages/api/chart.js +42 -0
pages/api/chart.js ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export default function handler(req, res) {
2
+ const { symbol } = req.query
3
+ const days = 30
4
+
5
+ const generateHistoricalData = (basePrice) => {
6
+ const data = []
7
+ let currentPrice = basePrice * 0.9
8
+
9
+ for (let i = days; i >= 0; i--) {
10
+ const date = new Date()
11
+ date.setDate(date.getDate() - i)
12
+
13
+ const volatility = 0.03
14
+ const trend = i === 0 ? 1 : 1 + (Math.random() - 0.5) * volatility
15
+ currentPrice = currentPrice * trend
16
+
17
+ data.push({
18
+ date: date.toISOString().split('T')[0],
19
+ price: parseFloat(currentPrice.toFixed(2)),
20
+ volume: Math.floor(Math.random() * 50000000) + 10000000
21
+ })
22
+ }
23
+
24
+ return data
25
+ }
26
+
27
+ const stockPrices = {
28
+ 'AAPL': 178.50,
29
+ 'MSFT': 378.85,
30
+ 'GOOGL': 139.62,
31
+ 'AMZN': 145.78,
32
+ 'META': 312.45,
33
+ 'TSLA': 248.50,
34
+ 'NVDA': 485.09,
35
+ 'NFLX': 445.03,
36
+ }
37
+
38
+ const basePrice = stockPrices[symbol] || 100
39
+ const chartData = generateHistoricalData(basePrice)
40
+
41
+ res.status(200).json(chartData)
42
+ }