import {z} from 'zod' export type GetApiV1SecuritiesTickerHolderTargetsArgs = {ticker: string, limit?: number | undefined, offset?: number | undefined, sort?: string | undefined}; export type GetApiV1SecuritiesTickerHolderTargetsOptions = {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 overlapPeerDto = z.object({rank: z.number().int().optional(), ticker: z.string().nullable().optional(), company: z.string().nullable().optional(), sharedHolders: z.number().int().optional(), similarity: z.number().optional()}); export const holderTargetDto = z.object({rank: z.number().int().optional(), cik: z.string().nullable().optional(), name: z.string().nullable().optional(), holderType: z.string().nullable().optional(), style: z.string().nullable().optional(), peerValue: z.number().int().optional(), peerWeight: z.number().optional(), peersHeld: z.number().int().optional(), topPeers: z.array(z.string()).nullable().optional(), bookValue: z.number().int().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 holderTargetsResponse = z.object({listingNotice: listingNotice.optional(), ticker: z.string().nullable().optional(), reportDate: z.string().nullable().optional(), sort: z.string().nullable().optional(), sectorFallback: z.boolean().optional(), sector: z.string().nullable().optional(), peers: z.array(overlapPeerDto).nullable().optional(), data: z.array(holderTargetDto).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 }; /** * Shareholder targeting: the 13F filers of the newest closed quarter that hold the stock's * holder-overlap peers (stocks whose active holders overlap most) but no class of the stock * itself, ranked by dollars held in the peers or by the peers' share of the filer's book. A * stock with no overlap peers falls back to its sector's largest 13F holdings (sectorFallback). * Each target carries its 13F book, holder type from regulatory records and measured style. * * GET /v1/securities/{ticker}/holder-targets */ export const getApiV1SecuritiesTickerHolderTargets = async (args: GetApiV1SecuritiesTickerHolderTargetsArgs, options?: GetApiV1SecuritiesTickerHolderTargetsOptions) => { 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.sort != null) query.append("sort", String(args.sort)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/securities/${encodeURIComponent(String(args.ticker))}/holder-targets${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(holderTargetsResponse, await res.json()) };