import {z} from 'zod' export type GetApiV1SecuritiesTickerInstitutionalHoldersArgs = {ticker: string, reportDate?: string | undefined, limit?: number | undefined, offset?: number | undefined, holderTypes?: string | undefined, styles?: string | undefined}; export type GetApiV1SecuritiesTickerInstitutionalHoldersOptions = {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 topHolderDto = z.object({name: z.string().nullable().optional(), cik: z.string().nullable().optional(), shares: z.number().int().optional(), value: z.number().int().optional(), percentOfTotal: z.number().optional(), listedTicker: z.string().nullable().optional(), positionType: z.string().nullable().optional(), holderType: z.string().nullable().optional(), style: z.string().nullable().optional()}); export const topHoldersMeta = z.object({reportDate: z.string().optional(), isCombinedQuarter: z.boolean().optional(), totalInstitutions: z.number().int().optional(), totalShares: z.number().int().optional(), totalValue: z.number().int().optional(), styleReportDate: z.string().nullable().optional(), matchingRows: z.number().int().nullable().optional(), matchingInstitutions: z.number().int().nullable().optional(), 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 topHoldersResponse = z.object({listingNotice: listingNotice.optional(), data: z.array(topHolderDto).nullable().optional(), meta: topHoldersMeta.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 }; /** * Top institutional holders (13F filers) of an exact stock or ETF listing, ranked by reported quantity. A row's * quantity is common shares, an option position's notional underlying shares, or a * principal amount, so the total is aggregate 13F exposure rather than pure ownership. * While the newest quarter's 13F filing window is open, non-ETF primary stocks use the * combined view (new filings + prior-quarter carry-forward); ETF listings remain exact and * as-filed because carry-forward is filer-wide. Share counts are restated onto today's basis. * Each row carries the holder's entity type from regulatory records, never from its name, and its * style band measured from its filed 13F book in one quarter for every row. * * GET /v1/securities/{ticker}/institutional-holders */ export const getApiV1SecuritiesTickerInstitutionalHolders = async (args: GetApiV1SecuritiesTickerInstitutionalHoldersArgs, options?: GetApiV1SecuritiesTickerInstitutionalHoldersOptions) => { 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.reportDate != null) query.append("reportDate", String(args.reportDate)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.holderTypes != null) query.append("holderTypes", String(args.holderTypes)) if (args.styles != null) query.append("styles", String(args.styles)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/securities/${encodeURIComponent(String(args.ticker))}/institutional-holders${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(topHoldersResponse, await res.json()) };