def is_market_open(self, timezone): """ Return True if the market is open, false otherwise - **timezone**: string representing the timezone """ tz = pytz.timezone(timezone) now_time = datetime.now(tz=tz).strftime("%H:%M") return BankHolidays().is_work_day(datetime.now(tz=tz)) and Utils.is_between( str(now_time), ("07:55", "16:35") )
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 test_is_between(): mock = "10:10" assert Utils.is_between(mock, ("10:09", "10:11")) mock = "00:00" assert Utils.is_between(mock, ("23:59", "00:01"))