export type GetApiTradeArgs = {poolId: string, limit?: number | undefined, nextPageKey?: string | undefined, owner?: string | undefined, minAmount?: number | undefined, maxAmount?: number | undefined}; export type GetApiTradeOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get trade history * * GET /trade */ export const getApiTrade = async (args: GetApiTradeArgs, options?: GetApiTradeOptions) => { 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.limit != null) query.append("limit", String(args.limit)) if (args.nextPageKey != null) query.append("nextPageKey", String(args.nextPageKey)) if (args.owner != null) query.append("owner", String(args.owner)) if (args.minAmount != null) query.append("minAmount", String(args.minAmount)) if (args.maxAmount != null) query.append("maxAmount", String(args.maxAmount)) const url = `${baseUrl.replace(/\/+$/, '')}/trade${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 };