import {z} from 'zod' export type GetApiApiV1TrendingTickersListArgs = {interval: string, tickers?: string | undefined, source: string, timeframe?: string | undefined, time_from?: string | undefined, time_to?: string | undefined, date_from?: string | undefined, date_to?: string | undefined, page?: number | undefined, pagesize?: number | undefined}; export type GetApiApiV1TrendingTickersListOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const modelsSecurity = z.object({exchange: z.string().optional(), name: z.string().optional(), ticker: z.string().optional()}); export const modelsTrendingTickersListData = z.object({count: z.number().int().optional(), pct_chg: z.number().int().optional(), security: modelsSecurity.optional()}); export const modelsTrendingTickersListAPIResponse = z.object({data: z.array(modelsTrendingTickersListData).optional(), ok: z.boolean().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 Trending Tickers List * * GET /api/v1/trending-tickers/list */ export const getApiApiV1TrendingTickersList = async (args: GetApiApiV1TrendingTickersListArgs, options?: GetApiApiV1TrendingTickersListOptions) => { const {baseUrl = "https://api.benzinga.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.interval != null) query.append("interval", String(args.interval)) if (args.tickers != null) query.append("tickers", String(args.tickers)) if (args.source != null) query.append("source", String(args.source)) if (args.timeframe != null) query.append("timeframe", String(args.timeframe)) if (args.time_from != null) query.append("time_from", String(args.time_from)) if (args.time_to != null) query.append("time_to", String(args.time_to)) if (args.date_from != null) query.append("date_from", String(args.date_from)) if (args.date_to != null) query.append("date_to", String(args.date_to)) if (args.page != null) query.append("page", String(args.page)) if (args.pagesize != null) query.append("pagesize", String(args.pagesize)) if (ApiKeyAuth !== undefined) headers.set("Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/trending-tickers/list${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(modelsTrendingTickersListAPIResponse, await res.json()) };