import {z} from 'zod' export type GetApiAtomicmarketV1AssetsAssetIdSalesArgs = {asset_id: number, buyer?: string | undefined, seller?: string | undefined, symbol?: string | undefined, order?: ('asc' | 'desc') | undefined}; export type GetApiAtomicmarketV1AssetsAssetIdSalesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiAtomicmarketV1AssetsAssetIdSalesResponse = z.object({success: z.boolean().optional(), data: z.array(z.object({sale_id: z.string().optional(), auction_id: z.string().optional(), buyoffer_id: z.string().optional(), price: z.string().optional(), token_symbol: z.string().optional(), token_precision: z.number().int().optional(), token_contract: z.string().optional(), seller: z.string().optional(), buyer: z.string().optional(), block_time: z.string().optional()})).optional(), query_time: z.number().int().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 }; /** * Gets price history for a specific asset * * GET /atomicmarket/v1/assets/{asset_id}/sales */ export const getApiAtomicmarketV1AssetsAssetIdSales = async (args: GetApiAtomicmarketV1AssetsAssetIdSalesArgs, options?: GetApiAtomicmarketV1AssetsAssetIdSalesOptions) => { const {baseUrl = "https://atomic.3dkrender.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.buyer != null) query.append("buyer", String(args.buyer)) if (args.seller != null) query.append("seller", String(args.seller)) if (args.symbol != null) query.append("symbol", String(args.symbol)) if (args.order != null) query.append("order", String(args.order)) const url = `${baseUrl.replace(/\/+$/, '')}/atomicmarket/v1/assets/${encodeURIComponent(String(args.asset_id))}/sales${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(getApiAtomicmarketV1AssetsAssetIdSalesResponse, await res.json()) };