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
import { fetchJSON } from "https://esm.town/v/sean/fetchJSON";
import { toQueryString } from "https://esm.town/v/sean/toQueryString";
export const alphaVantageSymbolSearch = async ({
apikey,
...options
}: {
apikey: string,
keywords: string,
}) => {
const API_HOST = "alpha-vantage.p.rapidapi.com";
const queryString = await toQueryString({
...options,
function: "SYMBOL_SEARCH",
});
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;
}
};