import {z} from 'zod' export type GetApiLimitOrderHistoryOrderListByUserArgs = {wallet: string, hideCancel?: string | undefined, poolId?: string | undefined, mint1?: string | undefined, mint2?: string | undefined, nextPageId?: string | undefined, size?: number | undefined}; export type GetApiLimitOrderHistoryOrderListByUserOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const limitOrderHistoryItem = z.object({pda: z.string(), owner: z.string(), poolId: z.string(), mintA: z.string(), mintB: z.string(), zeroForOne: z.boolean(), tick: z.number().int(), price: z.number(), openBlockTime: z.number().int(), fillStatus: z.enum(["NONE", "PARTIAL", "FULL"]), orderInputAmountUi: z.number(), orderOutputAmountUi: z.number(), filledInputAmountUi: z.number(), filledOutputAmountUi: z.number()}); export const limitOrderHistoryByUserResponse = z.object({id: z.string().optional(), success: z.boolean(), data: z.object({rows: z.array(limitOrderHistoryItem), nextPageId: z.string().nullable().optional()})}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * List a wallet's historical CLMM limit orders * * GET /limit-order/history/order/list-by-user */ export const getApiLimitOrderHistoryOrderListByUser = async (args: GetApiLimitOrderHistoryOrderListByUserArgs, options?: GetApiLimitOrderHistoryOrderListByUserOptions) => { const {baseUrl = "https://api.raydium.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.wallet != null) query.append("wallet", String(args.wallet)) if (args.hideCancel != null) query.append("hideCancel", String(args.hideCancel)) if (args.poolId != null) query.append("poolId", String(args.poolId)) if (args.mint1 != null) query.append("mint1", String(args.mint1)) if (args.mint2 != null) query.append("mint2", String(args.mint2)) if (args.nextPageId != null) query.append("nextPageId", String(args.nextPageId)) if (args.size != null) query.append("size", String(args.size)) const url = `${baseUrl.replace(/\/+$/, '')}/limit-order/history/order/list-by-user${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 validateResponse(limitOrderHistoryByUserResponse, await res.json()) };