export type GetApiApiCommoditiesConvertArgs = {api_key: string, amount?: number | undefined, from?: string | undefined, to?: string | undefined, format?: ('json' | 'xml' | 'csv' | 'tsv') | undefined, callback?: string | undefined}; export type GetApiApiCommoditiesConvertOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Convert between commodities and currencies (Pro subscription required). 19 commodities: gold, silver, platinum, palladium (troy oz); WTI and Brent crude (barrel), US Henry Hub natural gas (MMBtu); copper, aluminium, zinc, nickel, lead, tin (tonne); wheat, corn (tonne), coffee, sugar, cocoa, cotton (kg). Precious metals are blended live from LBMA and market feeds; energy, base metals and agriculturals are World Bank reference prices (CC BY 4.0, attribution: The World Bank). * * GET /api/commodities/convert */ export const getApiApiCommoditiesConvert = async (args: GetApiApiCommoditiesConvertArgs, options: GetApiApiCommoditiesConvertOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "single_conversion") if (args.api_key != null) query.append("api_key", String(args.api_key)) if (args.amount != null) query.append("amount", String(args.amount)) if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args.format != null) query.append("format", String(args.format)) if (args.callback != null) query.append("callback", String(args.callback)) const url = `${baseUrl.replace(/\/+$/, '')}/api/commodities/convert${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() };