summaryrefslogtreecommitdiff
path: root/ping/frontend/src/routes/stocksapi/insights/+server.ts
blob: 6be76e911f75b585c01568db0f5a428235801ca5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import type { RequestHandler } from '@sveltejs/kit';
import yahooFinance from 'yahoo-finance2';

/**
 * Example request : GET /stocksapi/insights?query=AAPL
 */
export const GET: RequestHandler = async ({ request }) => {
    const sp = new URL(request.url).searchParams;
    const query = sp.get('query') || 'AAPL';

    const queryOptions = { lang: 'en-US', reportsCount: 2, region: 'US' };
    const data = await yahooFinance.insights(query, queryOptions);
    return new Response(JSON.stringify(data), {
        headers: {
            'Content-Type': 'application/json',
            'Cache-Control': 'no-cache',
        },
    });
};