import {z} from 'zod' export type ExchangePublicCreateQuoteExecutionBody = {quote_id: string, ref_id?: string | undefined, base_amount?: string | undefined, quote_amount?: string | undefined, metadata?: {[key: string]: string} | undefined, identity_id?: string | undefined, account_id?: string | undefined, recipient_profile_id?: string | undefined}; export type CreateApiProfilesProfileIdQuoteExecutionsArgs = {profile_id: string, body: ExchangePublicCreateQuoteExecutionBody}; export type CreateApiProfilesProfileIdQuoteExecutionsOptions = {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 }; /** * Create Quote Execution * * POST /profiles/{profile_id}/quote-executions */ export const createApiProfilesProfileIdQuoteExecutions = async (args: CreateApiProfilesProfileIdQuoteExecutionsArgs, options?: CreateApiProfilesProfileIdQuoteExecutionsOptions) => { const {baseUrl = "https://api.paxos.com/v2", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") 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${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) 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()) };