Exemple #1
0
    def sendOrder(self, vtSymbol, direction, offset, price, volume, payup=0):
        """发单"""
        contract = self.mainEngine.getContract(vtSymbol)
        if not contract:
            return ''

        req = VtOrderReq()
        req.symbol = contract.symbol
        req.exchange = contract.exchange
        req.vtSymbol = contract.vtSymbol
        req.direction = direction
        req.offset = offset
        req.volume = int(volume)
        req.priceType = PRICETYPE_LIMITPRICE

        if direction == DIRECTION_LONG:
            req.price = price + payup * contract.priceTick
        else:
            req.price = price - payup * contract.priceTick

        # 委托转换
        reqList = self.mainEngine.convertOrderReq(req)
        vtOrderIDList = []

        for req in reqList:
            vtOrderID = self.mainEngine.sendOrder(req, contract.gatewayName)
            vtOrderIDList.append(vtOrderID)

        return vtOrderIDList
Exemple #2
0
 def sendOrder(self, vtSymbol, direction, offset, price, volume, payup=0):
     """发单"""
     contract = self.mainEngine.getContract(vtSymbol)
     if not contract:
         return ''
     
     req = VtOrderReq()
     req.symbol = contract.symbol
     req.exchange = contract.exchange
     req.vtSymbol = contract.vtSymbol
     req.direction = direction
     req.offset = offset
     req.volume = int(volume)
     req.priceType = PRICETYPE_LIMITPRICE
     
     if direction == DIRECTION_LONG:
         req.price = price + payup * contract.priceTick
     else:
         req.price = price - payup * contract.priceTick
         
     # 委托转换
     reqList = self.mainEngine.convertOrderReq(req)
     vtOrderIDList = []
     
     for req in reqList:
         vtOrderID = self.mainEngine.sendOrder(req, contract.gatewayName)
         vtOrderIDList.append(vtOrderID)
     
     return vtOrderIDList
Exemple #3
0
    def sendOrder(self, algo, vtSymbol, direction, price, volume, 
                  priceType=None, offset=None):
        """发单"""
        contract = self.mainEngine.getContract(vtSymbol)
        if not contract:
            self.writeLog(u'%s委托下单失败,找不到合约:%s' %(algo.algoName, vtSymbol))

        req = VtOrderReq()
        req.vtSymbol = vtSymbol
        req.symbol = contract.symbol
        req.exchange = contract.exchange
        req.direction = direction        
        req.offset = OFFSET_CLOSETODAY
        req.price = price
        req.volume = volume
        
        if priceType:
            req.priceType = priceType
        else:
            req.priceType = PRICETYPE_LIMITPRICE
        
        if offset:
            req.offset = offset
        else:
            req.offset = OFFSET_OPEN
        
        vtOrderID = self.mainEngine.sendOrder(req, contract.gatewayName)
        self.orderAlgoDict[vtOrderID] = algo
        
        return vtOrderID
Exemple #4
0
    def sendOrder(self, vtSymbol, direction, offset, price, volume):
        """发单"""
        contract = self.mainEngine.getContract(vtSymbol)
        if not contract:
            return ''

        req = VtOrderReq()
        req.symbol = contract.symbol
        req.exchange = contract.exchange
        req.vtSymbol = vtSymbol
        req.price = price
        req.volume = volume
        req.direction = direction
        req.offset = offset
        req.priceType = PRICETYPE_LIMITPRICE

        return self.mainEngine.sendOrder(req, contract.gatewayName)
Exemple #5
0
 def sendOrder(self, vtSymbol, direction, offset, price, volume):
     """发单"""
     contract = self.mainEngine.getContract(vtSymbol)
     if not contract:
         return ''
     
     req = VtOrderReq()
     req.symbol = contract.symbol
     req.exchange = contract.exchange
     req.vtSymbol = vtSymbol
     req.price = price
     req.volume = volume
     req.direction = direction
     req.offset = offset
     req.priceType = PRICETYPE_LIMITPRICE
     
     return self.mainEngine.sendOrder(req, contract.gatewayName)
Exemple #6
0
    def sendOrder(self, algo, vtSymbol, direction, price, volume):
        """发单"""
        contract = self.mainEngine.getContract(vtSymbol)
        if not contract:
            self.writeLog(u'%s委托下单失败,找不到合约:%s' % (algo.algoName, vtSymbol))

        req = VtOrderReq()
        req.vtSymbol = vtSymbol
        req.symbol = contract.symbol
        req.exchange = contract.exchange
        req.direction = direction
        req.priceType = PRICETYPE_LIMITPRICE
        req.offset = OFFSET_CLOSETODAY
        req.price = price
        req.volume = volume
        vtOrderID = self.mainEngine.sendOrder(req, contract.gatewayName)

        return vtOrderID
Exemple #7
0
    def sendOrder(self,
                  algo,
                  vtSymbol,
                  direction,
                  price,
                  volume,
                  priceType=None,
                  offset=None):
        """发单"""
        contract = self.mainEngine.getContract(vtSymbol)
        if not contract:
            self.writeLog(u'%s委托下单失败,找不到合约:%s' % (algo.algoName, vtSymbol))

        vtSymbol = '.'.join([contract.symbol, contract.exchange])
        req = VtOrderReq()
        req.vtSymbol = vtSymbol
        req.symbol = contract.symbol
        req.exchange = contract.exchange
        req.direction = direction
        req.offset = OFFSET_CLOSETODAY
        req.price = price
        req.volume = volume

        if priceType:
            req.priceType = priceType
        else:
            req.priceType = PRICETYPE_LIMITPRICE

        if offset:
            req.offset = offset
        else:
            req.offset = OFFSET_OPEN

        strData = 'symbol %s exchange %s price %.2f volume %d direction %s offset %s vtSymbol %s gatewayName %s'\
        %(req.symbol,req.exchange,req.price,req.volume,req.direction,req.offset,req.vtSymbol,contract.gatewayName)

        print 'currency productClass ', req.currency, req.productClass
        # print 'sendOrder req:'
        # print strData
        vtOrderID = self.mainEngine.sendOrder(req, contract.gatewayName)
        self.orderAlgoDict[vtOrderID] = algo

        return vtOrderID
Exemple #8
0
    def sendOrder(self,
                  algo,
                  vtSymbol,
                  direction,
                  price,
                  volume,
                  priceType=None,
                  offset=None):
        logger.info(f"{algo.algoName}")
        print(f"进入发单")
        print(vtSymbol)
        """发单"""
        contract = self.mainEngine.getContract(vtSymbol)
        if not contract:
            self.writeLog(u'%s委托下单失败,找不到合约:%s' % (algo.algoName, vtSymbol))

        req = VtOrderReq()
        req.vtSymbol = vtSymbol
        req.symbol = contract.symbol
        req.exchange = contract.exchange
        req.direction = direction
        req.offset = OFFSET_CLOSETODAY
        req.price = price
        req.volume = volume

        if priceType:
            req.priceType = priceType
        else:
            req.priceType = PRICETYPE_LIMITPRICE

        if offset:
            req.offset = offset
        else:
            req.offset = OFFSET_OPEN

        vtOrderID = self.mainEngine.sendOrder(req, contract.gatewayName)
        self.orderAlgoDict[vtOrderID] = algo
        logger.info(f"{vtOrderID}")

        return vtOrderID
Exemple #9
0
    def sendOrder(self, symbol, orderType, price, volume, strategy):
        try:
            req = VtOrderReq()
            req.symbol = symbol
            req.vtSymbol = symbol
            req.price = price
            req.volume = volume
            req.priceType = PRICETYPE_LIMITPRICE

            gatewayName = "TradeDllAShare"

            # CTA委托类型映射
            if orderType == CTAORDER_BUY:
                req.direction = DIRECTION_LONG
            elif orderType == CTAORDER_SELL:
                req.direction = DIRECTION_SHORT
            else:
                self.writeLog(u"不支持订单方向类型:" + orderType)

            VtOrderID = self.mainEngine.sendOrder(req, gatewayName)

            if VtOrderID:
                # 下单成功,添加orderid和策略对应关系
                # self.orderStrategyDict[VtOrderID] = strategy  # 保存order和策略的映射关系
                # self.strategyDict[strategy.strategyID].addOrder(VtOrderID)  # 添加到策略委托号集合中

                self.writeLog(u'策略%s发送委托成功,%s,%s,%s@%s' %
                              (strategy.strategyID, symbol, req.direction,
                               volume, price))
            else:
                self.writeLog(u"策略%s发送委托失败,%s,%s,%s@%s" %
                              (strategy.strategyID, symbol, req.direction,
                               volume, price))

            return VtOrderID
        except:
            traceback.print_exc()
            return VtOrderID
Exemple #10
0
    def sendOrder(self, symbol, orderType, price, volume):
        try:
            req = VtOrderReq()
            req.symbol = symbol
            req.vtSymbol = symbol
            req.price = price
            req.volume = volume
            req.priceType = PRICETYPE_LIMITPRICE

            gatewayName = "FUTU"

            req.direction = orderType
            orderID = self.mainEngine.sendOrder(req, gatewayName)

            if orderID:
                self.writeLog(u'委托成功 %s, %s,%s@%s %s' %
                              (symbol, orderType, volume, price, orderID))
            else:
                self.writeLog(u'委托失败 %s, %s,%s@%s %s' %
                              (symbol, orderType, volume, price, orderID))
            return orderID
        except:
            traceback.print_exc()