diff --git a/tests/test_bar_data.py b/tests/test_bar_data.py index 3abc5b9d77..366d6bf097 100644 --- a/tests/test_bar_data.py +++ b/tests/test_bar_data.py @@ -462,79 +462,85 @@ def test_spot_price_at_midnight(self): bd.current(self.HILARIOUSLY_ILLIQUID_ASSET, "volume") ) - def test_can_trade_during_non_market_hours(self): - # make sure that if we use `can_trade` at midnight, we don't pretend - # we're in the previous day's last minute - the_day_after = self.trading_calendar.next_session_label( - self.equity_minute_bar_days[-1] - ) - - bar_data = BarData(self.data_portal, lambda: the_day_after, "minute") - - for asset in [self.ASSET1, self.HILARIOUSLY_ILLIQUID_ASSET]: - self.assertFalse(bar_data.can_trade(asset)) - - with handle_non_market_minutes(bar_data): - self.assertFalse(bar_data.can_trade(asset)) - - # NYSE is closed at midnight, so even if the asset is alive, can_trade - # should return False - bar_data2 = BarData( - self.data_portal, - lambda: self.equity_minute_bar_days[1], - "minute", - ) - for asset in [self.ASSET1, self.HILARIOUSLY_ILLIQUID_ASSET]: - self.assertFalse(bar_data2.can_trade(asset)) - - with handle_non_market_minutes(bar_data2): - self.assertFalse(bar_data2.can_trade(asset)) - - def test_can_trade_exchange_closed(self): - nyse_asset = self.asset_finder.retrieve_asset(1) - ice_asset = self.asset_finder.retrieve_asset(6) - - # minutes we're going to check (to verify that that the same bardata - # can check multiple exchange calendars, all times Eastern): - # 2016-01-05: - # 20:00 (minute before ICE opens) - # 20:01 (first minute of ICE session) - # 20:02 (second minute of ICE session) - # 00:00 (Cinderella's ride becomes a pumpkin) - # 2016-01-06: - # 9:30 (minute before NYSE opens) - # 9:31 (first minute of NYSE session) - # 9:32 (second minute of NYSE session) - # 15:59 (second-to-last minute of NYSE session) - # 16:00 (last minute of NYSE session) - # 16:01 (minute after NYSE closed) - # 17:59 (second-to-last minute of ICE session) - # 18:00 (last minute of ICE session) - # 18:01 (minute after ICE closed) - - # each row is dt, whether-nyse-is-open, whether-ice-is-open - minutes_to_check = [ - (pd.Timestamp("2016-01-05 20:00", tz="US/Eastern"), False, False), - (pd.Timestamp("2016-01-05 20:01", tz="US/Eastern"), False, True), - (pd.Timestamp("2016-01-05 20:02", tz="US/Eastern"), False, True), - (pd.Timestamp("2016-01-06 00:00", tz="US/Eastern"), False, True), - (pd.Timestamp("2016-01-06 9:30", tz="US/Eastern"), False, True), - (pd.Timestamp("2016-01-06 9:31", tz="US/Eastern"), True, True), - (pd.Timestamp("2016-01-06 9:32", tz="US/Eastern"), True, True), - (pd.Timestamp("2016-01-06 15:59", tz="US/Eastern"), True, True), - (pd.Timestamp("2016-01-06 16:00", tz="US/Eastern"), True, True), - (pd.Timestamp("2016-01-06 16:01", tz="US/Eastern"), False, True), - (pd.Timestamp("2016-01-06 17:59", tz="US/Eastern"), False, True), - (pd.Timestamp("2016-01-06 18:00", tz="US/Eastern"), False, True), - (pd.Timestamp("2016-01-06 18:01", tz="US/Eastern"), False, False), - ] - - for info in minutes_to_check: - bar_data = BarData(self.data_portal, lambda: info[0], "minute") - series = bar_data.can_trade([nyse_asset, ice_asset]) - - self.assertEqual(info[1], series.loc[nyse_asset]) - self.assertEqual(info[2], series.loc[ice_asset]) + # FIXME temporarily commenting out until we restore the new can_trade + # functionality that checks exchange status + # def test_can_trade_during_non_market_hours(self): + # # make sure that if we use `can_trade` at midnight, we don't pretend + # # we're in the previous day's last minute + # the_day_after = self.trading_calendar.next_session_label( + # self.equity_minute_bar_days[-1] + # ) + # + # bar_data = BarData(self.data_portal, lambda: the_day_after, "minute") + # + # for asset in [self.ASSET1, self.HILARIOUSLY_ILLIQUID_ASSET]: + # self.assertFalse(bar_data.can_trade(asset)) + # + # with handle_non_market_minutes(bar_data): + # self.assertFalse(bar_data.can_trade(asset)) + # + # # NYSE is closed at midnight, so even if the asset is alive, + # # can_trade should return False + # bar_data2 = BarData( + # self.data_portal, + # lambda: self.equity_minute_bar_days[1], + # "minute", + # ) + # for asset in [self.ASSET1, self.HILARIOUSLY_ILLIQUID_ASSET]: + # self.assertFalse(bar_data2.can_trade(asset)) + # + # with handle_non_market_minutes(bar_data2): + # self.assertFalse(bar_data2.can_trade(asset)) + + # FIXME temporarily commenting out until we restore the new can_trade + # functionality that checks exchange status + # def test_can_trade_exchange_closed(self): + # nyse_asset = self.asset_finder.retrieve_asset(1) + # ice_asset = self.asset_finder.retrieve_asset(6) + # + # # minutes we're going to check (to verify that that the same bardata + # # can check multiple exchange calendars, all times Eastern): + # # 2016-01-05: + # # 20:00 (minute before ICE opens) + # # 20:01 (first minute of ICE session) + # # 20:02 (second minute of ICE session) + # # 00:00 (Cinderella's ride becomes a pumpkin) + # # 2016-01-06: + # # 9:30 (minute before NYSE opens) + # # 9:31 (first minute of NYSE session) + # # 9:32 (second minute of NYSE session) + # # 15:59 (second-to-last minute of NYSE session) + # # 16:00 (last minute of NYSE session) + # # 16:01 (minute after NYSE closed) + # # 17:59 (second-to-last minute of ICE session) + # # 18:00 (last minute of ICE session) + # # 18:01 (minute after ICE closed) + # + # # each row is dt, whether-nyse-is-open, whether-ice-is-open + # minutes_to_check = [ + # (pd.Timestamp("2016-01-05 20:00", tz="US/Eastern"), False, + # False), + # (pd.Timestamp("2016-01-05 20:01", tz="US/Eastern"), False, True), + # (pd.Timestamp("2016-01-05 20:02", tz="US/Eastern"), False, True), + # (pd.Timestamp("2016-01-06 00:00", tz="US/Eastern"), False, True), + # (pd.Timestamp("2016-01-06 9:30", tz="US/Eastern"), False, True), + # (pd.Timestamp("2016-01-06 9:31", tz="US/Eastern"), True, True), + # (pd.Timestamp("2016-01-06 9:32", tz="US/Eastern"), True, True), + # (pd.Timestamp("2016-01-06 15:59", tz="US/Eastern"), True, True), + # (pd.Timestamp("2016-01-06 16:00", tz="US/Eastern"), True, True), + # (pd.Timestamp("2016-01-06 16:01", tz="US/Eastern"), False, True), + # (pd.Timestamp("2016-01-06 17:59", tz="US/Eastern"), False, True), + # (pd.Timestamp("2016-01-06 18:00", tz="US/Eastern"), False, True), + # (pd.Timestamp("2016-01-06 18:01", tz="US/Eastern"), False, + # False), + # ] + # + # for info in minutes_to_check: + # bar_data = BarData(self.data_portal, lambda: info[0], "minute") + # series = bar_data.can_trade([nyse_asset, ice_asset]) + # + # self.assertEqual(info[1], series.loc[nyse_asset]) + # self.assertEqual(info[2], series.loc[ice_asset]) def test_is_stale_during_non_market_hours(self): bar_data = BarData( diff --git a/zipline/_protocol.pyx b/zipline/_protocol.pyx index 6141d77e89..fe7851ce5c 100644 --- a/zipline/_protocol.pyx +++ b/zipline/_protocol.pyx @@ -467,9 +467,11 @@ cdef class BarData: # asset isn't alive return False - if not asset.is_exchange_open(dt): - # exchange isn't open - return False + # FIXME temporarily commenting out while we sort out some downstream + # dependencies + # if not asset.is_exchange_open(dt): + # # exchange isn't open + # return False if isinstance(asset, Future): # FIXME: this will get removed once we can get prices for futures