import {z} from 'zod' export type GetApiProfilesProfileIdQuoteExecutionsIdArgs = {profile_id: string, id: string}; export type GetApiProfilesProfileIdQuoteExecutionsIdOptions = {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 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 }; /** * Get Quote Execution * * GET /profiles/{profile_id}/quote-executions/{id} */ export const getApiProfilesProfileIdQuoteExecutionsId = async (args: GetApiProfilesProfileIdQuoteExecutionsIdArgs, options?: GetApiProfilesProfileIdQuoteExecutionsIdOptions) => { 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 (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/profiles/${encodeURIComponent(String(args.profile_id))}/quote-executions/${encodeURIComponent(String(args.id))}${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(quoteExecution, await res.json()) };