Lean  $LEAN_TAG$
QuantConnect.Securities.SecurityExchange Class Reference

Base exchange class providing information and helper tools for reading the current exchange situation More...

Inheritance diagram for QuantConnect.Securities.SecurityExchange:
[legend]

Public Member Functions

 SecurityExchange (SecurityExchangeHours exchangeHours)
 Initializes a new instance of the SecurityExchange class using the specified exchange hours to determine open/close times More...
 
void SetLocalDateTimeFrontierProvider (LocalTimeKeeper timeProvider)
 Set the current datetime in terms of the exchange's local time zone More...
 
bool DateIsOpen (DateTime dateToCheck, bool extendedMarketHours=false)
 Check if the date is open. More...
 
bool DateTimeIsOpen (DateTime dateTime)
 Check if this DateTime is open. More...
 
bool IsOpenDuringBar (DateTime barStartTime, DateTime barEndTime, bool isExtendedMarketHours)
 Determines if the exchange was open at any time between start and stop More...
 
bool IsClosingSoon (int minutesToClose)
 Determines if the exchange is going to close in the next provided minutes More...
 
void SetMarketHours (IEnumerable< MarketHoursSegment > marketHoursSegments, params DayOfWeek[] days)
 Sets the regular market hours for the specified days If no days are specified then all days will be updated. More...
 

Public Attributes

DateTimeZone TimeZone => Hours.TimeZone
 Gets the time zone for this exchange More...
 
virtual int TradingDaysPerYear => 365
 Number of trading days per year for this security. By default the market is open 365 days per year. More...
 
DateTime LocalTime => _timeProvider.LocalTime
 Time from the most recent data More...
 
bool ExchangeOpen => Hours.IsOpen(LocalTime, false)
 Boolean property for quickly testing if the exchange is open. More...
 
bool ClosingSoon => IsClosingSoon(minutesToClose:10)
 Boolean property for quickly testing if the exchange is 10 minutes away from closing. More...
 

Properties

SecurityExchangeHours Hours [get]
 Gets the SecurityExchangeHours for this exchange More...
 

Detailed Description

Base exchange class providing information and helper tools for reading the current exchange situation

Definition at line 27 of file SecurityExchange.cs.

Constructor & Destructor Documentation

◆ SecurityExchange()

QuantConnect.Securities.SecurityExchange.SecurityExchange ( SecurityExchangeHours  exchangeHours)

Initializes a new instance of the SecurityExchange class using the specified exchange hours to determine open/close times

Parameters
exchangeHoursContains the weekly exchange schedule plus holidays

Definition at line 67 of file SecurityExchange.cs.

Member Function Documentation

◆ SetLocalDateTimeFrontierProvider()

void QuantConnect.Securities.SecurityExchange.SetLocalDateTimeFrontierProvider ( LocalTimeKeeper  timeProvider)

Set the current datetime in terms of the exchange's local time zone

Parameters
timeProviderMost recent data tick

Definition at line 76 of file SecurityExchange.cs.

◆ DateIsOpen()

bool QuantConnect.Securities.SecurityExchange.DateIsOpen ( DateTime  dateToCheck,
bool  extendedMarketHours = false 
)

Check if the date is open.

This is useful for first checking the date list, and then the market hours to save CPU cycles

Parameters
dateToCheckDate to check
extendedMarketHoursTrue to consider days with extended market hours only as open
Returns
Return true if the exchange is open for this date

Definition at line 88 of file SecurityExchange.cs.

Here is the call graph for this function:

◆ DateTimeIsOpen()

bool QuantConnect.Securities.SecurityExchange.DateTimeIsOpen ( DateTime  dateTime)

Check if this DateTime is open.

Parameters
dateTimeDateTime to check
Returns
Boolean true if the market is open

Definition at line 98 of file SecurityExchange.cs.

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

◆ IsOpenDuringBar()

bool QuantConnect.Securities.SecurityExchange.IsOpenDuringBar ( DateTime  barStartTime,
DateTime  barEndTime,
bool  isExtendedMarketHours 
)

Determines if the exchange was open at any time between start and stop

Definition at line 106 of file SecurityExchange.cs.

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

◆ IsClosingSoon()

bool QuantConnect.Securities.SecurityExchange.IsClosingSoon ( int  minutesToClose)

Determines if the exchange is going to close in the next provided minutes

Parameters
minutesToCloseMinutes to close to check
Returns
Returns true if the exchange is going to close in the next provided minutes

Definition at line 116 of file SecurityExchange.cs.

Here is the call graph for this function:

◆ SetMarketHours()

void QuantConnect.Securities.SecurityExchange.SetMarketHours ( IEnumerable< MarketHoursSegment marketHoursSegments,
params DayOfWeek[]  days 
)

Sets the regular market hours for the specified days If no days are specified then all days will be updated.

Parameters
marketHoursSegmentsSpecifies each segment of the market hours, such as premarket/market/postmark
daysThe days of the week to set these times for

Definition at line 127 of file SecurityExchange.cs.

Member Data Documentation

◆ TimeZone

DateTimeZone QuantConnect.Securities.SecurityExchange.TimeZone => Hours.TimeZone

Gets the time zone for this exchange

Definition at line 39 of file SecurityExchange.cs.

◆ TradingDaysPerYear

virtual int QuantConnect.Securities.SecurityExchange.TradingDaysPerYear => 365

Number of trading days per year for this security. By default the market is open 365 days per year.

Used for performance statistics to calculate sharpe ratio accurately

Definition at line 45 of file SecurityExchange.cs.

◆ LocalTime

DateTime QuantConnect.Securities.SecurityExchange.LocalTime => _timeProvider.LocalTime

Time from the most recent data

Definition at line 50 of file SecurityExchange.cs.

◆ ExchangeOpen

bool QuantConnect.Securities.SecurityExchange.ExchangeOpen => Hours.IsOpen(LocalTime, false)

Boolean property for quickly testing if the exchange is open.

Definition at line 55 of file SecurityExchange.cs.

◆ ClosingSoon

bool QuantConnect.Securities.SecurityExchange.ClosingSoon => IsClosingSoon(minutesToClose:10)

Boolean property for quickly testing if the exchange is 10 minutes away from closing.

Definition at line 60 of file SecurityExchange.cs.

Property Documentation

◆ Hours

SecurityExchangeHours QuantConnect.Securities.SecurityExchange.Hours
get

Gets the SecurityExchangeHours for this exchange

Definition at line 34 of file SecurityExchange.cs.


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