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
38
39
40
41
42
43
44
import { fetchJSON } from "https://esm.town/v/sean/fetchJSON";
import { toQueryString } from "https://esm.town/v/sean/toQueryString";
export const alphaVantageSymbolQuery = async ({
apikey,
...options
}: {
apikey: string,
function:
| "TIME_SERIES_INTRADAY"
| "TIME_SERIES_INTRADAY_EXTENDED"
| "TIME_SERIES_DAILY"
| "TIME_SERIES_DAILY_ADJUSTED"
| "TIME_SERIES_WEEKLY"
| "TIME_SERIES_WEEKLY_ADJUSTED"
| "TIME_SERIES_MONTHLY"
| "TIME_SERIES_MONTHLY_ADJUSTED"
| "GLOBAL_QUOTE"
symbol: string,
interval?: "1min" | "5min" | "15min" | "30min" | "60min",
outputSize?: "compact" | "full",
adjusted?: boolean,
slice?: string,
}) => {
const API_HOST = "alpha-vantage.p.rapidapi.com";
const queryString = await toQueryString(options);
try {
const json = await fetchJSON(
`https://${API_HOST}/query?${queryString}`,
{
method: "GET",
headers: {
"X-RapidAPI-Key": apikey,
"X-RapidAPI-Host": API_HOST,
},
}
);
return json;
} catch (error) {
throw error;
}
};
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023