export type GetApiV1OptionsChainHistoryTickerArgs = {ticker: string, expiration: string, right: 'C' | 'P', from: string, to: string, interval: '1m' | '5m' | '10m' | '15m' | '30m' | '1h'}; export type GetApiV1OptionsChainHistoryTickerOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Historical chain NBBO series for one ticker + expiration + right (on-demand materialization) * * GET /v1/options/chain-history/{ticker} */ export const getApiV1OptionsChainHistoryTicker = async (args: GetApiV1OptionsChainHistoryTickerArgs, options?: GetApiV1OptionsChainHistoryTickerOptions) => { const {baseUrl = "https://api.yehangshe.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.expiration != null) query.append("expiration", String(args.expiration)) if (args.right != null) query.append("right", String(args.right)) if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args.interval != null) query.append("interval", String(args.interval)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/options/chain-history/${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 };