import {z} from 'zod' export type GetApiApiPriceHistoryV1Args = {asset: string, timestamp_start?: number | undefined, timestamp_end?: number | undefined, page?: number | undefined, limit?: number | undefined, order?: ('timestamp_asc' | 'timestamp_desc') | undefined}; export type GetApiApiPriceHistoryV1Options = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiPriceHistoryV1Response = z.object({pagination: z.object({current_page: z.number().int().optional(), per_page: z.number().int().optional(), total_items: z.number().int().optional(), total_pages: z.number().int().optional(), next_page: z.number().int().optional(), prev_page: z.unknown()}).optional(), data: z.array(z.object({created_at: z.string().optional(), updated_at: z.string().optional(), name: z.string().optional(), symbol: z.string().optional(), slug: z.string().optional(), circulating_supply: z.string().optional(), max_supply: z.string().optional(), total_supply: z.string().optional(), last_updated: z.string().optional(), price: z.string().optional(), volume_24h: z.string().optional(), market_cap: z.string().optional(), percent_change_1h: z.string().optional(), percent_change_24h: z.string().optional(), percent_change_7d: z.string().optional(), percent_change_30d: z.string().optional(), percent_change_60d: z.string().optional(), percent_change_90d: z.string().optional(), market_cap_dominance: z.string().optional(), fully_diluted_market_cap: z.string().optional()})).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 Price History * * GET /api/price/history/v1 */ export const getApiApiPriceHistoryV1 = async (args: GetApiApiPriceHistoryV1Args, options?: GetApiApiPriceHistoryV1Options) => { const {baseUrl = "https://api.taostats.io", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.asset != null) query.append("asset", String(args.asset)) if (args.timestamp_start != null) query.append("timestamp_start", String(args.timestamp_start)) if (args.timestamp_end != null) query.append("timestamp_end", String(args.timestamp_end)) if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.order != null) query.append("order", String(args.order)) if (sec0 !== undefined) headers.set("Authorization", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/api/price/history/v1${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(getApiApiPriceHistoryV1Response, await res.json()) };