import {z} from 'zod' export type ResponseFormat = 'json' | 'csv' | 'csv_gzip'; export type GetApiV1DataUsEquityOptRefOccInfoMemosArgs = {sort?: (string | null) | undefined, columns?: (string | null) | undefined, offset?: number | undefined, limit?: number | undefined, response_format?: ResponseFormat | undefined}; export type GetApiV1DataUsEquityOptRefOccInfoMemosOptions = {baseUrl?: string | undefined, APIKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const oCCInformationMemosDataDetailsOut = z.object({MemoId: z.number().int().nullable().optional(), PublishDate: z.string().nullable().optional(), EffectiveDate: z.string().nullable().optional(), SymbolChangeDate: z.array(z.string()).nullable().optional(), OldSymbol: z.array(z.string()).nullable().optional(), NewSymbol: z.array(z.string()).nullable().optional(), SymbolAssetType: z.array(z.string()).nullable().optional(), SymbolChangeDetail: z.string().nullable().optional(), StrikeDivisor: z.number().int().nullable().optional(), StrikeAdjustment: z.number().nullable().optional(), MultiplierDetail: z.string().nullable().optional(), Multiplier: z.number().int().nullable().optional(), Deliverables: z.array(z.string()).nullable().optional(), UnderSymbolCUSIP: z.array(z.string()).nullable().optional()}); export const paginationDetailsOut = z.object({offset: z.number().int().optional(), limit: z.number().int(), next_offset: z.number().int().nullable().optional()}); export const oCCInformationMemosDataOut = z.object({data: z.array(oCCInformationMemosDataDetailsOut), pagination: paginationDetailsOut}); 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 }; /** * OCC Information Memos * * GET /v1/data/us-equity-opt-ref/occ-info-memos */ export const getApiV1DataUsEquityOptRefOccInfoMemos = async (args: GetApiV1DataUsEquityOptRefOccInfoMemosArgs, options?: GetApiV1DataUsEquityOptRefOccInfoMemosOptions) => { const {baseUrl = "https://api.algoseek.com", fetch: fetchFn = fetch, APIKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.sort != null) query.append("sort", String(args.sort)) if (args.columns != null) query.append("columns", String(args.columns)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.response_format != null) query.append("response_format", String(args.response_format)) if (APIKeyAuth !== undefined) headers.set("X-API-KEY", APIKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/data/us-equity-opt-ref/occ-info-memos${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(oCCInformationMemosDataOut, await res.json()) };