import {z} from 'zod' export type GetApiMarketsMarketRecentExecutionsArgs = {market: 'ETHEUR' | 'ETHSGD' | 'ETHUSD' | 'BTCEUR' | 'BTCSGD' | 'BTCUSD' | 'PAXGUSD' | 'BCHUSD' | 'LTCUSD' | 'USDPUSD' | 'ETHBRL' | 'BTCBRL' | 'LTCBRL' | 'BCHBRL' | 'USDPGBP' | 'USDPBRL' | 'LINKUSD' | 'AAVEUSD' | 'UNIUSD' | 'AAVEMXN' | 'BCHMXN' | 'BTCMXN' | 'ETHMXN' | 'LTCMXN' | 'USDPMXN' | 'AAVEEUR' | 'BCHEUR' | 'LTCEUR' | 'LINKEUR' | 'PAXGEUR' | 'SOLEUR' | 'USDPEUR' | 'UNIEUR' | 'PYUSDEUR' | 'PEPEUSD' | 'TRUMPUSD' | 'SHIBUSD' | 'ARBUSD' | 'BONKUSD' | 'ENAUSD' | 'MNTUSD' | 'ONDOUSD' | 'PENGUUSD' | 'QNTUSD' | 'RENDERUSD' | 'SKYUSD' | 'WIFUSD' | 'WLDUSD' | 'DOGEUSD' | 'AVAXUSD' | 'SUIUSD' | 'POLUSD' | 'XLMUSD' | 'BNBUSD'}; export type GetApiMarketsMarketRecentExecutionsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const recentExecution = z.object({match_number: z.string().optional(), price: z.string().optional(), amount: z.string().optional(), executed_at: z.string().optional()}); export const listRecentExecutionsResponse = z.object({items: z.array(recentExecution).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 Recent Executions * * GET /markets/{market}/recent-executions */ export const getApiMarketsMarketRecentExecutions = async (args: GetApiMarketsMarketRecentExecutionsArgs, options?: GetApiMarketsMarketRecentExecutionsOptions) => { const {baseUrl = "https://api.paxos.com/v2", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/markets/${encodeURIComponent(String(args.market))}/recent-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(listRecentExecutionsResponse, await res.json()) };