Securities
Exchange
Hours
To get the exchange hours, use the Exchange.Hours
property on a Security
object.
var securityExchangeHours = Securities["SPY"].Exchange.Hours;
security_exchange_hours = self.Securities["SPY"].Exchange.Hours
The preceding code snippet returns a SecurityExchangeHours
object, which has the following attributes:
To check if the exchange is open at a specific time, call the IsOpen
method.
// Check if the exchange is open at a specific time var isOpenNow = securityExchangeHours.IsOpen(Time, extendedMarketHours: false); // Check if the exchange is open at any point in time over a specific interval var isOpen = securityExchangeHours.IsOpen(Time, Time.AddDays(1), extendedMarketHours: false);
# Check if the exchange is open at a specific time is_open_now = security_exchange_hours.IsOpen(self.Time, extendedMarketHours=False) # Check if the exchange is open at any point in time over a specific interval is_open = security_exchange_hours.IsOpen(self.Time, self.Time + timedelta(days=1), extendedMarketHours=False)
To check if the exchange is open on a specific date, call the IsDateOpen
method.
var isOpen = securityExchangeHours.IsDateOpen(Time);
is_open = security_exchange_hours.IsDateOpen(self.Time)
To get the next market open time, call the GetNextMarketOpen
method.
var marketOpenTime = securityExchangeHours.GetNextMarketOpen(Time, extendedMarketHours: false);
market_open_time = security_exchange_hours.GetNextMarketOpen(self.Time, extendedMarketHours=False)
To get the next market close time, call the GetNextMarketClose
method.
var marketCloseTime = securityExchangeHours.GetNextMarketClose(Time, extendedMarketHours: false);
market_close_time = security_exchange_hours.GetNextMarketClose(self.Time, extendedMarketHours=False)
To get the previous trading day, call the GetPreviousTradingDay
method.
var day = securityExchangeHours.GetPreviousTradingDay(Time);
day = security_exchange_hours.GetPreviousTradingDay(self.Time)
To get the next trading day, call the GetNextTradingDay
method.
var day = securityExchangeHours.GetNextTradingDay(Time);
day = security_exchange_hours.GetNextTradingDay(self.Time)
Extended Market Hours
By default, your security subscriptions only cover regular trading hours. To subscribe to pre and post-market trading hours for a specific asset, enable the extendedMarketHours
argument when you create the security subscription.
AddEquity("SPY", extendedMarketHours: true);
self.AddEquity("SPY", extendedMarketHours=True)
You only receive extended market hours data if you create the subscription with minute, second, or tick resolution. If you create the subscription with daily or hourly resolution, the bars only reflect the regular trading hours.