Skip to content

SecurityExchangeHours

QuantConnect.Securities.SecurityExchangeHours

SecurityExchangeHours(
    time_zone: Any,
    holiday_dates: List[datetime],
    market_hours_for_each_day_of_week: Dictionary[
        DayOfWeek, LocalMarketHours
    ],
    early_closes: IReadOnlyDictionary[datetime, timedelta],
    late_opens: IReadOnlyDictionary[datetime, timedelta],
    bank_holiday_dates: List[datetime] = None,
)

Bases: Object

Represents the schedule of a security exchange. This includes daily regular and extended market hours as well as holidays, early closes and late opens.

Initializes a new instance of the SecurityExchangeHours class

Parameters:

Name Type Description Default
time_zone Any

The time zone the dates and hours are represented in

required
holiday_dates List[datetime]

The dates this exchange is closed for holiday

required
market_hours_for_each_day_of_week Dictionary[DayOfWeek, LocalMarketHours]

The exchange's schedule for each day of the week

required
early_closes IReadOnlyDictionary[datetime, timedelta]

The dates this exchange has an early close

required
late_opens IReadOnlyDictionary[datetime, timedelta]

The dates this exchange has a late open

required

time_zone

time_zone: Any

Gets the time zone this exchange resides in

holidays

holidays: HashSet[datetime]

Gets the holidays for the exchange

bank_holidays

bank_holidays: HashSet[datetime]

Gets the bank holidays for the exchange

market_hours

market_hours: IReadOnlyDictionary[
    DayOfWeek, LocalMarketHours
]

Gets the market hours for this exchange

early_closes

early_closes: IReadOnlyDictionary[datetime, timedelta]

Gets the early closes for this exchange

late_opens

late_opens: IReadOnlyDictionary[datetime, timedelta]

Gets the late opens for this exchange

regular_market_duration

regular_market_duration: timedelta

Gets the most common tradable time during the market week. For a normal US equity trading day this is 6.5 hours. This does NOT account for extended market hours and only considers MARKETHoursState.MARKET

is_market_always_open

is_market_always_open: bool

Checks whether the market is always open or not

get_next_market_close

get_next_market_close(
    local_date_time: Union[datetime, date],
    extended_market_hours: bool,
) -> datetime
get_next_market_close(
    local_date_time: Union[datetime, date],
    extended_market_hours: bool,
    last_close: bool,
) -> datetime

Gets the local date time corresponding to the next market close following the specified time

Parameters:

Name Type Description Default
local_date_time Union[datetime, date]

The time to begin searching for market close (non-inclusive)

required
extended_market_hours bool

True to include extended market hours in the search

required
last_close Optional[bool]

True if the last available close of the date should be returned, else the first will be used

None

Returns:

Type Description
datetime

The next market closing date time following the specified local date time.

get_previous_market_open

get_previous_market_open(
    local_date_time: Union[datetime, date],
    extended_market_hours: bool,
) -> datetime
get_previous_market_open(
    local_date_time: Union[datetime, date],
    extended_market_hours: bool,
    first_open: bool,
) -> datetime

Gets the local date time corresponding to the previous market open to the specified time

Parameters:

Name Type Description Default
local_date_time Union[datetime, date]

The time to begin searching for the last market open (non-inclusive)

required
extended_market_hours bool

True to include extended market hours in the search

required

Returns:

Type Description
datetime

The previous market opening date time to the specified local date time.

is_open

is_open(
    local_date_time: Union[datetime, date],
    extended_market_hours: bool,
) -> bool
is_open(
    start_local_date_time: Union[datetime, date],
    end_local_date_time: Union[datetime, date],
    extended_market_hours: bool,
) -> bool

Signature descriptions:

  • Determines if the exchange is open at the specified local date time.

  • Determines if the exchange is open at any point in time over the specified interval.

Parameters:

Name Type Description Default
local_date_time Optional[Union[datetime, date]]

The time to check represented as a local time

None
extended_market_hours bool

True to use the extended market hours, false for just regular market hours

required
start_local_date_time Optional[Union[datetime, date]]

The start of the interval in local time

None
end_local_date_time Optional[Union[datetime, date]]

The end of the interval in local time

None

Returns:

Type Description
bool

True if the exchange is considered open at the specified time, false otherwise.

always_open

always_open(time_zone: Any) -> SecurityExchangeHours

Gets a SecurityExchangeHours instance that is always open

get_first_daily_market_open

get_first_daily_market_open(
    local_date_time: Union[datetime, date],
    extended_market_hours: bool,
) -> datetime

Gets the local date time corresponding to the first market open to the specified previous date

Parameters:

Name Type Description Default
local_date_time Union[datetime, date]

The time to begin searching for the last market open (non-inclusive)

required
extended_market_hours bool

True to include extended market hours in the search

required

Returns:

Type Description
datetime

The previous market opening date time to the specified local date time.

get_last_daily_market_close

get_last_daily_market_close(
    local_date_time: Union[datetime, date],
    extended_market_hours: bool,
) -> datetime

Gets the local date time corresponding to the last market close following the specified date

Parameters:

Name Type Description Default
local_date_time Union[datetime, date]

The time to begin searching for market close (non-inclusive)

required
extended_market_hours bool

True to include extended market hours in the search

required

Returns:

Type Description
datetime

The next market closing date time following the specified local date time.

get_market_hours

get_market_hours(
    local_date_time: Union[datetime, date],
) -> LocalMarketHours

Helper to access the market hours field based on the day of week

Parameters:

Name Type Description Default
local_date_time Union[datetime, date]

The local date time to retrieve market hours for

required

get_next_market_open

get_next_market_open(
    local_date_time: Union[datetime, date],
    extended_market_hours: bool,
) -> datetime

Gets the local date time corresponding to the next market open following the specified time

Parameters:

Name Type Description Default
local_date_time Union[datetime, date]

The time to begin searching for market open (non-inclusive)

required
extended_market_hours bool

True to include extended market hours in the search

required

Returns:

Type Description
datetime

The next market opening date time following the specified local date time.

get_next_trading_day

get_next_trading_day(
    date: Union[datetime, date],
) -> datetime

Gets the next trading day

Parameters:

Name Type Description Default
date Union[datetime, date]

The date to start searching at

required

Returns:

Type Description
datetime

The next trading day.

get_previous_trading_day

get_previous_trading_day(
    local_date: Union[datetime, date],
) -> datetime

Gets the previous trading day

Parameters:

Name Type Description Default
local_date Union[datetime, date]

The date to start searching at in this exchange's time zones

required

Returns:

Type Description
datetime

The previous trading day.

is_date_open

is_date_open(
    local_date_time: Union[datetime, date],
    extended_market_hours: bool = False,
) -> bool

Determines if the exchange will be open on the date specified by the local date time

Parameters:

Name Type Description Default
local_date_time Union[datetime, date]

The date time to check if the day is open

required
extended_market_hours bool

True to consider days with extended market hours only as open

False

Returns:

Type Description
bool

True if the exchange will be open on the specified date, false otherwise.