import {z} from 'zod' export type GetApiV1SecuritiesTickerQuoteArgs = {ticker: string}; export type GetApiV1SecuritiesTickerQuoteOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const liveQuoteDto = z.object({ticker: z.string().nullable().optional(), currency: z.string().nullable().optional(), price: z.number().nullable().optional(), bidPrice: z.number().nullable().optional(), askPrice: z.number().nullable().optional(), asOf: z.string().optional(), sessionDate: z.string().optional(), expectedSessionDate: z.string().optional(), stale: z.boolean().optional(), ageSeconds: z.number().int().optional(), delayed: z.boolean().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 }; /** * Latest available intraday quote for one active U.S. listing (consolidated SIP) or one listing named as MIC:TICKER on a Canadian exchange (XTSE, XTSX, XCNQ, NEOE) or a Euronext exchange (XPAR, XAMS, XBRU, XMSM, XOSL, MTAA, XLIS) — a market reading, not a daily bar. Requires a paid plan: for U.S. listings Pro receives real-time trade and bid/ask and Plus the same fields 15 minutes delayed; for Canadian listings both receive the last price in the listing's currency, real time on XTSE and XTSX and 15 minutes behind on XCNQ and NEOE (delayed=true), and for Euronext listings both receive the last trade 15 minutes behind (delayed=true); neither carries bid/ask. Free receives 403 because it covers end-of-day data only. SessionDate and ExpectedSessionDate identify the market sessions involved; Stale is true when the reading predates the expected session, so an old print is never silently presented as current. Use /v1/stocks/{ticker}/prices for stored traded daily history when available. * * GET /v1/securities/{ticker}/quote */ export const getApiV1SecuritiesTickerQuote = async (args: GetApiV1SecuritiesTickerQuoteArgs, options?: GetApiV1SecuritiesTickerQuoteOptions) => { 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 (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/securities/${encodeURIComponent(String(args.ticker))}/quote${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(liveQuoteDto, await res.json()) };