import {z} from 'zod' export type GetApiV1ExecutionsExecutionIdArgs = {executionId: string}; export type GetApiV1ExecutionsExecutionIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const orderType = z.enum(["MARKET", "LIMIT", "PREVIOUSLY_QUOTED"]); export const executionStatus = z.enum(["TRADE_EXECUTED", "TRADE_CONFIRMED", "TRADE_SETTLED"]); export const execution = z.object({executionId: z.string().optional(), orderId: z.string().optional(), accountId: z.string().optional(), executedAt: z.string().optional(), pair: z.string().optional(), side: z.string().optional(), orderType: orderType.optional(), deliverCurrency: z.string().optional(), deliverQuantity: z.string().optional(), receiveCurrency: z.string().optional(), receiveQuantity: z.string().optional(), price: z.string().optional(), baseQuantity: z.string().optional(), quoteQuantity: z.string().optional(), clientFeeRate: z.string().nullable().optional(), clientFeeAmount: z.string().nullable().optional(), providerFeeRate: z.string().optional(), clientFeeQuantity: z.string().optional(), providerFeeQuantity: z.string().optional(), feeCurrency: z.string().optional(), executionStatus: executionStatus.optional(), tradeDate: z.string().optional(), valueDate: z.string().optional(), confirmedAt: z.string().nullable().optional(), clientReference: z.string().nullable().optional(), tradeTaxRate: z.string().optional(), clientTaxQuantity: z.string().optional(), providerTaxQuantity: z.string().optional(), fileUrl: z.string().nullable().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 Execution * * GET /v1/executions/{executionId} */ export const getApiV1ExecutionsExecutionId = async (args: GetApiV1ExecutionsExecutionIdArgs, options?: GetApiV1ExecutionsExecutionIdOptions) => { const {baseUrl = "https://cams.aquanow.com/api", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/executions/${encodeURIComponent(String(args.executionId))}${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(execution, await res.json()) };