def test_is_market_open(): timezone = "Europe/London" tz = pytz.timezone(timezone) now_time = datetime.now(tz=tz).strftime("%H:%M") expected = Utils.is_between( str(now_time), ("07:55", "16:35")) and BankHolidays().is_work_day(datetime.now(tz=tz)) result = Utils.is_market_open(timezone) assert result == expected
def safety_checks(self): """ Perform some safety checks before running the strategy against the next market Return True if the trade can proceed, False otherwise """ percent_used = self.broker.get_account_used_perc() if percent_used is None: logging.warning( "Stop trading because can't fetch percentage of account used") raise NotSafeToTradeException() if percent_used >= self.max_account_usable: logging.warning( "Stop trading because {}% of account is used".format( str(percent_used))) raise NotSafeToTradeException() if not Utils.is_market_open(self.time_zone): logging.warning("Market is closed: stop processing") raise MarketClosedException()