import {z} from 'zod' export type GetApiApiTradeV20TradesArgs = {version: string, pageSize?: number | undefined, pageNumber?: number | undefined, id?: string | undefined, taxId?: string | undefined, beginDate?: string | undefined, endDate?: string | undefined, side?: ('Buy' | 'Sell') | undefined, priceNet?: number | undefined, quoteId?: string | undefined, baseCurrency?: string | undefined, baseCurrencySize?: number | undefined, quoteCurrency?: string | undefined, quoteCurrencySize?: number | undefined, accountIdBase?: string | undefined, accountIdQuote?: string | undefined, Authorization: string}; export type GetApiApiTradeV20TradesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiTradeV20TradesResponse = z.object({}); 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 }; /** * Retrieve all Trades * * GET /api/trade/v2.0/trades */ export const getApiApiTradeV20Trades = async (args: GetApiApiTradeV20TradesArgs, options?: GetApiApiTradeV20TradesOptions) => { const {baseUrl = "https://sandbox-api-baasic.transfero.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.pageNumber != null) query.append("pageNumber", String(args.pageNumber)) if (args.id != null) query.append("id", String(args.id)) if (args.taxId != null) query.append("taxId", String(args.taxId)) if (args.beginDate != null) query.append("beginDate", String(args.beginDate)) if (args.endDate != null) query.append("endDate", String(args.endDate)) if (args.side != null) query.append("side", String(args.side)) if (args.priceNet != null) query.append("priceNet", String(args.priceNet)) if (args.quoteId != null) query.append("quoteId", String(args.quoteId)) if (args.baseCurrency != null) query.append("baseCurrency", String(args.baseCurrency)) if (args.baseCurrencySize != null) query.append("baseCurrencySize", String(args.baseCurrencySize)) if (args.quoteCurrency != null) query.append("quoteCurrency", String(args.quoteCurrency)) if (args.quoteCurrencySize != null) query.append("quoteCurrencySize", String(args.quoteCurrencySize)) if (args.accountIdBase != null) query.append("accountIdBase", String(args.accountIdBase)) if (args.accountIdQuote != null) query.append("accountIdQuote", String(args.accountIdQuote)) if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/api/trade/v2.0/trades${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(getApiApiTradeV20TradesResponse, await res.json()) };