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;
}
};