blob: 3271e83ade45d710b1aa4a99c8416336975b2f95 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
import type { RequestHandler } from '@sveltejs/kit';
import yahooFinance from 'yahoo-finance2';
/**
* Example request : GET /stocksapi/chart?query=AAPL&startDate=2025-01-01&
*/
export const GET: RequestHandler = async ({ request }) => {
const sp = new URL(request.url).searchParams;
const query = sp.get('query') || 'AAPL';
const startDate = sp.get('startDate') || '2025-01-01';
const endDate = sp.get('endDate') || new Date().toISOString().split('T')[0];
const interval = sp.get('interval') || '1d';
const data = await yahooFinance.chart(query, { period1: startDate, period2: endDate, interval: interval });
return new Response(JSON.stringify(data), {
headers: {
'Content-Type': 'application/json',
'Cache-Control': 'no-cache',
},
});
};
|