From 0215ba42b886775cf628e59bb9b63e74e8184f3a Mon Sep 17 00:00:00 2001 From: msincenselee Date: Tue, 17 Oct 2017 19:59:06 +0800 Subject: [PATCH] sync 1.7 --- vnpy/trader/gateway/ctpGateway/ctpGateway.py | 25 +++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/vnpy/trader/gateway/ctpGateway/ctpGateway.py b/vnpy/trader/gateway/ctpGateway/ctpGateway.py index 316a6859..fc8deb0e 100644 --- a/vnpy/trader/gateway/ctpGateway/ctpGateway.py +++ b/vnpy/trader/gateway/ctpGateway/ctpGateway.py @@ -378,6 +378,11 @@ class CtpMdApi(MdApi): # 忽略成交量为0的无效tick数据 #if not data['Volume']: # return + if not self.connectionStatus: + self.connectionStatus = True + + if not self.gateway.mdConnected: + self.gateway.mdConnected = True tick = VtTickData() tick.gatewayName = self.gatewayName @@ -458,13 +463,14 @@ class CtpMdApi(MdApi): """订阅合约""" # 这里的设计是,如果尚未登录就调用了订阅方法 # 则先保存订阅请求,登录完成后会自动订阅 - if self.loginStatus: - print u'subscribe {0}'.format(str(subscribeReq.symbol)) - self.subscribeMarketData(str(subscribeReq.symbol)) - self.writeLog(u'订阅合约:{0}'.format(str(subscribeReq.symbol))) - else: - print u'not login, add {0} into subscribe list'.format(str(subscribeReq.symbol)) - self.writeLog(u'未连接,增加合约{0}至待订阅列表'.format(str(subscribeReq.symbol))) + #if self.loginStatus: + print u'subscribe {0}'.format(str(subscribeReq.symbol)) + self.subscribeMarketData(str(subscribeReq.symbol)) + self.writeLog(u'订阅合约:{0}'.format(str(subscribeReq.symbol))) + #else: + # print u'not login, add {0} into subscribe list'.format(str(subscribeReq.symbol)) + # self.writeLog(u'未连接,增加合约{0}至待订阅列表'.format(str(subscribeReq.symbol))) + self.subscribedSymbols.add(subscribeReq) #---------------------------------------------------------------------- @@ -753,6 +759,9 @@ class CtpTdApi(TdApi): if not data['InstrumentID']: return + if not self.gateway.tdConnected: + self.gateway.tdConnected = True + # 获取持仓缓存对象 posName = '.'.join([data['InstrumentID'], data['PosiDirection']]) if posName in self.posDict: @@ -1541,7 +1550,7 @@ class CtpTdApi(TdApi): #---------------------------------------------------------------------- def test(): """测试""" - from PyQt4 import QtCore + from qtpy import QtCore import sys def print_log(event):