import {z} from 'zod' export type GetApiV1ShortVolumeLargestArgs = {date?: string | undefined, minShortVolume?: number | undefined, sortBy?: string | undefined, minTotalVolume?: number | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiV1ShortVolumeLargestOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const largestShortVolumeDto = z.object({ticker: z.string().nullable().optional(), name: z.string().nullable().optional(), shortVolume: z.number().int().optional(), shortExemptVolume: z.number().int().optional(), totalVolume: z.number().int().optional(), shortVolumePercent: z.number().optional()}); export const largestShortVolumeResponse = z.object({date: z.string().nullable().optional(), data: z.array(largestShortVolumeDto).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 }; /** * Exact stock and ETF listings with the largest daily short volume for a single trading day, sorted by short volume descending by default. Volumes cover FINRA-reported off-exchange facility trades only, so a 40-50% short percentage is the normal baseline. Pass sortBy=shortPercent with a minTotalVolume floor to rank by short intensity instead of raw size. * * GET /v1/short-volume/largest */ export const getApiV1ShortVolumeLargest = async (args: GetApiV1ShortVolumeLargestArgs, options?: GetApiV1ShortVolumeLargestOptions) => { 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.date != null) query.append("date", String(args.date)) if (args.minShortVolume != null) query.append("minShortVolume", String(args.minShortVolume)) if (args.sortBy != null) query.append("sortBy", String(args.sortBy)) if (args.minTotalVolume != null) query.append("minTotalVolume", String(args.minTotalVolume)) 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/short-volume/largest${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(largestShortVolumeResponse, await res.json()) };