Example #1
0
 def handle_bar(self, event):
     if self._force_run_before_trading:
         self.before_trading(event)
     else:
         bar_dict = event.bar_dict
         with ExecutionContext(EXECUTION_PHASE.ON_BAR):
             with ModifyExceptionFromType(EXC_TYPE.USER_EXC):
                 self._handle_bar(self._user_context, bar_dict)
 def before_trading_(self, event):
     with ExecutionContext(EXECUTION_PHASE.BEFORE_TRADING):
         self._stage = 'before_trading'
         for day_rule, time_rule, func in self._registry:
             if day_rule() and time_rule():
                 with ModifyExceptionFromType(EXC_TYPE.USER_EXC):
                     func(self._ucontext, None)
         self._stage = None
Example #3
0
 def handle_tick(self, event):
     if self._force_run_before_trading:
         self.before_trading(event)
     else:
         tick = event.tick
         with ExecutionContext(EXECUTION_PHASE.ON_TICK):
             with ModifyExceptionFromType(EXC_TYPE.USER_EXC):
                 self._handle_tick(self._user_context, tick)
Example #4
0
    def init(self):
        if self._init:
            with ExecutionContext(EXECUTION_PHASE.ON_INIT):
                with ModifyExceptionFromType(EXC_TYPE.USER_EXC):
                    self._init(self._user_context)

        Environment.get_instance().event_bus.publish_event(
            Event(EVENT.POST_USER_INIT))
Example #5
0
 def next_bar_(self, event):
     bars = event.bar_dict
     with ExecutionContext(EXECUTION_PHASE.SCHEDULED):
         self._current_minute = self._minutes_since_midnight(self._ucontext.now.hour, self._ucontext.now.minute)
         for day_rule, time_rule, func in self._registry:
             if day_rule() and time_rule():
                 with ModifyExceptionFromType(EXC_TYPE.USER_EXC):
                     func(self._ucontext, bars)
         self._last_minute = self._current_minute
Example #6
0
    def end(self):
        if not self._end:
            return

        with ExecutionContext(EXECUTION_PHASE.FINALIZED):
            with ModifyExceptionFromType(EXC_TYPE.USER_EXC):
                self._end(self._user_context)

        Environment.get_instance().event_bus.publish_event(
            Event(EVENT.POST_USER_END))
Example #7
0
 def before_trading(self, event):
     self._force_run_before_trading = False
     with ExecutionContext(EXECUTION_PHASE.BEFORE_TRADING):
         with ModifyExceptionFromType(EXC_TYPE.USER_EXC):
             self._before_trading(self._user_context)
Example #8
0
 def after_trading(self, event):
     with ExecutionContext(EXECUTION_PHASE.AFTER_TRADING):
         with ModifyExceptionFromType(EXC_TYPE.USER_EXC):
             self._after_trading(self._user_context)
Example #9
0
 def handle_bar(self, event):
     bar_dict = event.bar_dict
     with ExecutionContext(EXECUTION_PHASE.ON_BAR):
         with ModifyExceptionFromType(EXC_TYPE.USER_EXC):
             self._handle_bar(self._user_context, bar_dict)
Example #10
0
 def wrapped_handler(event):
     with ExecutionContext(EXECUTION_PHASE.GLOBAL):
         with ModifyExceptionFromType(EXC_TYPE.USER_EXC):
             return handler(self._user_context, event)
Example #11
0
 def handle_tick(self, event):
     tick = event.tick
     with ExecutionContext(EXECUTION_PHASE.ON_TICK):
         with ModifyExceptionFromType(EXC_TYPE.USER_EXC):
             self._handle_tick(self._user_context, tick)
Example #12
0
 def open_auction(self, event):
     bar_dict = event.bar_dict
     with ExecutionContext(EXECUTION_PHASE.OPEN_AUCTION):
         with ModifyExceptionFromType(EXC_TYPE.USER_EXC):
             self._open_auction(self._user_context, bar_dict)