import {z} from 'zod' export type GetApiProfilesProfileIdQuoteExecutionsArgs = {profile_id: string, side?: ('BUY' | 'SELL') | undefined, market?: ('ETHEUR' | 'ETHSGD' | 'ETHUSD' | 'BTCEUR' | 'BTCSGD' | 'BTCUSD' | 'PAXGUSD' | 'BCHUSD' | 'LTCUSD' | 'USDPUSD' | 'LINKUSD' | 'AAVEUSD' | 'UNIUSD' | 'PEPEUSD' | 'TRUMPUSD' | 'SHIBUSD' | 'ARBUSD' | 'BONKUSD' | 'ENAUSD' | 'MNTUSD' | 'ONDOUSD' | 'PENGUUSD' | 'QNTUSD' | 'RENDERUSD' | 'SKYUSD' | 'WIFUSD' | 'WLDUSD' | 'DOGEUSD' | 'AVAXUSD' | 'SUIUSD' | 'POLUSD' | 'XLMUSD' | 'BNBUSD') | undefined, status?: ('CREATED' | 'SETTLED') | undefined, 'created_at.begin'?: string | undefined, 'created_at.end'?: string | undefined, limit?: number | undefined, order?: ('DESC' | 'ASC') | undefined, order_by?: 'CREATED_AT' | undefined, page_cursor?: string | undefined}; export type GetApiProfilesProfileIdQuoteExecutionsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const quoteExecutionStatus = z.enum(["CREATED", "SETTLED"]); export const market = z.enum(["ETHEUR", "ETHSGD", "ETHUSD", "BTCEUR", "BTCSGD", "BTCUSD", "PAXGUSD", "BCHUSD", "LTCUSD", "USDPUSD", "LINKUSD", "AAVEUSD", "UNIUSD", "PEPEUSD", "TRUMPUSD", "SHIBUSD", "ARBUSD", "BONKUSD", "ENAUSD", "MNTUSD", "ONDOUSD", "PENGUUSD", "QNTUSD", "RENDERUSD", "SKYUSD", "WIFUSD", "WLDUSD", "DOGEUSD", "AVAXUSD", "SUIUSD", "POLUSD", "XLMUSD", "BNBUSD"]); export const orderSide = z.enum(["BUY", "SELL"]); export const quoteExecution = z.object({id: z.string(), profile_id: z.string(), quote_id: z.string(), ref_id: z.string().optional(), status: quoteExecutionStatus, market: market, side: orderSide, price: z.string(), base_amount: z.string(), base_asset: z.string(), quote_amount: z.string(), quote_asset: z.string(), created_at: z.string(), settled_at: z.string().optional(), metadata: z.record(z.string(), z.string()).optional(), identity_id: z.string().optional(), account_id: z.string().optional(), recipient_profile_id: z.string().optional()}); export const listQuoteExecutionsResponse = z.object({total_count: z.number().int().optional(), items: z.array(quoteExecution).optional(), next_page_cursor: z.string().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 Quote Executions * * GET /profiles/{profile_id}/quote-executions */ export const getApiProfilesProfileIdQuoteExecutions = async (args: GetApiProfilesProfileIdQuoteExecutionsArgs, options?: GetApiProfilesProfileIdQuoteExecutionsOptions) => { const {baseUrl = "https://api.paxos.com/v2", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.side != null) query.append("side", String(args.side)) if (args.market != null) query.append("market", String(args.market)) if (args.status != null) query.append("status", String(args.status)) if (args['created_at.begin'] != null) query.append("created_at.begin", String(args['created_at.begin'])) if (args['created_at.end'] != null) query.append("created_at.end", String(args['created_at.end'])) if (args.limit != null) query.append("limit", String(args.limit)) if (args.order != null) query.append("order", String(args.order)) if (args.order_by != null) query.append("order_by", String(args.order_by)) if (args.page_cursor != null) query.append("page_cursor", String(args.page_cursor)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/profiles/${encodeURIComponent(String(args.profile_id))}/quote-executions${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(listQuoteExecutionsResponse, await res.json()) };