export type GetApiApiCalendarExchangeArgs = {api_key: string, mic: string, date?: string | undefined, format?: ('json' | 'xml') | undefined, callback?: string | undefined}; export type GetApiApiCalendarExchangeOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Is an exchange open on a given date, or right now? Returns the session open/close (local exchange time and UTC), lunch breaks, early closes / late opens, the holiday name when closed, and the previous/next trading days. Omit `date` for live status (`is_open_now`, `next_open_utc`, `next_close_utc`, evaluated in the exchange's own timezone). Computed from the open-source exchange_calendars rule set - reference only. Every answer carries `holiday_data_available`, `holiday_data_available_through` (the last date with published holiday data; null = rule-based calendar with no fixed end) and `warning`. A few exchanges with lunar-calendar holidays (e.g. XSHG, XBOM, XSES) only have holiday data to a fixed date (see /api/calendar/exchanges); for a date AFTER it the endpoint still answers, best-effort: weekdays are treated as trading days with the exchange's regular session times (incl. lunch breaks), weekends as closed, dates the exchange closed on a weekday in each of the previous two years (fixed-date holidays such as 1 January) as closed; other public holidays (e.g. lunar-calendar ones) and early closes are NOT known, `holiday_data_available` is false and `warning` explains. The same applies to `is_open_now` / `next_open_utc` / `next_close_utc`. Pro subscription required. * * GET /api/calendar/exchange */ export const getApiApiCalendarExchange = async (args: GetApiApiCalendarExchangeArgs, options: GetApiApiCalendarExchangeOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "early_close") if (args.api_key != null) query.append("api_key", String(args.api_key)) if (args.mic != null) query.append("mic", String(args.mic)) if (args.date != null) query.append("date", String(args.date)) if (args.format != null) query.append("format", String(args.format)) if (args.callback != null) query.append("callback", String(args.callback)) const url = `${baseUrl.replace(/\/+$/, '')}/api/calendar/exchange${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 res.blob() };