Example #1
0
 def handler(pdata, pRspInfo):
     d = struct_format(pdata)
     e = struct_format(pRspInfo)
     if log:
         logger.error(f'<错误回报处理>信息:{d}')
         logger.error(f'<错误回报处理>错误:{e}')
     handle(pdata)
Example #2
0
    def register_rsp_callback(self, func_name, log=False):
        if getattr(self, func_name, None) == None:
            logger.error(f'<回调>不存在该回调函数')
            raise Exception(f'<回调>不存在该回调函数')

        def wrapper(handle):
            def handler(pdata, pRspInfo, nRequestID, bIsLast):
                if pdata:
                    d = struct_format(pdata)
                    if log:
                        logger.info(f'<回调处理>信息:{d}')
                    handle(pdata)

                if pRspInfo and pRspInfo.ErrorID != 0:
                    RspInfo = struct_format(pRspInfo)
                    logger.error(
                        f'<ReqID: {nRequestID}>ErrorID:{RspInfo["ErrorID"]}  ErrorMsg:{RspInfo["ErrorMsg"]}'
                    )

                if bIsLast:
                    logger.info(f'<回调处理>信息推送完毕')

            setattr(self, func_name, handler)

        return wrapper
Example #3
0
 def OnRspTradingAccountPasswordUpdate(self, pTradingAccountPasswordUpdate,
                                       pRspInfo, nRequestID, bIsLast):
     if pRspInfo.ErrorID == 0:
         accID = pTradingAccountPasswordUpdate.AccountID.decode()
         logger.info(f'<密码>账户:{ accID} 修改密码成功')
     else:
         RspInfo = struct_format(pRspInfo)
         logger.error(
             f'<ReqID: {nRequestID}>ErrorID:{RspInfo["ErrorID"]}  ErrorMsg:{RspInfo["ErrorMsg"]}'
         )
Example #4
0
 def OnRspUserPasswordUpdate(self, pUserPasswordUpdate, pRspInfo,
                             nRequestID, bIsLast):
     if pRspInfo.ErrorID == 0:
         userID = pUserPasswordUpdate.UserID.decode()
         logger.info(f'<密码>账户:{ userID} 修改密码成功')
     else:
         RspInfo = struct_format(pRspInfo)
         logger.error(
             f'<ReqID: {nRequestID}>ErrorID:{RspInfo["ErrorID"]}  ErrorMsg:{RspInfo["ErrorMsg"]}'
         )
Example #5
0
 def OnRspUserLogout(self, pUserLogout, pRspInfo, nRequestID, bIsLast):
     if pRspInfo.ErrorID == 0:
         self.loginStatus = False
         UserLogout = struct_format(pUserLogout)
         logger.info(f'<登出>交易接口:{UserLogout["UserID"]} 登出成功')
     else:
         RspInfo = struct_format(pRspInfo)
         logger.error(
             f'<ReqID: {nRequestID}>ErrorID:{RspInfo["ErrorID"]}  ErrorMsg:{RspInfo["ErrorMsg"]}'
         )
Example #6
0
 def OnRspUnSubMarketData(self, pSpecificInstrument, pRspInfo, nRequestID,
                          bIsLast):
     if pRspInfo.ErrorID == 0:
         self.loginStatus = False
         SpecificInstrument = struct_format(pSpecificInstrument)
         logger.info(f'<订阅>产品:{SpecificInstrument["InstrumentID"]} 取消订阅成功')
     else:
         RspInfo = struct_format(pRspInfo)
         logger.error(
             f'<ReqID: {nRequestID}>ErrorID:{RspInfo["ErrorID"]}  ErrorMsg:{RspInfo["ErrorMsg"]}'
         )
Example #7
0
    def OnRspOrderInsert(self, pInputOrder, pRspInfo, nRequestID, bIsLast):
        if pInputOrder:
            order = struct_format(pInputOrder)
            logger.info(f'<订单>报单插入:{order}')

        if pRspInfo and pRspInfo.ErrorID != 0:
            RspInfo = struct_format(pRspInfo)
            logger.error(
                f'<ReqID: {nRequestID}>ErrorID:{RspInfo["ErrorID"]}  ErrorMsg:{RspInfo["ErrorMsg"]}'
            )

        if bIsLast:
            logger.info(f'<订单>报单插入信息推送完毕')
Example #8
0
    def OnRspQryOrder(self, pOrder, pRspInfo, nRequestID, bIsLast):
        if pOrder:
            o = struct_format(pOrder)
            logger.info(f'<订单>订单信息:{o}')

        if pRspInfo and pRspInfo.ErrorID != 0:
            RspInfo = struct_format(pRspInfo)
            logger.error(
                f'<ReqID: {nRequestID}>ErrorID:{RspInfo["ErrorID"]}  ErrorMsg:{RspInfo["ErrorMsg"]}'
            )

        if bIsLast:
            logger.info(f'<订单>信息推送完毕')
Example #9
0
    def OnRspAuthenticate(self, pRspAuthenticate, pRspInfo, nRequestID,
                          bIsLast):
        if pRspInfo.ErrorID == 0:
            self.authStatus = True

            logger.info(LogInfo.T_AUTHENTICATED)

            self.login()
        else:
            RspInfo = struct_format(pRspInfo)
            logger.error(
                f'<ReqID: {nRequestID}>ErrorID:{RspInfo["ErrorID"]}  ErrorMsg:{RspInfo["ErrorMsg"]}'
            )
Example #10
0
    def OnRspQryTrade(self, pTrade, pRspInfo, nRequestID, bIsLast):
        if pTrade:
            t = struct_format(pTrade)
            logger.info(f'<成交>成交信息:{t}')

        if pRspInfo and pRspInfo.ErrorID != 0:
            RspInfo = struct_format(pRspInfo)
            logger.error(
                f'<ReqID: {nRequestID}>ErrorID:{RspInfo["ErrorID"]}  ErrorMsg:{RspInfo["ErrorMsg"]}'
            )

        if bIsLast:
            logger.info(f'<成交>信息推送完毕')
Example #11
0
    def OnRspQryProduct(self, pProduct, pRspInfo, nRequestID, bIsLast):
        if pProduct:
            t = struct_format(pProduct)
            logger.info(f'<产品>产品信息:{t}')

        if pRspInfo and pRspInfo.ErrorID != 0:
            RspInfo = struct_format(pRspInfo)
            logger.error(
                f'<ReqID: {nRequestID}>ErrorID:{RspInfo["ErrorID"]}  ErrorMsg:{RspInfo["ErrorMsg"]}'
            )

        if bIsLast:
            logger.info(f'<产品>信息推送完毕')
Example #12
0
    def OnRspQryInstrument(self, pInstrument, pRspInfo, nRequestID, bIsLast):
        if pInstrument:
            i = struct_format(pInstrument)
            logger.info(f'<合约>合约信息:{i}')

        if pRspInfo and pRspInfo.ErrorID != 0:
            RspInfo = struct_format(pRspInfo)
            logger.error(
                f'<ReqID: {nRequestID}>ErrorID:{RspInfo["ErrorID"]}  ErrorMsg:{RspInfo["ErrorMsg"]}'
            )

        if bIsLast:
            logger.info('<合约>信息推送完毕')
Example #13
0
    def OnRspParkedOrderAction(self, pParkedOrderAction, pRspInfo, nRequestID,
                               bIsLast):
        if pParkedOrderAction:
            order = struct_format(pParkedOrderAction)
            logger.info(f'<预埋订单>报单操作:{order}')

        if pRspInfo and pRspInfo.ErrorID != 0:
            RspInfo = struct_format(pRspInfo)
            logger.error(
                f'<ReqID: {nRequestID}>ErrorID:{RspInfo["ErrorID"]}  ErrorMsg:{RspInfo["ErrorMsg"]}'
            )

        if bIsLast:
            logger.info(f'<预埋订单>报单操作信息推送完毕')
Example #14
0
    def OnRspQueryMaxOrderVolume(self, pQueryMaxOrderVolume, pRspInfo,
                                 nRequestID, bIsLast):
        if pQueryMaxOrderVolume:
            order_volumn = struct_format(pQueryMaxOrderVolume)
            logger.info(f'<订单>最大报单量:{order_volumn}')

        if pRspInfo and pRspInfo.ErrorID != 0:
            RspInfo = struct_format(pRspInfo)
            logger.error(
                f'<ReqID: {nRequestID}>ErrorID:{RspInfo["ErrorID"]}  ErrorMsg:{RspInfo["ErrorMsg"]}'
            )

        if bIsLast:
            logger.info(f'<订单>最大报单量信息推送完毕')
Example #15
0
    def OnRspQryCFMMCTradingAccountKey(self, pCFMMCTradingAccountKey, pRspInfo,
                                       nRequestID, bIsLast):
        if pCFMMCTradingAccountKey:
            p = struct_format(pCFMMCTradingAccountKey)
            logger.info(f'<CFMMCTradingAccountKey>信息:{p}')

        if pRspInfo and pRspInfo.ErrorID != 0:
            RspInfo = struct_format(pRspInfo)
            logger.error(
                f'<ReqID: {nRequestID}>ErrorID:{RspInfo["ErrorID"]}  ErrorMsg:{RspInfo["ErrorMsg"]}'
            )

        if bIsLast:
            logger.info(f'<CFMMCTradingAccountKey>信息推送完毕')
Example #16
0
    def OnRspQryTransferBank(self, pTransferBank, pRspInfo, nRequestID,
                             bIsLast):
        if pTransferBank:
            transferBank = struct_format(pTransferBank)
            logger.info(f'<转账>信息:{transferBank}')

        if pRspInfo and pRspInfo.ErrorID != 0:
            RspInfo = struct_format(pRspInfo)
            logger.error(
                f'<ReqID: {nRequestID}>ErrorID:{RspInfo["ErrorID"]}  ErrorMsg:{RspInfo["ErrorMsg"]}'
            )

        if bIsLast:
            logger.info(f'<转账>信息推送完毕')
Example #17
0
    def OnRspQryInvestorPositionDetail(self, pInvestorPositionDetail, pRspInfo,
                                       nRequestID, bIsLast):
        if pInvestorPositionDetail:
            p = struct_format(pInvestorPositionDetail)
            logger.info(f'<持仓明细>信息:{p}')

        if pRspInfo and pRspInfo.ErrorID != 0:
            RspInfo = struct_format(pRspInfo)
            logger.error(
                f'<ReqID: {nRequestID}>ErrorID:{RspInfo["ErrorID"]}  ErrorMsg:{RspInfo["ErrorMsg"]}'
            )

        if bIsLast:
            logger.info(f'<持仓明细>信息推送完毕')
Example #18
0
    def OnRspQryInstrumentCommissionRate(self, pInstrumentCommissionRate,
                                         pRspInfo, nRequestID, bIsLast):
        if pInstrumentCommissionRate:
            t = struct_format(pInstrumentCommissionRate)
            logger.info(f'<手续费>手续费信息:{t}')

        if pRspInfo and pRspInfo.ErrorID != 0:
            RspInfo = struct_format(pRspInfo)
            logger.error(
                f'<ReqID: {nRequestID}>ErrorID:{RspInfo["ErrorID"]}  ErrorMsg:{RspInfo["ErrorMsg"]}'
            )

        if bIsLast:
            logger.info(f'<手续费>信息推送完毕')
Example #19
0
    def OnRspQrySettlementInfoConfirm(self, pSettlementInfoConfirm, pRspInfo,
                                      nRequestID, bIsLast):
        if pSettlementInfoConfirm:
            pSettlementInfo = struct_format(pSettlementInfoConfirm)
            logger.info(f'<结算>信息:{pSettlementInfo}')

        if pRspInfo and pRspInfo.ErrorID != 0:
            RspInfo = struct_format(pRspInfo)
            logger.error(
                f'<ReqID: {nRequestID}>ErrorID:{RspInfo["ErrorID"]}  ErrorMsg:{RspInfo["ErrorMsg"]}'
            )

        if bIsLast:
            logger.info(f'<结算>信息推送完毕')
Example #20
0
    def OnRspQryDepthMarketData(self, pDepthMarketData, pRspInfo, nRequestID,
                                bIsLast):
        if pDepthMarketData:
            pSettlementInfo = struct_format(pDepthMarketData)
            logger.info(f'<深度>信息:{pSettlementInfo}')

        if pRspInfo and pRspInfo.ErrorID != 0:
            RspInfo = struct_format(pRspInfo)
            logger.error(
                f'<ReqID: {nRequestID}>ErrorID:{RspInfo["ErrorID"]}  ErrorMsg:{RspInfo["ErrorMsg"]}'
            )

        if bIsLast:
            logger.info(f'<深度>信息推送完毕')
Example #21
0
    def OnRspQryInstrumentMarginRate(self, pInstrumentMarginRate, pRspInfo,
                                     nRequestID, bIsLast):
        if pInstrumentMarginRate:
            m = struct_format(pInstrumentMarginRate)
            logger.info(f'<保证金率>信息:{m}')

        if pRspInfo and pRspInfo.ErrorID != 0:
            RspInfo = struct_format(pRspInfo)
            logger.error(
                f'<ReqID: {nRequestID}>ErrorID:{RspInfo["ErrorID"]}  ErrorMsg:{RspInfo["ErrorMsg"]}'
            )

        if bIsLast:
            logger.info(f'<保证金率>信息推送完毕')
Example #22
0
    def OnRspQryTradingAccount(self, pTradingAccount, pRspInfo, nRequestID,
                               bIsLast):
        if pTradingAccount:
            t = struct_format(pTradingAccount)
            logger.info(f'<账户>账户信息:{t}')

        if pRspInfo and pRspInfo.ErrorID != 0:
            RspInfo = struct_format(pRspInfo)
            logger.error(
                f'<ReqID: {nRequestID}>ErrorID:{RspInfo["ErrorID"]}  ErrorMsg:{RspInfo["ErrorMsg"]}'
            )

        if bIsLast:
            logger.info(f'<账户>信息推送完毕')
Example #23
0
            def handler(pdata, pRspInfo, nRequestID, bIsLast):
                if pdata:
                    d = struct_format(pdata)
                    if log:
                        logger.info(f'<回调处理>信息:{d}')
                    handle(pdata)

                if pRspInfo and pRspInfo.ErrorID != 0:
                    RspInfo = struct_format(pRspInfo)
                    logger.error(
                        f'<ReqID: {nRequestID}>ErrorID:{RspInfo["ErrorID"]}  ErrorMsg:{RspInfo["ErrorMsg"]}'
                    )

                if bIsLast:
                    logger.info(f'<回调处理>信息推送完毕')
Example #24
0
    def register_rtn_callback(self, func_name, log=False):
        if getattr(self, func_name, None) == None:
            logger.error(f'<回报>不存在该回报函数')
            raise Exception(f'<回报>不存在该回报函数')

        def wrapper(handle):
            def handler(pdata):
                d = struct_format(pdata)
                if log:
                    logger.info(f'<回报处理>信息:{d}')
                handle(pdata)

            setattr(self, func_name, handler)

        return wrapper
Example #25
0
    def OnRspUserLogin(self, pRspUserLogin, pRspInfo, nRequestID, bIsLast):
        if pRspInfo.ErrorID == 0:
            self.loginStatus = True
            RspUserLogin = struct_format(pRspUserLogin)
            logger.info(
                f'<登入>行情接口:{RspUserLogin["UserID"]}于{RspUserLogin["LoginTime"]}登录成功,当前交易日为{RspUserLogin["TradingDay"]}'
            )

            for s in self.subscribedSymbols:
                self.subcribe(s)

        else:
            RspInfo = struct_format(pRspInfo)
            logger.error(
                f'<ReqID: {nRequestID}>ErrorID:{RspInfo["ErrorID"]}  ErrorMsg:{RspInfo["ErrorMsg"]}'
            )
Example #26
0
    def register_errrtn_callback(self, func_name, log=False):
        if getattr(self, func_name, None) == None:
            logger.error(f'<错误回报>不存在该错误回报函数')
            raise Exception(f'<错误回报>不存在该错误回报函数')

        def wrapper(handle):
            def handler(pdata, pRspInfo):
                d = struct_format(pdata)
                e = struct_format(pRspInfo)
                if log:
                    logger.error(f'<错误回报处理>信息:{d}')
                    logger.error(f'<错误回报处理>错误:{e}')
                handle(pdata)

            setattr(self, func_name, handler)

        return wrapper
Example #27
0
    def OnRspUserLogin(self, pRspUserLogin, pRspInfo, nRequestID, bIsLast):
        if pRspInfo.ErrorID == 0:
            RspUserLogin = struct_format(pRspUserLogin)
            self.frontID = RspUserLogin['FrontID']
            self.sessionID = RspUserLogin['SessionID']
            self.loginStatus = True
            logger.info(
                f'<登入>交易接口:{RspUserLogin["UserID"]}于{RspUserLogin["LoginTime"]}登录成功,当前交易日为{RspUserLogin["TradingDay"]}'
            )

            req = ApiStruct.SettlementInfoConfirm(
                BrokerID=self.brokerID.encode(),
                InvestorID=self.userID.encode())
            self.reqID += 1
            self.ReqSettlementInfoConfirm(req, self.reqID)

        else:
            RspInfo = struct_format(pRspInfo)
            logger.error(
                f'<ReqID: {nRequestID}>ErrorID:{RspInfo["ErrorID"]}  ErrorMsg:{RspInfo["ErrorMsg"]}'
            )
Example #28
0
 def OnRspError(self, pRspInfo, nRequestID, bIsLast):
     RspInfo = struct_format(pRspInfo)
     logger.error(
         f'<ReqID: {nRequestID}>ErrorID:{RspInfo["ErrorID"]}  ErrorMsg:{RspInfo["ErrorMsg"]}'
     )
Example #29
0
 def OnErrRtnOrderAction(self, pOrderAction, pRspInfo):
     o_a = struct_format(pOrderAction)
     e = struct_format(pRspInfo)
     logger.error(f'<订单>撤单错误回报:{o_a} 错误:{e}')
Example #30
0
 def OnErrRtnOrderInsert(self, pInputOrder, pRspInfo):
     i_o = struct_format(pInputOrder)
     e = struct_format(pRspInfo)
     logger.error(f'<订单>发单错误回报:{i_o} 错误:{e}')