import {z} from 'zod' export type GetApiProfilesProfileIdOrdersIdArgs = {profile_id: string, id: string}; export type GetApiProfilesProfileIdOrdersIdOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const orderStatus = z.enum(["PENDING_SUBMISSION", "SUBMITTED", "OPEN", "FILLED", "CANCELLED", "REJECTED", "EXPIRED"]); export const orderSide = z.enum(["BUY", "SELL"]); 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 orderType = z.enum(["LIMIT", "MARKET", "POST_ONLY_LIMIT", "STOP_MARKET", "STOP_LIMIT"]); export const timeInForce = z.enum(["GTC", "FOK", "IOC", "GTT"]); export const order = z.object({id: z.string().optional(), profile_id: z.string().optional(), ref_id: z.string().optional(), status: orderStatus.optional(), side: orderSide.optional(), market: market.optional(), type: orderType.optional(), base_amount: z.string().optional(), price: z.string().optional(), quote_amount: z.string().optional(), metadata: z.record(z.string(), z.string()).optional(), created_at: z.string().optional(), modified_at: z.string().optional(), amount_filled: z.string().optional(), volume_weighted_average_price: z.string().optional(), time_in_force: timeInForce.optional(), expiration_date: z.string().optional(), identity_id: z.string().optional(), identity_account_id: z.string().optional(), stop_price: z.string().optional(), recipient_profile_id: z.string().optional(), is_triggered: z.boolean().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 Order * * GET /profiles/{profile_id}/orders/{id} */ export const getApiProfilesProfileIdOrdersId = async (args: GetApiProfilesProfileIdOrdersIdArgs, options?: GetApiProfilesProfileIdOrdersIdOptions) => { 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))}/orders/${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(order, await res.json()) };