Пример #1
0
    def buy(self, price: float, volume: float, origin: [BarData, TickData, TradeData, OrderData, PositionData],
            price_type: OrderType = OrderType.LIMIT, stop: bool = False, lock: bool = False, **kwargs):
        """
        多头开仓

        Args:
          price (float): 价格

          volume(float): 手数, 股票会自动*100

          origin(Any(BarData, TradeData, TickData, OrderData, PositionData)): 快速获取品种和交易所信息

          price_type(OrderType): 价格类型

        Returns:
          str: 单号
        """

        if not isinstance(self.app.config['SLIPPAGE_BUY'], float) and not isinstance(
                self.app.config['SLIPPAGE_BUY'], int):
            raise ConfigError(message="滑点配置应为浮点小数或者整数")
        price = price + self.app.config['SLIPPAGE_BUY']
        req = helper.generate_order_req_by_var(volume=volume, price=price, offset=Offset.OPEN, direction=Direction.LONG,
                                               type=price_type, exchange=origin.exchange, symbol=origin.symbol)
        return self.send_order(req)
Пример #2
0
    def cover(self, price: float, volume: float, origin: [BarData, TickData, TradeData, OrderData, PositionData],
              price_type: OrderType = OrderType.LIMIT, stop: bool = False, lock: bool = False, **kwargs):
        """
        平多头, 注意返回是一个list, 因为单号会涉及到平昨平今组合平仓

        Args:
          price (float): 价格

          volume(float): 手数, 股票会自动*100

          origin(Any(BarData, TradeData, TickData, OrderData, PositionData)): 快速获取品种和交易所信息

          price_type(OrderType): 价格类型

        Returns:
          str: 单号
        """
        if not isinstance(self.app.config['SLIPPAGE_COVER'], float) and not isinstance(
                self.app.config['SLIPPAGE_COVER'], int):
            raise ConfigError(message="滑点配置应为浮点小数")
        price = price - self.app.config['SLIPPAGE_COVER']
        req_list = [helper.generate_order_req_by_var(volume=x[1], price=price, offset=x[0], direction=Direction.SHORT,
                                                     type=price_type, exchange=origin.exchange,
                                                     symbol=origin.symbol) for x in
                    self.get_req(origin.local_symbol, Direction.LONG, volume, self.app)]
        return [self.send_order(req) for req in req_list if req.volume != 0]
Пример #3
0
 def sell(self,
          price: float,
          volume: float,
          origin: [BarData, TickData, TradeData, OrderData] = None,
          stop: bool = False,
          lock: bool = False,
          **kwargs):
     """ 平空头 """
     if not isinstance(self.app.config['SLIPPAGE_SELL'],
                       float) and not isinstance(
                           self.app.config['SLIPPAGE_SELL'], int):
         raise ConfigError(message="滑点配置应为浮点小数")
     price = price + self.app.config['SLIPPAGE_SELL']
     req_list = [
         helper.generate_order_req_by_var(volume=x[1],
                                          price=price,
                                          offset=x[0],
                                          direction=Direction.LONG,
                                          type=OrderType.LIMIT,
                                          exchange=origin.exchange,
                                          symbol=origin.symbol)
         for x in self.get_req(origin.local_symbol, Direction.SHORT, volume,
                               self.app)
     ]
     return [self.send_order(req) for req in req_list if req.volume != 0]
Пример #4
0
 def cover(self,
           price: float,
           volume: float,
           origin: [BarData, TickData, TradeData, OrderData, PositionData],
           price_type: OrderType = OrderType.LIMIT,
           stop: bool = False,
           lock: bool = False,
           **kwargs):
     if not isinstance(self.looper.params['slippage_cover'],
                       float) and not isinstance(
                           self.looper.params['slippage_cover'], int):
         raise ConfigError(message="滑点配置应为浮点小数")
     price = price + self.looper.exec_intercept['slippage_cover']
     req_list = [
         helper.generate_order_req_by_var(volume=x[1],
                                          price=price,
                                          offset=x[0],
                                          direction=Direction.LONG,
                                          type=price_type,
                                          exchange=origin.exchange,
                                          symbol=origin.symbol)
         for x in self.get_req(origin.local_symbol, Direction.SHORT, volume,
                               self.looper)
     ]
     return [
         self.looper.send_order(req) for req in req_list if req.volume != 0
     ]
Пример #5
0
    def short(self,
              price: float,
              volume: float,
              origin: [BarData, TickData, TradeData, OrderData, PositionData],
              price_type: OrderType = OrderType.LIMIT,
              stop: bool = False,
              lock: bool = False,
              **kwargs):
        """
         开仓 空头
        """

        if not isinstance(self.app.config['SLIPPAGE_SHORT'],
                          float) and not isinstance(
                              self.app.config['SLIPPAGE_SHORT'], int):
            raise ConfigError(message="滑点配置应为浮点小数")
        price = price + self.app.config['SLIPPAGE_SHORT']
        req = helper.generate_order_req_by_var(volume=volume,
                                               price=price,
                                               offset=Offset.OPEN,
                                               direction=Direction.SHORT,
                                               type=price_type,
                                               exchange=origin.exchange,
                                               symbol=origin.symbol)
        return self.send_order(req)