示例#1
0
    def OnOrder(self, order=OrderField()):
        """委托响应"""
        print('委托反应')
        self.oid = self.GetLastOrder().OrderID

        print('last order == ', self.GetLastOrder())
        print('order id == ', self.oid)
        print('cancel orderid == ', order.OrderID)
        self.ReqCancel(self.oid)
示例#2
0
    def __OnRtnOrder(self, pOrder=CThostFtdcOrderField):
        """"""
        id = '{0}|{1}|{2}'.format(pOrder.getSessionID(), pOrder.getFrontID(),
                                  pOrder.getOrderRef())
        # of = OrderField()
        of = self.DicOrderField.get(id)
        if not of:
            of = OrderField()
            l = int(pOrder.getOrderRef())
            of.Custom = l % 1000000
            of.InstrumentID = pOrder.getInstrumentID()
            of.InsertTime = pOrder.getInsertTime()
            of.Direction = DirectType.Buy if DirectionType(pOrder.getDirection(
            )) == DirectionType.Buy else DirectType.Sell
            ot = OffsetFlagType(ord(pOrder.getCombOffsetFlag()[0]))
            of.Offset = OffsetType.Open if ot == OffsetFlagType.Open else (
                OffsetType.CloseToday
                if ot == OffsetFlagType.CloseToday else OffsetType.Close)
            of.Status = OrderStatus.Normal
            of.StatusMsg = pOrder.getStatusMsg()
            of.IsLocal = pOrder.getSessionID() == self.SessionID
            of.LimitPrice = pOrder.getLimitPrice()
            of.OrderID = id
            of.Volume = pOrder.getVolumeTotalOriginal()
            of.VolumeLeft = of.Volume
            self.DicOrderField[id] = of
            self.OnRtnOrder(of)
            # _thread.start_new_thread(self.OnRtnOrder, (of,))  # call client OnRtnOrder event
        elif pOrder.getOrderStatus() == OrderStatusType.Canceled:
            of.Status = OrderStatus.Canceled
            of.StatusMsg = pOrder.getStatusMsg()

            if of.StatusMsg.find('被拒绝') >= 0:
                info = InfoField()
                info.ErrorID = -1
                info.ErrorMsg = of.StatusMsg
                self.OnRtnErrOrder(of, info)
            else:
                self.OnRtnCancel(of)
        else:
            if pOrder.getOrderSysID():
                of.SysID = pOrder.getOrderSysID()
                self.__dic_orderid_sysid[pOrder.getOrderSysID(
                )] = id  # 记录sysid与orderid关联,方便Trade时查找处理
示例#3
0
    def __OnRspOrder(self,
                     pInputOrder=CThostFtdcInputOrderField,
                     pRspInfo=CThostFtdcRspInfoField,
                     nRequestID=int,
                     bIsLast=bool):
        """"""
        info = InfoField()
        info.ErrorID = pRspInfo.getErrorID()
        info.ErrorMsg = pRspInfo.getErrorMsg()

        id = '{0}|{1}|{2}'.format(self.SessionID, '0',
                                  pInputOrder.getOrderRef())
        of = self.DicOrderField.get(id)
        if not of:
            of = OrderField()
            l = int(pInputOrder.getOrderRef())
            of.Custom = l % 1000000
            of.InstrumentID = pInputOrder.getInstrumentID()
            of.InsertTime = time.strftime('%Y%M%d %H:%M:%S', time.localtime())
            # 对direction需特别处理(具体见ctp_struct)
            of.Direction = DirectType.Buy if DirectionType(
                pInputOrder.getDirection(
                )) == DirectionType.Buy else DirectType.Sell
            ot = OffsetFlagType(ord(pInputOrder.getCombOffsetFlag()[0]))
            of.Offset = OffsetType.Open if ot == OffsetFlagType.Open else (
                OffsetType.CloseToday
                if ot == OffsetFlagType.CloseToday else OffsetType.Close)
            # of.Status = OrderStatus.Normal
            # of.StatusMsg = f.getStatusMsg()
            of.IsLocal = True
            of.LimitPrice = pInputOrder.getLimitPrice()
            of.OrderID = id
            of.Volume = pInputOrder.getVolumeTotalOriginal()
            of.VolumeLeft = of.Volume
            self.DicOrderField[id] = of

        of.Status = OrderStatus.Error
        of.StatusMsg = '{0}:{1}'.format(info.ErrorID, info.ErrorMsg)
        _thread.start_new_thread(self.OnRtnErrOrder, (of, info))
示例#4
0
 def OnErrCancel(self, order=OrderField(), info=InfoField()):
     """撤单错误"""
     print('撤单错误')
     print('strategy err cancel')
     print(order)
示例#5
0
 def OnErrOrder(self, order=OrderField(), info=InfoField()):
     """委托错误"""
     print('委托错误')
     print('strategy err order')
     print(order)
示例#6
0
 def OnErrCancel(self, order=OrderField(), info=InfoField()):
     """撤单错误"""
     pass
示例#7
0
 def OnErrOrder(self, order=OrderField(), info=InfoField()):
     """委托错误"""
     pass
示例#8
0
 def OnCancel(self, order=OrderField()):
     """撤单响应"""
     pass
示例#9
0
 def OnOrder(self, order=OrderField()):
     """委托响应"""
     pass
示例#10
0
 def _get_lastorder(self, stra):
     """获取最后一个委托"""
     return OrderField()
示例#11
0
 def OnOrder(self, order=OrderField()):
     """委托响应"""
     print('strategy order')
     print(order)