export type GetApiV1StocksOhlcTickerArgs = {ticker: string, candle_size: '1m' | '5m' | '10m' | '15m' | '30m' | '1h' | '4h' | '1d' | '1w'}; export type GetApiV1StocksOhlcTickerOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * OHLC candles for one ticker at a chosen candle size (on-demand materialization) * * GET /v1/stocks/ohlc/{ticker} */ export const getApiV1StocksOhlcTicker = async (args: GetApiV1StocksOhlcTickerArgs, options?: GetApiV1StocksOhlcTickerOptions) => { const {baseUrl = "https://api.yehangshe.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.candle_size != null) query.append("candle_size", String(args.candle_size)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/stocks/ohlc/${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 };