export type GetApiOptionquoteTickerArgs = {ticker: string, expiry?: string | undefined, strike?: number | undefined, type?: string | undefined}; export type GetApiOptionquoteTickerOptions = {baseUrl: string, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * GET /optionquote/{ticker} */ export const getApiOptionquoteTicker = async (args: GetApiOptionquoteTickerArgs, options: GetApiOptionquoteTickerOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.expiry != null) query.append("expiry", String(args.expiry)) if (args.strike != null) query.append("strike", String(args.strike)) if (args.type != null) query.append("type", String(args.type)) if (ApiKey !== undefined) headers.set("X-Api-Key", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/optionquote/${encodeURIComponent(String(args.ticker))}${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 };