-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
37 lines (32 loc) · 918 Bytes
/
Copy pathserver.js
File metadata and controls
37 lines (32 loc) · 918 Bytes
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
import express from 'express';
import cors from 'cors';
import YahooFinance from 'yahoo-finance2';
const yahooFinance = new YahooFinance();
const app = express();
app.use(cors());
app.get('/api/yahoo', async (req, res) => {
try {
const { ticker } = req.query;
if (!ticker) {
return res.status(400).json({ error: 'Ticker is required' });
}
const modules = [
"financialData",
"defaultKeyStatistics",
"incomeStatementHistory",
"balanceSheetHistory",
"cashflowStatementHistory",
"assetProfile",
"price"
];
const data = await yahooFinance.quoteSummary(ticker, { modules });
res.json(data);
} catch (error) {
console.error("Yahoo API Error:", error);
res.status(500).json({ error: error.message });
}
});
const PORT = 3001;
app.listen(PORT, () => {
console.log(`Local Yahoo Proxy running on http://localhost:${PORT}`);
});