Example #1
0
    def _OnErrOrder(self, pInputOrder: CThostFtdcInputOrderField, pRspInfo: CThostFtdcRspInfoField):
        """"""
        id = '{0}|{1}|{2}'.format(self.session, '0', pInputOrder.getOrderRef())
        of = self.orders.get(id)

        info = InfoField()
        info.ErrorID = pRspInfo.getErrorID()
        info.ErrorMsg = pRspInfo.getErrorMsg()

        if of and of.IsLocal:
            of.Status = OrderStatus.Error
            of.StatusMsg = '{0}:{1}'.format(pRspInfo.getErrorID(), pRspInfo.getErrorMsg())
            _thread.start_new_thread(self.OnErrOrder, (self, of, info))
Example #2
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.session, '0', pInputOrder.getOrderRef())
        of = self.orders.get(id)
        if not of:
            of = OrderField()
            l = int(pInputOrder.getOrderRef())
            of.Custom = l % 1000000
            of.InstrumentID = pInputOrder.getInstrumentID()
            of.InsertTime = time.strftime('%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.orders[id] = of

        of.Status = OrderStatus.Error
        of.StatusMsg = '{0}:{1}'.format(info.ErrorID, info.ErrorMsg)
        _thread.start_new_thread(self.OnErrOrder, (self, of, info))
Example #3
0
 def OnRspOrderInsert(self, pInputOrder: ctp.CThostFtdcInputOrderField,
                      pRspInfo: ctp.CThostFtdcRspInfoField, nRequestID: int,
                      bIsLast: bool):
     print("---------报单应答---------")
     print(pRspInfo)
     print(pInputOrder)
     print(pRspInfo.getErrorMsg())
Example #4
0
    def OnRspUserLogin(self, rsp: ctp.CThostFtdcRspUserLoginField, info: ctp.CThostFtdcRspInfoField, req: int, last: bool):
        print(info.getErrorMsg())

        if info.getErrorID() == 0:
            self.Session = rsp.getSessionID()
            self.t.ReqSettlementInfoConfirm(BrokerID=self.broker, InvestorID=self.investor)
        else:
            self.RelogEnable = False
Example #5
0
 def _OnRspUserLogin(self, pRspUserLogin: CThostFtdcRspUserLoginField,
                     pRspInfo: CThostFtdcRspInfoField, nRequestID: int,
                     bIsLast: bool):
     """"""
     info = InfoField()
     info.ErrorID = pRspInfo.getErrorID()
     info.ErrorMsg = pRspInfo.getErrorMsg()
     self.logined = True
     _thread.start_new_thread(self.OnUserLogin, (self, info))
Example #6
0
 def OnRspAuthenticate(
         self, pRspAuthenticateField: ctp.CThostFtdcRspAuthenticateField,
         pRspInfo: ctp.CThostFtdcRspInfoField, nRequestID: int,
         bIsLast: bool):
     print('auth:{0}:{1}'.format(pRspInfo.getErrorID(),
                                 pRspInfo.getErrorMsg()))
     self.t.ReqUserLogin(BrokerID=self.broker,
                         UserID=self.investor,
                         Password=self.pwd,
                         UserProductInfo='@haifeng')
Example #7
0
 def _OnRspUserLogin(self, pRspUserLogin: CThostFtdcRspUserLoginField(), pRspInfo: CThostFtdcRspInfoField, nRequestID: int, bIsLast: bool):
     """"""
     if pRspInfo.getErrorID() == 0:
         self.session = pRspUserLogin.getSessionID()
         self.tradingday = pRspUserLogin.getTradingDay()
         self.t.ReqSettlementInfoConfirm(self.broker, self.investor)
     elif self.logined:
         _thread.start_new_thread(self._relogin, ())
     else:
         info = InfoField()
         info.ErrorID = pRspInfo.getErrorID()
         info.ErrorMsg = pRspInfo.getErrorMsg()
         _thread.start_new_thread(self.OnUserLogin, (self, info))