Delete src
Browse files- src/index.mts +0 -240
src/index.mts
DELETED
@@ -1,240 +0,0 @@
|
|
1 |
-
const express = require('express');
|
2 |
-
const cors = require('cors');
|
3 |
-
const yahooFinance = require('yahoo-finance2').default;
|
4 |
-
const fetch = require('node-fetch');
|
5 |
-
|
6 |
-
const app = express();
|
7 |
-
const PORT = 3001;
|
8 |
-
|
9 |
-
app.use(cors());
|
10 |
-
app.use(express.json());
|
11 |
-
|
12 |
-
app.get('/api/search/:query', async (req, res) => {
|
13 |
-
const query = req.params.query;
|
14 |
-
try {
|
15 |
-
const results = await yahooFinance.search(query);
|
16 |
-
res.json(results);
|
17 |
-
} catch (error) {
|
18 |
-
res.status(500).json({ message: 'Error searching stocks.' });
|
19 |
-
}
|
20 |
-
});
|
21 |
-
|
22 |
-
app.get('/api/quote/:symbol', async (req, res) => {
|
23 |
-
const symbol = req.params.symbol;
|
24 |
-
try {
|
25 |
-
const quote = await yahooFinance.quote(symbol);
|
26 |
-
res.json(quote);
|
27 |
-
} catch (error) {
|
28 |
-
res.status(500).json({ message: 'Error fetching quote data.' });
|
29 |
-
}
|
30 |
-
});
|
31 |
-
|
32 |
-
app.get('/api/historical/:symbol', async (req, res) => {
|
33 |
-
const symbol = req.params.symbol;
|
34 |
-
const interval = req.query.interval || '1d'; // Default to 1 day
|
35 |
-
const range = req.query.range || '1y'; // Default to 1 year
|
36 |
-
|
37 |
-
try {
|
38 |
-
const url = `https://query1.finance.yahoo.com/v8/finance/chart/${symbol}?interval=${interval}&range=${range}`;
|
39 |
-
const response = await fetch(url);
|
40 |
-
const data = await response.json();
|
41 |
-
|
42 |
-
if (!data.chart.result) {
|
43 |
-
return res.status(404).json({ message: `No historical data found for ${symbol}` });
|
44 |
-
}
|
45 |
-
|
46 |
-
const timestamps = data.chart.result[0].timestamp;
|
47 |
-
const closePrices = data.chart.result[0].indicators.quote[0].close;
|
48 |
-
const openPrices = data.chart.result[0].indicators.quote[0].open;
|
49 |
-
const highPrices = data.chart.result[0].indicators.quote[0].high;
|
50 |
-
const lowPrices = data.chart.result[0].indicators.quote[0].low;
|
51 |
-
const adjustClosePrices = data.chart.result[0].indicators.adjclose[0].adjclose;
|
52 |
-
const volume = data.chart.result[0].indicators.quote[0].volume;
|
53 |
-
|
54 |
-
const historicalData = timestamps.map((time, index) => ({
|
55 |
-
date: new Date(time * 1000).toISOString().slice(0, 10), // Convert timestamp to date format
|
56 |
-
open: openPrices[index],
|
57 |
-
high: highPrices[index],
|
58 |
-
low: lowPrices[index],
|
59 |
-
close: closePrices[index],
|
60 |
-
adjustclose: adjustClosePrices[index],
|
61 |
-
volume: volume[index]
|
62 |
-
}));
|
63 |
-
|
64 |
-
res.json(historicalData.reverse());
|
65 |
-
|
66 |
-
} catch (error) {
|
67 |
-
console.error(`Error fetching historical data for ${symbol}:`, error);
|
68 |
-
res.status(500).json({ message: 'Error fetching historical data.', error: error.message });
|
69 |
-
}
|
70 |
-
});
|
71 |
-
|
72 |
-
app.get('/api/summary/:symbol', async (req, res) => {
|
73 |
-
const symbol = req.params.symbol;
|
74 |
-
try {
|
75 |
-
const queryOptions = { modules: ['summaryDetail', 'summaryProfile'] };
|
76 |
-
const quote = await yahooFinance.quoteSummary(symbol, queryOptions);
|
77 |
-
res.json(quote);
|
78 |
-
} catch (error) {
|
79 |
-
res.status(500).json({ message: 'Error fetching summary data.' });
|
80 |
-
}
|
81 |
-
})
|
82 |
-
|
83 |
-
app.get('/api/assetProfile/:symbol', async (req, res) => {
|
84 |
-
const symbol = req.params.symbol;
|
85 |
-
try {
|
86 |
-
const queryOptions = { modules: ['assetProfile'] };
|
87 |
-
const quote = await yahooFinance.quoteSummary(symbol, queryOptions);
|
88 |
-
res.json(quote);
|
89 |
-
} catch (error) {
|
90 |
-
res.status(500).json({ message: 'Error fetching assetProfile data.' });
|
91 |
-
}
|
92 |
-
})
|
93 |
-
|
94 |
-
app.get('/api/balanceSheetHistory/:symbol', async (req, res) => {
|
95 |
-
const symbol = req.params.symbol;
|
96 |
-
try {
|
97 |
-
const queryOptions = { modules: ['balanceSheetHistory', 'balanceSheetHistoryQuarterly'] };
|
98 |
-
const quote = await yahooFinance.quoteSummary(symbol, queryOptions);
|
99 |
-
res.json(quote);
|
100 |
-
} catch (error) {
|
101 |
-
res.status(500).json({ message: 'Error fetching balanceSheet data.' });
|
102 |
-
}
|
103 |
-
})
|
104 |
-
|
105 |
-
app.get('/api/calendar/:symbol', async (req, res) => {
|
106 |
-
const symbol = req.params.symbol;
|
107 |
-
try {
|
108 |
-
const queryOptions = { modules: ['calendarEvents'] };
|
109 |
-
const quote = await yahooFinance.quoteSummary(symbol, queryOptions);
|
110 |
-
res.json(quote);
|
111 |
-
} catch (error) {
|
112 |
-
res.status(500).json({ message: 'Error fetching calendarEvents data.' });
|
113 |
-
}
|
114 |
-
})
|
115 |
-
|
116 |
-
app.get('/api/cashflow/:symbol', async (req, res) => {
|
117 |
-
const symbol = req.params.symbol;
|
118 |
-
try {
|
119 |
-
const queryOptions = { modules: ['cashflowStatementHistory', 'cashflowStatementHistoryQuarterly'] };
|
120 |
-
const quote = await yahooFinance.quoteSummary(symbol, queryOptions);
|
121 |
-
res.json(quote);
|
122 |
-
} catch (error) {
|
123 |
-
res.status(500).json({ message: 'Error fetching cashflowstatement data.' });
|
124 |
-
}
|
125 |
-
})
|
126 |
-
|
127 |
-
app.get('/api/statistic/:symbol', async (req, res) => {
|
128 |
-
const symbol = req.params.symbol;
|
129 |
-
try {
|
130 |
-
const queryOptions = { modules: ['defaultKeyStatistics'] };
|
131 |
-
const quote = await yahooFinance.quoteSummary(symbol, queryOptions);
|
132 |
-
res.json(quote);
|
133 |
-
} catch (error) {
|
134 |
-
res.status(500).json({ message: 'Error fetching statistic data.' });
|
135 |
-
}
|
136 |
-
})
|
137 |
-
|
138 |
-
app.get('/api/earnings/:symbol', async (req, res) => {
|
139 |
-
const symbol = req.params.symbol;
|
140 |
-
try {
|
141 |
-
const queryOptions = { modules: ['earnings', 'earningsHistory', 'earningsTrend'] };
|
142 |
-
const quote = await yahooFinance.quoteSummary(symbol, queryOptions);
|
143 |
-
res.json(quote);
|
144 |
-
} catch (error) {
|
145 |
-
res.status(500).json({ message: 'Error fetching earnings data.' });
|
146 |
-
}
|
147 |
-
})
|
148 |
-
|
149 |
-
app.get('/api/financial/:symbol', async (req, res) => {
|
150 |
-
const symbol = req.params.symbol;
|
151 |
-
try {
|
152 |
-
const queryOptions = { modules: ['financialData'] };
|
153 |
-
const quote = await yahooFinance.quoteSummary(symbol, queryOptions);
|
154 |
-
res.json(quote);
|
155 |
-
} catch (error) {
|
156 |
-
res.status(500).json({ message: 'Error fetching financial data.' });
|
157 |
-
}
|
158 |
-
})
|
159 |
-
|
160 |
-
app.get('/api/fund/:symbol', async (req, res) => {
|
161 |
-
const symbol = req.params.symbol;
|
162 |
-
try {
|
163 |
-
const queryOptions = { modules: ['fundOwnership', 'fundPerformance', 'fundProfile'] };
|
164 |
-
const quote = await yahooFinance.quoteSummary(symbol, queryOptions);
|
165 |
-
res.json(quote);
|
166 |
-
} catch (error) {
|
167 |
-
res.status(500).json({ message: 'Error fetching fund data.' });
|
168 |
-
}
|
169 |
-
})
|
170 |
-
|
171 |
-
app.get('/api/income/:symbol', async (req, res) => {
|
172 |
-
const symbol = req.params.symbol;
|
173 |
-
try {
|
174 |
-
const queryOptions = { modules: ['incomeStatementHistory', 'incomeStatementHistoryQuarterly'] };
|
175 |
-
const quote = await yahooFinance.quoteSummary(symbol, queryOptions);
|
176 |
-
res.json(quote);
|
177 |
-
} catch (error) {
|
178 |
-
res.status(500).json({ message: 'Error fetching incomestatement data.' });
|
179 |
-
}
|
180 |
-
})
|
181 |
-
|
182 |
-
app.get('/api/trend/:symbol', async (req, res) => {
|
183 |
-
const symbol = req.params.symbol;
|
184 |
-
try {
|
185 |
-
const queryOptions = { modules: ['indexTrend', 'industryTrend'] };
|
186 |
-
const quote = await yahooFinance.quoteSummary(symbol, queryOptions);
|
187 |
-
res.json(quote);
|
188 |
-
} catch (error) {
|
189 |
-
res.status(500).json({ message: 'Error fetching trend data.' });
|
190 |
-
}
|
191 |
-
})
|
192 |
-
|
193 |
-
app.get('/api/insider/:symbol', async (req, res) => {
|
194 |
-
const symbol = req.params.symbol;
|
195 |
-
try {
|
196 |
-
const queryOptions = { modules: ['insiderHolders', 'insiderTransactions', 'institutionOwnership'] };
|
197 |
-
const quote = await yahooFinance.quoteSummary(symbol, queryOptions);
|
198 |
-
res.json(quote);
|
199 |
-
} catch (error) {
|
200 |
-
res.status(500).json({ message: 'Error fetching insider data.' });
|
201 |
-
}
|
202 |
-
})
|
203 |
-
|
204 |
-
app.get('/api/major/:symbol', async (req, res) => {
|
205 |
-
const symbol = req.params.symbol;
|
206 |
-
try {
|
207 |
-
const queryOptions = { modules: ['topHoldings', 'majorDirectHolders', 'majorHoldersBreakdown'] };
|
208 |
-
const quote = await yahooFinance.quoteSummary(symbol, queryOptions);
|
209 |
-
res.json(quote);
|
210 |
-
} catch (error) {
|
211 |
-
res.status(500).json({ message: 'Error fetching majorholders data.' });
|
212 |
-
}
|
213 |
-
})
|
214 |
-
|
215 |
-
|
216 |
-
app.get('/api/netshare/:symbol', async (req, res) => {
|
217 |
-
const symbol = req.params.symbol;
|
218 |
-
try {
|
219 |
-
const queryOptions = { modules: ['netSharePurchaseActivity', 'price'] };
|
220 |
-
const quote = await yahooFinance.quoteSummary(symbol, queryOptions);
|
221 |
-
res.json(quote);
|
222 |
-
} catch (error) {
|
223 |
-
res.status(500).json({ message: 'Error fetching netshare data.' });
|
224 |
-
}
|
225 |
-
})
|
226 |
-
|
227 |
-
app.get('/api/recommend/:symbol', async (req, res) => {
|
228 |
-
const symbol = req.params.symbol;
|
229 |
-
try {
|
230 |
-
const queryOptions = { modules: ['recommendationTrend'] };
|
231 |
-
const quote = await yahooFinance.quoteSummary(symbol, queryOptions);
|
232 |
-
res.json(quote);
|
233 |
-
} catch (error) {
|
234 |
-
res.status(500).json({ message: 'Error fetching recommendationTrend data.' });
|
235 |
-
}
|
236 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