Lean  $LEAN_TAG$
QuantConnect.Securities.SecurityExchangeHours Class Reference

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

Public Member Functions

 SecurityExchangeHours (DateTimeZone timeZone, IEnumerable< DateTime > holidayDates, Dictionary< DayOfWeek, LocalMarketHours > marketHoursForEachDayOfWeek, IReadOnlyDictionary< DateTime, TimeSpan > earlyCloses, IReadOnlyDictionary< DateTime, TimeSpan > lateOpens)
 Initializes a new instance of the SecurityExchangeHours class More...
 
bool IsOpen (DateTime localDateTime, bool extendedMarketHours)
 Determines if the exchange is open at the specified local date time. More...
 
bool IsOpen (DateTime startLocalDateTime, DateTime endLocalDateTime, bool extendedMarketHours)
 Determines if the exchange is open at any point in time over the specified interval. More...
 
bool IsDateOpen (DateTime localDateTime, bool extendedMarketHours=false)
 Determines if the exchange will be open on the date specified by the local date time More...
 
DateTime GetPreviousMarketOpen (DateTime localDateTime, bool extendedMarketHours)
 Gets the local date time corresponding to the previous market open to the specified time More...
 
DateTime GetNextMarketOpen (DateTime localDateTime, bool extendedMarketHours)
 Gets the local date time corresponding to the next market open following the specified time More...
 
DateTime GetNextMarketClose (DateTime localDateTime, bool extendedMarketHours)
 Gets the local date time corresponding to the next market close following the specified time More...
 
LocalMarketHours GetMarketHours (DateTime localDateTime)
 Helper to access the market hours field based on the day of week More...
 
DateTime GetPreviousTradingDay (DateTime localDate)
 Gets the previous trading day More...
 
DateTime GetNextTradingDay (DateTime date)
 Gets the next trading day More...
 

Static Public Member Functions

static SecurityExchangeHours AlwaysOpen (DateTimeZone timeZone)
 Gets a SecurityExchangeHours instance that is always open More...
 

Public Attributes

IReadOnlyDictionary< DayOfWeek, LocalMarketHoursMarketHours => _openHoursByDay
 Gets the market hours for this exchange More...
 
IReadOnlyDictionary< DateTime, TimeSpan > EarlyCloses => _earlyCloses
 Gets the early closes for this exchange More...
 
IReadOnlyDictionary< DateTime, TimeSpan > LateOpens => _lateOpens
 Gets the late opens for this exchange More...
 

Properties

DateTimeZone TimeZone [get]
 Gets the time zone this exchange resides in More...
 
HashSet< DateTime > Holidays [get]
 Gets the holidays for the exchange More...
 
TimeSpan RegularMarketDuration [get]
 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 More...
 
bool IsMarketAlwaysOpen [get]
 Checks whether the market is always open or not More...
 

Detailed Description

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

This type assumes that IsOpen will be called with increasingly future times, that is, the calls should never back track in time. This assumption is required to prevent time zone conversions on every call.

Definition at line 33 of file SecurityExchangeHours.cs.

Constructor & Destructor Documentation

◆ SecurityExchangeHours()

QuantConnect.Securities.SecurityExchangeHours.SecurityExchangeHours ( DateTimeZone  timeZone,
IEnumerable< DateTime >  holidayDates,
Dictionary< DayOfWeek, LocalMarketHours marketHoursForEachDayOfWeek,
IReadOnlyDictionary< DateTime, TimeSpan >  earlyCloses,
IReadOnlyDictionary< DateTime, TimeSpan >  lateOpens 
)

Initializes a new instance of the SecurityExchangeHours class

Parameters
timeZoneThe time zone the dates and hours are represented in
holidayDatesThe dates this exchange is closed for holiday
marketHoursForEachDayOfWeekThe exchange's schedule for each day of the week
earlyClosesThe dates this exchange has an early close
lateOpensThe dates this exchange has a late open

Definition at line 126 of file SecurityExchangeHours.cs.

Here is the caller graph for this function:

Member Function Documentation

◆ AlwaysOpen()

static SecurityExchangeHours QuantConnect.Securities.SecurityExchangeHours.AlwaysOpen ( DateTimeZone  timeZone)
static

Gets a SecurityExchangeHours instance that is always open

Definition at line 107 of file SecurityExchangeHours.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsOpen() [1/2]

bool QuantConnect.Securities.SecurityExchangeHours.IsOpen ( DateTime  localDateTime,
bool  extendedMarketHours 
)

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

Parameters
localDateTimeThe time to check represented as a local time
extendedMarketHoursTrue to use the extended market hours, false for just regular market hours
Returns
True if the exchange is considered open at the specified time, false otherwise

Definition at line 162 of file SecurityExchangeHours.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsOpen() [2/2]

bool QuantConnect.Securities.SecurityExchangeHours.IsOpen ( DateTime  startLocalDateTime,
DateTime  endLocalDateTime,
bool  extendedMarketHours 
)

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

Parameters
startLocalDateTimeThe start of the interval in local time
endLocalDateTimeThe end of the interval in local time
extendedMarketHoursTrue to use the extended market hours, false for just regular market hours
Returns
True if the exchange is considered open at the specified time, false otherwise

Definition at line 175 of file SecurityExchangeHours.cs.

Here is the call graph for this function:

◆ IsDateOpen()

bool QuantConnect.Securities.SecurityExchangeHours.IsDateOpen ( DateTime  localDateTime,
bool  extendedMarketHours = false 
)

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

Parameters
localDateTimeThe date time to check if the day is open
extendedMarketHoursTrue to consider days with extended market hours only as open
Returns
True if the exchange will be open on the specified date, false otherwise

Definition at line 212 of file SecurityExchangeHours.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetPreviousMarketOpen()

DateTime QuantConnect.Securities.SecurityExchangeHours.GetPreviousMarketOpen ( DateTime  localDateTime,
bool  extendedMarketHours 
)

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

Parameters
localDateTimeThe time to begin searching for the last market open (non-inclusive)
extendedMarketHoursTrue to include extended market hours in the search
Returns
The previous market opening date time to the specified local date time

Definition at line 235 of file SecurityExchangeHours.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetNextMarketOpen()

DateTime QuantConnect.Securities.SecurityExchangeHours.GetNextMarketOpen ( DateTime  localDateTime,
bool  extendedMarketHours 
)

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

Parameters
localDateTimeThe time to begin searching for market open (non-inclusive)
extendedMarketHoursTrue to include extended market hours in the search
Returns
The next market opening date time following the specified local date time

Definition at line 276 of file SecurityExchangeHours.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetNextMarketClose()

DateTime QuantConnect.Securities.SecurityExchangeHours.GetNextMarketClose ( DateTime  localDateTime,
bool  extendedMarketHours 
)

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

Parameters
localDateTimeThe time to begin searching for market close (non-inclusive)
extendedMarketHoursTrue to include extended market hours in the search
Returns
The next market closing date time following the specified local date time

Definition at line 329 of file SecurityExchangeHours.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetMarketHours()

LocalMarketHours QuantConnect.Securities.SecurityExchangeHours.GetMarketHours ( DateTime  localDateTime)

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

Parameters
localDateTimeThe local date time to retrieve market hours for

This method will return an adjusted instance of LocalMarketHours for the specified date, that is, it will account for holidays, early closes, and late opens (e.g. if the security trades regularly on Mondays, but a specific Monday is a holiday, this method will return a LocalMarketHours that is closed all day). In order to get the regular schedule, use the MarketHours property.

Definition at line 447 of file SecurityExchangeHours.cs.

Here is the caller graph for this function:

◆ GetPreviousTradingDay()

DateTime QuantConnect.Securities.SecurityExchangeHours.GetPreviousTradingDay ( DateTime  localDate)

Gets the previous trading day

Parameters
localDateThe date to start searching at in this exchange's time zones
Returns
The previous trading day

Definition at line 576 of file SecurityExchangeHours.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetNextTradingDay()

DateTime QuantConnect.Securities.SecurityExchangeHours.GetNextTradingDay ( DateTime  date)

Gets the next trading day

Parameters
dateThe date to start searching at
Returns
The next trading day

Definition at line 592 of file SecurityExchangeHours.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ MarketHours

IReadOnlyDictionary<DayOfWeek, LocalMarketHours> QuantConnect.Securities.SecurityExchangeHours.MarketHours => _openHoursByDay

Gets the market hours for this exchange

This returns the regular schedule for each day, without taking into account special cases such as holidays, early closes, or late opens. In order to get the actual market hours for a specific date, use GetMarketHours(DateTime)

Definition at line 79 of file SecurityExchangeHours.cs.

◆ EarlyCloses

IReadOnlyDictionary<DateTime, TimeSpan> QuantConnect.Securities.SecurityExchangeHours.EarlyCloses => _earlyCloses

Gets the early closes for this exchange

Definition at line 84 of file SecurityExchangeHours.cs.

◆ LateOpens

IReadOnlyDictionary<DateTime, TimeSpan> QuantConnect.Securities.SecurityExchangeHours.LateOpens => _lateOpens

Gets the late opens for this exchange

Definition at line 89 of file SecurityExchangeHours.cs.

Property Documentation

◆ TimeZone

DateTimeZone QuantConnect.Securities.SecurityExchangeHours.TimeZone
get

Gets the time zone this exchange resides in

Definition at line 61 of file SecurityExchangeHours.cs.

◆ Holidays

HashSet<DateTime> QuantConnect.Securities.SecurityExchangeHours.Holidays
get

Gets the holidays for the exchange

Definition at line 67 of file SecurityExchangeHours.cs.

◆ RegularMarketDuration

TimeSpan QuantConnect.Securities.SecurityExchangeHours.RegularMarketDuration
get

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

Definition at line 97 of file SecurityExchangeHours.cs.

◆ IsMarketAlwaysOpen

bool QuantConnect.Securities.SecurityExchangeHours.IsMarketAlwaysOpen
get

Checks whether the market is always open or not

Definition at line 102 of file SecurityExchangeHours.cs.


The documentation for this class was generated from the following file: