From 00701b0f5e99da8ad114d14b68cbff90302c42f5 Mon Sep 17 00:00:00 2001 From: msincenselee Date: Thu, 4 Aug 2016 15:13:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9gateway=EF=BC=8C=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E6=9B=B4=E5=A4=9A=E7=9A=84ErrMsg=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vn.trader/ctpGateway/ctpGateway.py | 32 +++++++++++++++++++++++------- vn.trader/eventType.py | 1 + 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/vn.trader/ctpGateway/ctpGateway.py b/vn.trader/ctpGateway/ctpGateway.py index 7026f87f..3c842e50 100644 --- a/vn.trader/ctpGateway/ctpGateway.py +++ b/vn.trader/ctpGateway/ctpGateway.py @@ -586,7 +586,8 @@ class CtpTdApi(TdApi): err = VtErrorData() err.gatewayName = self.gatewayName err.errorID = error['ErrorID'] - err.errorMsg = error['ErrorMsg'].decode('gbk') + u'{0},{1},{2}'.format(orderRef,direction , offset,) + err.errorMsg = error['ErrorMsg'].decode('gbk') + err.additionalInfo = u'onRspOrderInsert():{0},{1},{2},{3}'.format(symbol, orderRef, direction , offset) self.gateway.onError(err) #---------------------------------------------------------------------- @@ -602,10 +603,16 @@ class CtpTdApi(TdApi): #---------------------------------------------------------------------- def onRspOrderAction(self, data, error, n, last): """撤单错误(柜台)""" + try: + symbol = data['InstrumentID'] + except KeyError: + symbol = u'KEYERROR' + err = VtErrorData() err.gatewayName = self.gatewayName err.errorID = error['ErrorID'] err.errorMsg = error['ErrorMsg'].decode('gbk') + err.additionalInfo = u'onRspOrderAction,{0}'.format(symbol) self.gateway.onError(err) #---------------------------------------------------------------------- @@ -903,10 +910,11 @@ class CtpTdApi(TdApi): #---------------------------------------------------------------------- def onRspError(self, error, n, last): """错误回报""" + err = VtErrorData() err.gatewayName = self.gatewayName err.errorID = error['ErrorID'] - err.errorMsg = error['ErrorMsg'].decode('gbk') + err.errorMsg = u'onRspError' + error['ErrorMsg'].decode('gbk') self.gateway.onError(err) #---------------------------------------------------------------------- @@ -937,15 +945,15 @@ class CtpTdApi(TdApi): # 开平 if data['CombOffsetFlag'] == '0': - offset = OFFSET_OPEN + order.offset = OFFSET_OPEN elif data['CombOffsetFlag'] == '1': - offset = OFFSET_CLOSE + order.offset = OFFSET_CLOSE elif data['CombOffsetFlag'] == '2': - offset = OFFSET_FORCECLOSE + order.offset = OFFSET_FORCECLOSE elif data['CombOffsetFlag'] == '3': - offset = OFFSET_CLOSETODAY + order.offset = OFFSET_CLOSETODAY elif data['CombOffsetFlag'] == '4': - offset = OFFSET_CLOSEYESTERDAY + order.offset = OFFSET_CLOSEYESTERDAY else: order.offset = OFFSET_UNKNOWN @@ -1015,19 +1023,29 @@ class CtpTdApi(TdApi): #---------------------------------------------------------------------- def onErrRtnOrderInsert(self, data, error): """发单错误回报(交易所)""" + + symbol = data['InstrumentID'] + volume = data['VolumeTotalOriginal'] + orderRef = data['OrderRef'] + err = VtErrorData() err.gatewayName = self.gatewayName err.errorID = error['ErrorID'] err.errorMsg = error['ErrorMsg'].decode('gbk') + err.additionalInfo = u'onErrRtnOrderInsert.{0},v:{1},ref:{2}:'.format(symbol, volume,orderRef) self.gateway.onError(err) #---------------------------------------------------------------------- def onErrRtnOrderAction(self, data, error): """撤单错误回报(交易所)""" + + symbol = data['InstrumentID'] + err = VtErrorData() err.gatewayName = self.gatewayName err.errorID = error['ErrorID'] err.errorMsg = error['ErrorMsg'].decode('gbk') + err.additionalInfo =u'onErrRtnOrderAction.{0}'.format(symbol) self.gateway.onError(err) #---------------------------------------------------------------------- diff --git a/vn.trader/eventType.py b/vn.trader/eventType.py index 1b3ccaa4..54e75188 100644 --- a/vn.trader/eventType.py +++ b/vn.trader/eventType.py @@ -19,6 +19,7 @@ EVENT_LOG = 'eLog' # 日志事件,全局通用 EVENT_TICK = 'eTick.' # TICK行情事件,可后接具体的vtSymbol EVENT_TRADE = 'eTrade.' # 成交回报事件 EVENT_ORDER = 'eOrder.' # 报单回报事件 +EVENT_ERRRTNORDERINSERT = 'eErrRtnOrderInsert' # 报单录入错误回报事件 EVENT_POSITION = 'ePosition.' # 持仓回报事件 EVENT_ACCOUNT = 'eAccount.' # 账户回报事件 EVENT_CONTRACT = 'eContract.' # 合约基础信息回报事件