| 19 | |
| 20 | |
| 21 | class ClockIntervalHandler: |
| 22 | def __init__(self, clock_engine, interval, trading=True, call=None): |
| 23 | """ |
| 24 | :param interval: float(minute) |
| 25 | :param trading: 在交易阶段才触发 |
| 26 | :return: |
| 27 | """ |
| 28 | self.clock_engine = clock_engine |
| 29 | self.clock_type = interval |
| 30 | self.interval = interval |
| 31 | self.second = int(interval * 60) |
| 32 | self.trading = trading |
| 33 | self.call = call or (lambda: None) |
| 34 | |
| 35 | def is_active(self): |
| 36 | if self.trading: |
| 37 | if not self.clock_engine.trading_state: |
| 38 | return False |
| 39 | return int(self.clock_engine.now) % self.second == 0 |
| 40 | |
| 41 | def __eq__(self, other): |
| 42 | if isinstance(other, ClockIntervalHandler): |
| 43 | return self.interval == other.interval |
| 44 | else: |
| 45 | return False |
| 46 | |
| 47 | def __hash__(self): |
| 48 | return self.second |
| 49 | |
| 50 | |
| 51 | class ClockMomentHandler: |