import {z} from 'zod' export type GetApiV1InsiderSentimentScoresArgs = {clusterBuysOnly?: boolean | undefined, minMarketCap?: number | undefined, minSharePrice?: number | undefined, minDollarVolume?: number | undefined, limit?: number | undefined, offset?: number | undefined, bottom?: boolean | undefined, ticker?: string | undefined}; export type GetApiV1InsiderSentimentScoresOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const insiderSentimentScoreDto = z.object({rank: z.number().int().optional(), ticker: z.string().nullable().optional(), score: z.number().optional(), distinctBuyers: z.number().int().optional(), distinctSellers: z.number().int().optional(), netDistinctBuyers: z.number().int().optional(), netSharesBoughtPercentOfShares: z.number().nullable().optional(), netBuyValue: z.number().nullable().optional(), isClusterBuy: z.boolean().optional(), marketCapUsd: z.number().nullable().optional(), sharePriceUsd: z.number().nullable().optional(), averageDollarVolume3MonthUsd: z.number().nullable().optional(), netDistinctBuyersPercentile: z.number().optional(), netSharesBoughtPercentile: z.number().nullable().optional(), netBuyValuePercentile: z.number().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 insiderSentimentScoresResponse = z.object({windowDays: z.number().int().optional(), totalScored: z.number().int().optional(), data: z.array(insiderSentimentScoreDto).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 }; /** * Stocks ranked by composite insider-sentiment score — a peer-relative 0-100 measure of how aggressively insiders are accumulating over a trailing 90-day window, from open-market Forms 4/5 buys and sells by officers and directors (a holder that is only a 10% owner is excluded). Highest score first. Rank reflects the full scored universe and does not renumber when liquidity filters are applied. Pass ticker for one stock's score and universe rank (the other filters do not apply then). * * GET /v1/insider-sentiment-scores */ export const getApiV1InsiderSentimentScores = async (args: GetApiV1InsiderSentimentScoresArgs, options?: GetApiV1InsiderSentimentScoresOptions) => { 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.clusterBuysOnly != null) query.append("clusterBuysOnly", String(args.clusterBuysOnly)) if (args.minMarketCap != null) query.append("minMarketCap", String(args.minMarketCap)) if (args.minSharePrice != null) query.append("minSharePrice", String(args.minSharePrice)) if (args.minDollarVolume != null) query.append("minDollarVolume", String(args.minDollarVolume)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.bottom != null) query.append("bottom", String(args.bottom)) if (args.ticker != null) query.append("ticker", String(args.ticker)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/insider-sentiment-scores${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(insiderSentimentScoresResponse, await res.json()) };