import {z} from 'zod' export type GetApiV1StocksTickerOptionsSummaryArgs = {ticker: string, expiration?: string | undefined}; export type GetApiV1StocksTickerOptionsSummaryOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const optionExpectedMoveDto = z.object({strike: z.number().optional(), callMid: z.number().optional(), putMid: z.number().optional(), amount: z.number().optional(), percentOfClose: z.number().nullable().optional()}); export const optionSkewDto = z.object({putStrike: z.number().optional(), putDelta: z.number().optional(), putImpliedVolatility: z.number().optional(), callStrike: z.number().optional(), callDelta: z.number().optional(), callImpliedVolatility: z.number().optional(), spread: z.number().optional()}); export const optionGammaStrikeDto = z.object({strike: z.number().optional(), grossGammaShares: z.number().nullable().optional()}); export const optionHighVolumeContractDto = z.object({occTicker: z.string().nullable().optional(), contractType: z.string().nullable().optional(), strikePrice: z.number().optional(), volume: z.number().int().optional(), volumeDate: z.string().nullable().optional(), openInterest: z.number().int().optional(), openInterestDate: z.string().nullable().optional(), volumeToOpenInterest: z.number().optional()}); export const optionSummaryResponse = z.object({ticker: z.string().nullable().optional(), companyName: z.string().nullable().optional(), expiration: z.string().optional(), underlyingClose: z.number().nullable().optional(), underlyingCloseDate: z.string().nullable().optional(), contracts: z.number().int().optional(), truncated: z.boolean().optional(), delayed: z.boolean().optional(), openInterestDate: z.string().nullable().optional(), volumeSession: z.string().nullable().optional(), totalCallOpenInterest: z.number().int().optional(), totalPutOpenInterest: z.number().int().optional(), totalCallVolume: z.number().int().optional(), totalPutVolume: z.number().int().optional(), putCallOpenInterestRatio: z.number().nullable().optional(), putCallVolumeRatio: z.number().nullable().optional(), maxPainStrike: z.number().nullable().optional(), atmImpliedVolatility: z.number().nullable().optional(), expectedMove: optionExpectedMoveDto.optional(), skew: optionSkewDto.optional(), gammaByStrike: z.array(optionGammaStrikeDto).nullable().optional(), highVolumeContracts: z.array(optionHighVolumeContractDto).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 }; /** * One expiration's positioning, computed from the live chain: open interest and volume by side with put/call ratios, max pain, at-the-money implied volatility, the at-the-money straddle's mid as a market-implied expected move, 25-delta skew, unsigned gross gamma by strike, and the contracts trading heaviest against their open interest. Defaults to the nearest upcoming expiration. A figure that needs the whole chain or one open-interest date is null rather than computed over part of it. Nothing here is a forecast, and gamma carries no dealer sign. Pro reads real-time quotes and Plus delayed indicative quotes; the Free plan covers end-of-day data only and receives 403. US listings only. * * GET /v1/stocks/{ticker}/options/summary */ export const getApiV1StocksTickerOptionsSummary = async (args: GetApiV1StocksTickerOptionsSummaryArgs, options?: GetApiV1StocksTickerOptionsSummaryOptions) => { 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.expiration != null) query.append("expiration", String(args.expiration)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/stocks/${encodeURIComponent(String(args.ticker))}/options/summary${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(optionSummaryResponse, await res.json()) };