export type GetApiApiHistoricalTimeseriesArgs = {api_key: string, start_date: string, end_date: string, amount?: number | undefined, base?: string | undefined, format?: ('json' | 'xml' | 'csv' | 'tsv') | undefined, callback?: string | undefined, currencies?: string | undefined}; export type GetApiApiHistoricalTimeseriesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Get time series data for a date range with optional amount conversion (max 5 years) * * GET /api/historical/timeseries */ export const getApiApiHistoricalTimeseries = async (args: GetApiApiHistoricalTimeseriesArgs, options: GetApiApiHistoricalTimeseriesOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "rates_only") if (args.api_key != null) query.append("api_key", String(args.api_key)) if (args.start_date != null) query.append("start_date", String(args.start_date)) if (args.end_date != null) query.append("end_date", String(args.end_date)) if (args.amount != null) query.append("amount", String(args.amount)) if (args.base != null) query.append("base", String(args.base)) if (args.format != null) query.append("format", String(args.format)) if (args.callback != null) query.append("callback", String(args.callback)) if (args.currencies != null) query.append("currencies", String(args.currencies)) const url = `${baseUrl.replace(/\/+$/, '')}/api/historical/timeseries${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 res.blob() };