Skip to content

@livefolio/sdk / ExchangeCalendar

Abstract Class: ExchangeCalendar

Defined in: calendars/exchange-calendar.ts:47

Abstract base class for exchange trading calendars. Implements the full Calendar interface by composing up to nine overridable hooks that subclasses provide. Concrete implementations ship for NYSEExchangeCalendar and LSEExchangeCalendar; additional exchanges can be added by extending this class.

Per-year caching: holiday sets and special-session maps are computed once per calendar year and stored in private Maps, so repeated calls to isOpen, next, or sessions within the same year are cheap.

Hook resolution order (adhoc beats rule, rule beats regular):

  1. adhocHolidays() / specialClosesAdhoc() / specialOpensAdhoc()YYYY-MM-DD string sets/maps populated once at first access.
  2. regularHolidays() / specialCloses() / specialOpens() — year-derived rule arrays applied per year via the resolver helpers.
  3. regularOpen(date) / regularClose(date) / weekmask(date) — per-date fallbacks that subclasses override to encode era-varying session times and trading-day sets.

Extending: override only the hooks you need. All hooks have no-op / sensible defaults (Mon–Fri weekmask, 09:30–16:00 session) so a minimal subclass need only set name, tz, and regularHolidays().

Extended by

Implements

Constructors

Constructor

new ExchangeCalendar(): ExchangeCalendar

Returns

ExchangeCalendar

Properties

PropertyModifierTypeDescriptionDefined in
nameabstractstringShort exchange name used as the registry key in getCalendar.calendars/exchange-calendar.ts:49
tzabstractstringIANA timezone identifier, e.g. 'America/New_York' or 'Europe/London'.calendars/exchange-calendar.ts:51

Methods

isEarlyClose()

isEarlyClose(t): boolean

Defined in: calendars/exchange-calendar.ts:262

Returns true if the exchange closes early on the day containing t. Common examples: Black Friday (US), Christmas Eve, New Year's Eve.

Parameters

ParameterTypeDescription
tDateThe instant or day to test.

Returns

boolean

Implementation of

Calendar.isEarlyClose


isOpen()

isOpen(t): boolean

Defined in: calendars/exchange-calendar.ts:215

Returns true when t falls on a regular trading day (weekmask check, then holiday check).

Parameters

ParameterType
tDate

Returns

boolean

Implementation of

Calendar.isOpen


next()

next(t): Date

Defined in: calendars/exchange-calendar.ts:225

Returns the first trading day strictly after t.

Parameters

ParameterType
tDate

Returns

Date

Implementation of

Calendar.next


previous()

previous(t): Date

Defined in: calendars/exchange-calendar.ts:232

Returns the first trading day strictly before t.

Parameters

ParameterType
tDate

Returns

Date

Implementation of

Calendar.previous


schedule()

schedule(range): readonly Session[]

Defined in: calendars/exchange-calendar.ts:253

Returns full Session records (date, open instant, close instant) for every trading day in the half-open interval [range.from, range.to).

Parameters

ParameterTypeDescription
rangeDateRangeHalf-open date range.

Returns

readonly Session[]

Ascending array of Session objects. Early-close days have a close earlier than the normal session close.

Implementation of

Calendar.schedule


sessions()

sessions(range): readonly Date[]

Defined in: calendars/exchange-calendar.ts:242

Returns UTC midnight Date objects for every trading day in [range.from, range.to). The from bound is inclusive; to is exclusive.

Parameters

ParameterType
rangeDateRange

Returns

readonly Date[]

Implementation of

Calendar.sessions

Released under the MIT License.