Securities
Exchange
Hours
To get the exchange hours, use the Exchange.Hours
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
is_open
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.is_open(self.time, extended_market_hours=False) # Check if the exchange is open at any point in time over a specific interval is_open = security_exchange_hours.is_open(self.time, self.time + timedelta(days=1), extended_market_hours=False)
To check if the exchange is open on a specific date, call the IsDateOpen
is_date_open
method.
var isOpen = securityExchangeHours.IsDateOpen(Time);
is_open = security_exchange_hours.is_date_open(self.time)
To get the next market open time, call the GetNextMarketOpen
get_next_market_open
method.
var marketOpenTime = securityExchangeHours.GetNextMarketOpen(Time, extendedMarketHours: false);
market_open_time = security_exchange_hours.get_next_market_open(self.time, extended_market_hours=False)
To get the next market close time, call the GetNextMarketClose
get_next_market_close
method.
var marketCloseTime = securityExchangeHours.GetNextMarketClose(Time, extendedMarketHours: false);
market_close_time = security_exchange_hours.get_next_market_close(self.time, extended_market_hours=False)
To get the previous trading day, call the GetPreviousTradingDay
get_previous_trading_day
method.
var day = securityExchangeHours.GetPreviousTradingDay(Time);
day = security_exchange_hours.get_previous_trading_day(self.time)
To get the next trading day, call the GetNextTradingDay
get_next_trading_day
method.
var day = securityExchangeHours.GetNextTradingDay(Time);
day = security_exchange_hours.get_next_trading_day(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
extended_market_hours
argument when you create the security subscription.
AddEquity("SPY", extendedMarketHours: true);
self.add_equity("SPY", extended_market_hours=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.