export type GetApiTaSlugCandlesticksArgs = {slug: string, interval?: ('m1' | 'm5' | 'm15' | 'm30' | 'h1' | 'h2' | 'h6' | 'h12' | 'd1') | undefined, start?: number | undefined, end?: number | undefined}; export type GetApiTaSlugCandlesticksOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Candlestick data * * GET /ta/{slug}/candlesticks * * Also accepts auth: apiKey */ export const getApiTaSlugCandlesticks = async (args: GetApiTaSlugCandlesticksArgs, options?: GetApiTaSlugCandlesticksOptions) => { const {baseUrl = "https://rest.coincap.io/v3", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.interval != null) query.append("interval", String(args.interval)) if (args.start != null) query.append("start", String(args.start)) if (args.end != null) query.append("end", String(args.end)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/ta/${encodeURIComponent(String(args.slug))}/candlesticks${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };