def _OnRspAuthenticate( self, pRspAuthenticateField: CThostFtdcRspAuthenticateField, pRspInfo: CThostFtdcRspInfoField, nRequestID: int, bIsLast: bool): if pRspInfo.getErrorID() == 0: if pRspAuthenticateField.getAppType( ) == TThostFtdcAppTypeType.THOST_FTDC_APP_TYPE_InvestorRelay: self.t.RegisterUserSystemInfo( self.broker, self.investor, 0, '', self.pub_ip, self.port, time.strftime('%H:%M:%S', time.localtime())) elif pRspAuthenticateField.getAppType( ) == TThostFtdcAppTypeType.THOST_FTDC_APP_TYPE_OperatorRelay: self.t.SubmitUserSystemInfo( self.broker, self.investor, 0, '', self.pub_ip, self.port, time.strftime('%H:%M:%S', time.localtime())) self.t.ReqUserLogin( BrokerID=self.broker, UserID=self.investor, Password=self.password, UserProductInfo=pRspAuthenticateField.getUserProductInfo()) else: info = InfoField() info.ErrorID = pRspInfo.getErrorID() info.ErrorMsg = f'认证错误:{pRspInfo.getErrorMsg()}' threading.Thread(target=self.OnUserLogin, args=(self, info)).start()
def _OnRspUserLogin(self, pRspUserLogin: CThostFtdcRspUserLoginField, pRspInfo: CThostFtdcRspInfoField, nRequestID: int, bIsLast: bool): """""" info = InfoField() info.ErrorID = pRspInfo.getErrorID() info.ErrorMsg = pRspInfo.getErrorMsg() self.logined = True threading.Thread(target=self.OnUserLogin, args=(self, info)).start()
def _OnErrRtnQuote(self, pInputQuote: CThostFtdcInputQuoteField, pRspInfo: CThostFtdcRspInfoField): info = InfoField() info.ErrorID = pRspInfo.getErrorID() info.ErrorMsg = pRspInfo.getErrorMsg() threading.Thread(target=self.OnErrRtnQuote, args=(self, pInputQuote, info)).start()
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()) threading.Thread(target=self.OnErrOrder, args=(self, of, info)).start()
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 pInputOrder.getDirection( ) == TThostFtdcDirectionType.THOST_FTDC_D_Buy else DirectType.Sell ot = TThostFtdcOffsetFlagType( ord(pInputOrder.getCombOffsetFlag()[0])) of.Offset = OffsetType.Open if ot == TThostFtdcOffsetFlagType.THOST_FTDC_OF_Open else OffsetType.CloseToday if ot == TThostFtdcOffsetFlagType.THOST_FTDC_OF_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) threading.Thread(target=self.OnErrOrder, args=(self, of, info)).start()
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: threading.Thread(target=self._relogin).start() else: info = InfoField() info.ErrorID = pRspInfo.getErrorID() info.ErrorMsg = pRspInfo.getErrorMsg() threading.Thread(target=self.OnUserLogin, args=(self, info)).start()
def OnRspUserLogin(self, rsp: ctp.CThostFtdcRspUserLoginField, info: ctp.CThostFtdcRspInfoField, req: int, last: bool): QA.QA_util_log_info(info.getErrorMsg()) # CTP:正确小于2种字符:请注意修改 if info.getErrorID() == 0: self.Session = rsp.getSessionID() self.t.ReqSettlementInfoConfirm( BrokerID=self.broker, InvestorID=self.investor) else: self.RelogEnable = False
def OnRspAuthenticate( self, pRspAuthenticateField: ctp.CThostFtdcRspAuthenticateField, pRspInfo: ctp.CThostFtdcRspInfoField, nRequestID: int, bIsLast: bool): QA.QA_util_log_info('auth:{0}:{1}'.format(pRspInfo.getErrorID(), pRspInfo.getErrorMsg())) self.t.ReqUserLogin(BrokerID=self.broker, UserID=self.investor, Password=self.pwd, UserProductInfo='@yutiansut')