import {z} from 'zod' export type GetApiV1StocksTickerShortVolumeArgs = {ticker: string, startDate?: string | undefined, endDate?: string | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiV1StocksTickerShortVolumeOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const listingNotice = z.object({status: z.string().nullable().optional(), ticker: z.string().nullable().optional(), delistedOn: z.string().nullable().optional(), successorTicker: z.string().nullable().optional()}); export const shortVolumeDto = z.object({date: z.string().optional(), shortVolume: z.number().int().optional(), shortExemptVolume: z.number().int().optional(), totalVolume: z.number().int().optional(), shortVolumePercent: z.number().optional()}); export const pageMeta = z.object({limit: z.number().int().optional(), offset: z.number().int().optional(), count: z.number().int().optional(), hasMore: z.boolean().optional(), total: z.number().int().nullable().optional()}); export const shortVolumeDtoPagedResponse = z.object({listingNotice: listingNotice.optional(), data: z.array(shortVolumeDto).nullable().optional(), meta: pageMeta.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 }; /** * Daily FINRA short volume for an exact stock or ETF listing, newest first. Volumes cover FINRA-reported off-exchange facility trades only (roughly 40% of consolidated tape volume, so a 40-50% short percentage is the normal baseline) and are restated onto today's split basis. Daily coverage begins 2026-04-06 — earlier dates return an empty page (use short-interest for deep history). * * GET /v1/stocks/{ticker}/short-volume */ export const getApiV1StocksTickerShortVolume = async (args: GetApiV1StocksTickerShortVolumeArgs, options?: GetApiV1StocksTickerShortVolumeOptions) => { const {baseUrl = "https://api.equibles.com", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.startDate != null) query.append("startDate", String(args.startDate)) if (args.endDate != null) query.append("endDate", String(args.endDate)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/stocks/${encodeURIComponent(String(args.ticker))}/short-volume${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(shortVolumeDtoPagedResponse, await res.json()) };