import {z} from 'zod' export type GetApiV1StocksTickerHoldersArgs = {ticker: string, limit?: number | undefined, offset?: number | undefined, source?: string | undefined, view?: string | undefined, holderTypes?: string | undefined}; export type GetApiV1StocksTickerHoldersOptions = {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 statedPurposeCategoryDto = z.object({token: z.string().nullable().optional(), name: z.string().nullable().optional(), quote: z.string().nullable().optional()}); export const statedPurposeDto = z.object({state: z.string().nullable().optional(), summary: z.string().nullable().optional(), categories: z.array(statedPurposeCategoryDto).nullable().optional()}); export const stockHolderDto: z.ZodType = z.object({name: z.string().nullable().optional(), source: z.string().nullable().optional(), idType: z.string().nullable().optional(), id: z.string().nullable().optional(), cik: z.string().nullable().optional(), seriesId: z.string().nullable().optional(), detail: z.string().nullable().optional(), holderType: z.string().nullable().optional(), style: z.string().nullable().optional(), country: z.string().nullable().optional(), shares: z.number().int().optional(), filedShares: z.number().optional(), value: z.number().int().nullable().optional(), changeShares: z.number().int().nullable().optional(), priorAsOf: z.string().nullable().optional(), percentOutstanding: z.number().nullable().optional(), filedPercentOfClass: z.number().nullable().optional(), votingRightsPercent: z.number().nullable().optional(), portfolioWeight: z.number().nullable().optional(), asOf: z.string().optional(), filingDate: z.string().nullable().optional(), accession: z.string().nullable().optional(), carried: z.boolean().optional(), stale: z.boolean().optional(), unconfirmed: z.boolean().optional(), splitUnresolved: z.boolean().optional(), issuerWide: z.boolean().optional(), notSummed: z.boolean().optional(), ultimateParentCik: z.string().nullable().optional(), ultimateParentLink: z.string().nullable().optional(), purpose: statedPurposeDto.optional(), childCount: z.number().int().optional(), children: z.array(z.lazy(() => stockHolderDto)).nullable().optional()}); export const ultimateHolderGroupDto = z.object({ultimateParentCik: z.string().nullable().optional(), name: z.string().nullable().optional(), shares: z.number().int().optional(), form13FShares: z.number().int().optional(), percentOutstanding: z.number().nullable().optional(), members: z.array(stockHolderDto).nullable().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 stockHoldersResponse = z.object({listingNotice: listingNotice.optional(), ticker: z.string().nullable().optional(), exactListing: z.boolean().optional(), reportDate: z.string().nullable().optional(), carriedFrom: z.string().nullable().optional(), view: z.string().nullable().optional(), source: z.string().nullable().optional(), sharesOutstanding: z.number().int().nullable().optional(), percentUnavailableReason: z.string().nullable().optional(), data: z.array(stockHolderDto).nullable().optional(), groups: z.array(ultimateHolderGroupDto).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 }; /** * Every disclosed holder of a stock or ETF listing in one list: 13F institutions, Schedule 13D * and 13G filers, insiders (Forms 3, 4 and 5, primary listing only), registered funds (each * series' latest N-PORT) and non-US disclosures. view=default gives one row per holder from its * freshest filing, with its other filings and the 13D/G, insider and fund disclosures its 13F * report holds nested under it, matched by CIK and SEC reporting links, never by name; zero * balances, insider filings older than 24 months and 13D/G filings older than the 13F quarter * that covers them are hidden. view=all, or a source filter, lists every row flat with stale * ones flagged. view=ultimate groups the summed holders under their ultimate parent. Shares are * restated onto today's split basis and change compares each row with the same holder's * previous filing in the same source. * * GET /v1/stocks/{ticker}/holders */ export const getApiV1StocksTickerHolders = async (args: GetApiV1StocksTickerHoldersArgs, options?: GetApiV1StocksTickerHoldersOptions) => { 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.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.source != null) query.append("source", String(args.source)) if (args.view != null) query.append("view", String(args.view)) if (args.holderTypes != null) query.append("holderTypes", String(args.holderTypes)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/stocks/${encodeURIComponent(String(args.ticker))}/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(stockHoldersResponse, await res.json()) };