import {z} from 'zod' export type GetApiV1SecuritiesTickerOwnershipSignalsArgs = {ticker: string, holders?: number | undefined, peers?: number | undefined}; export type GetApiV1SecuritiesTickerOwnershipSignalsOptions = {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 ownershipSignalsQuarterDto = z.object({reportDate: z.string().optional(), filers: z.number().int().optional(), shares: z.number().int().optional(), value: z.number().int().optional(), convictionHolders: z.number().int().optional(), convictionShare: z.number().nullable().optional(), holdersAboveFivePercent: z.number().int().optional(), averageWeight: z.number().nullable().optional(), medianWeight: z.number().nullable().optional(), crowding: z.number().nullable().optional(), crowdingPercentile: z.number().nullable().optional(), notRankedReason: z.string().nullable().optional(), crowdedHolders: z.number().int().optional(), privateFundAdviserOwnership: z.number().nullable().optional(), institutionalOwnership: z.number().nullable().optional(), institutionalOwnershipOfFloat: z.number().nullable().optional(), estimatedFreeFloat: z.number().int().nullable().optional(), sharesOutstanding: z.number().int().nullable().optional(), sharesOutstandingAsOf: z.string().nullable().optional(), sharesOutstandingBasis: z.string().nullable().optional(), insiderShares: z.number().int().nullable().optional(), outstandingUnavailableReason: z.string().nullable().optional(), herfindahl: z.number().nullable().optional(), topTenHolderShare: z.number().nullable().optional(), tenureUnderOneYear: z.number().nullable().optional(), tenureOneToThreeYears: z.number().nullable().optional(), tenureThreeYearsOrMore: z.number().nullable().optional(), tenureSinceCoverageStart: z.number().nullable().optional(), valueWeightedTenureQuarters: z.number().nullable().optional(), estimatedCostPerShare: z.number().nullable().optional(), estimatedCostCoverage: z.number().nullable().optional(), quarterEndPrice: z.number().nullable().optional(), estimatedCostGap: z.number().nullable().optional(), estimatedUnderwaterValueShare: z.number().nullable().optional(), activeLikeForLikeChange: z.number().nullable().optional(), topScoreNetBuyValue: z.number().nullable().optional(), topScoreBuyers: z.number().int().nullable().optional(), topScoreSellers: z.number().int().nullable().optional(), schedule13DFilers: z.number().int().optional(), schedule13GFilers: z.number().int().optional(), schedule13GQualifiedInstitutions: z.number().int().optional(), schedule13GPassiveInvestors: z.number().int().optional(), schedule13GExemptInvestors: z.number().int().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 convictionHolderDto = z.object({cik: z.string().nullable().optional(), name: z.string().nullable().optional(), holderType: z.string().nullable().optional(), style: z.string().nullable().optional(), shares: z.number().int().optional(), value: z.number().int().optional(), weight: z.number().optional(), bookValue: z.number().int().optional()}); export const ownershipSignalsResponse = z.object({listingNotice: listingNotice.optional(), ticker: z.string().nullable().optional(), current: ownershipSignalsQuarterDto.optional(), previous: ownershipSignalsQuarterDto.optional(), peersAsOf: z.string().nullable().optional(), peers: z.array(overlapPeerDto).nullable().optional(), convictionHolders: z.array(convictionHolderDto).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 }; /** * Who holds a stock and how, measured across every 13F filer's book for the newest closed * quarter, with the quarter before for trends: conviction, crowding (high-turnover filers and * private-fund advisers as a fraction of shares outstanding, with its percentile), ownership of * the estimated free float, holder concentration, how long holders have held it, the holders' * estimated average cost per share and the value held at an estimated loss, active holders' * like-for-like change, top-scored managers' net buying, Schedule 13D and 13G stakes on record, * the holder-overlap peers and the filers with the highest weight in the stock. Cost figures are * estimates from quarter average prices, never filed. Ratios are fractions. * * GET /v1/securities/{ticker}/ownership-signals */ export const getApiV1SecuritiesTickerOwnershipSignals = async (args: GetApiV1SecuritiesTickerOwnershipSignalsArgs, options?: GetApiV1SecuritiesTickerOwnershipSignalsOptions) => { 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.holders != null) query.append("holders", String(args.holders)) if (args.peers != null) query.append("peers", String(args.peers)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/securities/${encodeURIComponent(String(args.ticker))}/ownership-signals${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(ownershipSignalsResponse, await res.json()) };