Ejemplo n.º 1
0
def is_valid_trading_day(trading_day: arrow.arrow.Arrow) -> bool:
    """Decides if a given trading day is valid and returns a boolean."""
    trading_day_formatted = trading_day.format("YYYY-MM-DD")
    is_valid = False
    nyse = ec.get_calendar("NYSE")
    nasdaq = ec.get_calendar("NASDAQ")
    if nyse.is_session(trading_day_formatted) and nasdaq.is_session(
            trading_day_formatted):
        is_valid = True
    return is_valid
Ejemplo n.º 2
0
    def _is_forex_trading_time(self, now: arrow.arrow.Arrow) -> bool:
        weekday = now.isoweekday()
        date = now.format('YYYY-MM-DD')

        if weekday <= 4:
            return True

        elif weekday == 5:
            if now < arrow.get(f'{date} 22:00'):
                return True

        elif weekday == 6:
            return False

        elif weekday == 7:
            if now >= arrow.get(f'{date} 21:00'):
                return True

        return False
Ejemplo n.º 3
0
    def _is_A_shares_trading_time(self, now: arrow.arrow.Arrow) -> bool:
        weekday = now.isoweekday()
        date = now.format('YYYY-MM-DD')

        if self.env.sys_frequency == 'D':

            if weekday <= 5:
                return True

        else:

            if weekday <= 5:
                left_1 = arrow.get(f'{date} 09:30')
                right_1 = arrow.get(f'{date} 11:30')
                left_2 = arrow.get(f'{date} 13:00')
                right_2 = arrow.get(f'{date} 15:00')

                if left_1 < now < right_1 or left_2 < now < right_2:
                    return True

        return False