Skip to content

LocalMarketHours

QuantConnect.Securities.LocalMarketHours

LocalMarketHours(
    day: DayOfWeek,
    *segments: Union[
        MarketHoursSegment, Iterable[MarketHoursSegment]
    ]
)
LocalMarketHours(
    day: DayOfWeek, segments: List[MarketHoursSegment]
)
LocalMarketHours(
    day: DayOfWeek,
    extended_market_open: timedelta,
    market_open: timedelta,
    market_close: timedelta,
    extended_market_close: timedelta,
)
LocalMarketHours(
    day: DayOfWeek,
    market_open: timedelta,
    market_close: timedelta,
)

Bases: Object

Represents the market hours under normal conditions for an exchange and a specific day of the week in terms of local time

Signature descriptions:

  • Initializes a new instance of the LocalMarketHours class

  • Initializes a new instance of the LocalMarketHours class from the specified open/close times

  • Initializes a new instance of the LocalMarketHours class from the specified open/close times using the market open as the extended market open and the market close as the extended market close, effectively removing any 'extended' session from these exchange hours

Parameters:

Name Type Description Default
day DayOfWeek

The day of the week these hours are applicable

required
segments Union[MarketHoursSegment, Iterable[MarketHoursSegment]]

The open/close segments defining the market hours for one day

()
extended_market_open Optional[timedelta]

The extended market open time

None
market_open Optional[timedelta]

The regular market open time, must be greater than or equal to the extended market open time

None
market_close Optional[timedelta]

The regular market close time, must be greater than the regular market open time

None
extended_market_close Optional[timedelta]

The extended market close time, must be greater than or equal to the regular market close time

None

is_closed_all_day

is_closed_all_day: bool

Gets whether or not this exchange is closed all day

is_open_all_day

is_open_all_day: bool

Gets whether or not this exchange is closed all day

day_of_week

day_of_week: DayOfWeek

Gets the day of week these hours apply to

market_duration

market_duration: timedelta

Gets the tradable time during the market day. 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

segments

segments: ReadOnlyCollection[MarketHoursSegment]

Gets the individual market hours segments that define the hours of operation for this day

get_market_close

get_market_close(
    time: timedelta,
    extended_market_hours: bool,
    next_day_segment_start: Optional[timedelta] = None,
) -> Optional[timedelta]
get_market_close(
    time: timedelta,
    extended_market_hours: bool,
    last_close: bool,
    next_day_segment_start: Optional[timedelta] = None,
) -> Optional[timedelta]

Gets the market closing time of day

Parameters:

Name Type Description Default
time timedelta

The reference time, the close returned will be the first close after the specified time if there are multiple market open segments

required
extended_market_hours bool

True to include extended market hours, false for regular market hours

required
next_day_segment_start Optional[timedelta]

Next day first segment start. This is used when the potential next market close is

None
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
Optional[timedelta]

The market's closing time of day.

is_open

is_open(
    time: timedelta, extended_market_hours: bool
) -> bool
is_open(
    start: timedelta,
    end: timedelta,
    extended_market_hours: bool,
) -> bool

Signature descriptions:

  • Determines if the exchange is open at the specified time

  • Determines if the exchange is open during the specified interval

Parameters:

Name Type Description Default
time Optional[timedelta]

The time of day to check

None
extended_market_hours bool

True to check exended market hours, false to check regular market hours

required
start Optional[timedelta]

The start time of the interval

None
end Optional[timedelta]

The end time of the interval

None

Returns:

Type Description
bool

True if the exchange is considered open, false otherwise.

closed_all_day

closed_all_day(day_of_week: DayOfWeek) -> LocalMarketHours

Gets a LocalMarketHours instance that is always closed

Parameters:

Name Type Description Default
day_of_week DayOfWeek

The day of week

required

Returns:

Type Description
LocalMarketHours

A LocalMarketHours instance that is always closed.

get_market_open

get_market_open(
    time: timedelta,
    extended_market_hours: bool,
    previous_day_last_segment: Optional[timedelta] = None,
) -> Optional[timedelta]

Gets the market opening time of day

Parameters:

Name Type Description Default
time timedelta

The reference time, the open returned will be the first open after the specified time if there are multiple market open segments

required
extended_market_hours bool

True to include extended market hours, false for regular market hours

required
previous_day_last_segment Optional[timedelta]

The previous days last segment. This is used when the potential next market open is the first segment of the day so we need to check that segment is not part of previous day last segment. If null, it means there were no segments on the last day

None

Returns:

Type Description
Optional[timedelta]

The market's opening time of day.

is_continuous_market_open

is_continuous_market_open(
    previous_segment_end: Optional[timedelta],
    next_segment_start: Optional[timedelta],
    prev_segment_is_from_prev_day: bool = True,
) -> bool

Check the given segment is not part of the current previous segment

Parameters:

Name Type Description Default
previous_segment_end Optional[timedelta]

Previous segment end time before the current segment

required
next_segment_start Optional[timedelta]

The next segment start time

required
prev_segment_is_from_prev_day bool

Indicated whether the previous segment is from the previous day or not (then it is from the same day as the next segment). Defaults to true

True

Returns:

Type Description
bool

True if indeed the given segment is part of the last segment. False otherwise.

open_all_day

open_all_day(day_of_week: DayOfWeek) -> LocalMarketHours

Gets a LocalMarketHours instance that is always open

Parameters:

Name Type Description Default
day_of_week DayOfWeek

The day of week

required

Returns:

Type Description
LocalMarketHours

A LocalMarketHours instance that is always open.

to_string

to_string() -> str

Returns a string that represents the current object.

Returns:

Type Description
str

A string that represents the current object.