Beispiel #1
0
 def data_events(self):
     yield Event(event_type=EventType.INITIALIZE)
     for data in self._env.data_proxy.data_walker:
         # 每天先完成上个交易日下单的撮合成交
         yield Event(event_type=EventType.ORDER_DEAL)
         yield Event(event_type=EventType.BEFORE_TRADING, data=data)
         yield Event(event_type=EventType.BAR, data=data)
         # 当前Bar订单提交
         yield Event(event_type=EventType.SETTLEMENT)
Beispiel #2
0
 def subscribe(self, symbols, before_bar_count=1):
     if isinstance(symbols, str):
         symbols = [
             symbols,
         ]
     evt = Event(event_type=EventType.SUBSCRIBE,
                 symbols=symbols,
                 before_bar_count=before_bar_count)
     self._env.event_bus.emit(event=evt)
Beispiel #3
0
 def on_order_submission(self, evt: Event):
     oder_obj = getattr(evt, 'order_obj')
     order_reason = self._order_manager.on_order_submission(oder_obj)
     flag = order_reason.result
     # ====================== 下单前验证 =====================
     if flag:
         order_reason = self._portfolio_manager.on_order_submission(
             oder_obj)
         flag = order_reason.result
     # ====================== 验证结束 ======================
     if flag:
         self._env.event_bus.emit()
     else:
         self._env.event_bus.emit(
             Event(event_type=EventType.ORDER_REJECTED,
                   info=order_reason.reason))
Beispiel #4
0
    def order(self,
              symbol,
              quantity,
              limit_price=None,
              order_type=OrderType.MKT):
        if quantity > 0:
            side = OrderSide.BUY
        else:
            side = OrderSide.SELL
            quantity = abs(quantity)
        dt = self._env.data_proxy.get_datetime()
        order_obj = Order(symbol=symbol,
                          quantity=quantity,
                          side=side,
                          order_type=order_type,
                          limit_price=limit_price,
                          order_time=dt)

        evt = Event(event_type=EventType.ORDER_NEW, order_obj=order_obj)
        self._env.event_bus.emit(evt)
Beispiel #5
0
 def _order_cancel_rejected(self, order):
     self._env.event_bus.emit(
         Event(EventType.ORDER_CANCELLATION_REJECTED, order=order))
Beispiel #6
0
 def _order_cancel_passed(self, order):
     self._open_orders[order.symbol].remove(order)
     self._env.event_bus.emit(
         Event(EventType.ORDER_CANCELLATION_PASSED, order=order))
Beispiel #7
0
 def data_events(self):
     yield Event(event_type=EventType.INITIALIZE)
     for data in self._env.data_proxy.data_walker:
         yield Event(event_type=EventType.BAR, data=data)
Beispiel #8
0
 def initialize(self):
     self.load_apps()
     self.load_broker()
     self._env.strategy.set_up()
     self._env.event_bus.emit(Event(EventType.INITIALIZE))