export type GetApiKlineArgs = {poolId: string, interval: '1m' | '5m' | '15m', limit?: number | undefined, nextPageKey?: string | undefined}; export type GetApiKlineOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get kline (candlestick) data * * GET /kline */ export const getApiKline = async (args: GetApiKlineArgs, options?: GetApiKlineOptions) => { const {baseUrl = "https://api.raydium.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.poolId != null) query.append("poolId", String(args.poolId)) if (args.interval != null) query.append("interval", String(args.interval)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.nextPageKey != null) query.append("nextPageKey", String(args.nextPageKey)) const url = `${baseUrl.replace(/\/+$/, '')}/kline${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 };