From 8cdfcef62ba5dc3b3c87277b16edee96f981f42d Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Sun, 10 Jun 2018 15:00:39 +0800 Subject: [PATCH] =?UTF-8?q?[Mod]=E7=81=AB=E5=B8=81=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E4=BB=A3=E7=90=86=E6=94=AF=E6=8C=81,?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=8A=A8=E8=AE=A2=E9=98=85=E8=A1=8C?= =?UTF-8?q?=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/CryptoTrader/VT_setting.json | 6 ++-- vnpy/api/huobi/vnhuobi.py | 21 ++--------- .../gateway/huobiGateway/huobiGateway.py | 35 ++++++++++--------- 3 files changed, 24 insertions(+), 38 deletions(-) diff --git a/examples/CryptoTrader/VT_setting.json b/examples/CryptoTrader/VT_setting.json index 473017fb..40495eca 100644 --- a/examples/CryptoTrader/VT_setting.json +++ b/examples/CryptoTrader/VT_setting.json @@ -9,12 +9,12 @@ "darkStyle": true, "language": "chinese", - "logActive": true, + "logActive": false, "logLevel": "debug", "logConsole": true, "logFile": true, - "tdPenalty": ["IF", "IH", "IC"], + "tdPenalty": [], - "maxDecimal": 4 + "maxDecimal": 10 } \ No newline at end of file diff --git a/vnpy/api/huobi/vnhuobi.py b/vnpy/api/huobi/vnhuobi.py index ca9db9a3..f6b37697 100644 --- a/vnpy/api/huobi/vnhuobi.py +++ b/vnpy/api/huobi/vnhuobi.py @@ -504,8 +504,6 @@ class DataApi(object): self.subDict = {} self.url = '' - self.proxyHost = '' - self.proxyPort = 0 #---------------------------------------------------------------------- def run(self): @@ -532,12 +530,7 @@ class DataApi(object): def reconnect(self): """重连""" try: - if not self.proxyHost: - self.ws = create_connection(self.url) - else: - self.ws = create_connection(self.url, - http_proxy_host=self.proxyHost, - http_proxy_port=self.proxyPort) + self.ws = create_connection(self.url) return True except: msg = traceback.format_exc() @@ -553,20 +546,12 @@ class DataApi(object): self.subTopic(topic) #---------------------------------------------------------------------- - def connect(self, url, proxyHost='', proxyPort=0): + def connect(self, url): """连接""" self.url = url - self.proxyHost = proxyHost - self.proxyPort = proxyPort try: - if not self.proxyHost: - self.ws = create_connection(self.url) - else: - self.ws = create_connection(self.url, - http_proxy_host=self.proxyHost, - http_proxy_port=self.proxyPort) - + self.ws = create_connection(self.url) self.active = True self.thread.start() diff --git a/vnpy/trader/gateway/huobiGateway/huobiGateway.py b/vnpy/trader/gateway/huobiGateway/huobiGateway.py index 2b84a7ee..7e50940c 100644 --- a/vnpy/trader/gateway/huobiGateway/huobiGateway.py +++ b/vnpy/trader/gateway/huobiGateway/huobiGateway.py @@ -75,8 +75,6 @@ class HuobiGateway(VtGateway): accessKey = str(setting['accessKey']) secretKey = str(setting['secretKey']) symbols = setting['symbols'] - proxyHost = str(setting['proxyHost']) - proxyPort = int(setting['proxyPort']) except KeyError: log = VtLogData() log.gatewayName = self.gatewayName @@ -85,7 +83,7 @@ class HuobiGateway(VtGateway): return # 创建行情和交易接口对象 - self.dataApi.connect(exchange, proxyHost, proxyPort) + self.dataApi.connect(exchange, symbols) self.tradeApi.connect(exchange, accessKey, secretKey, symbols) # 初始化并启动查询 @@ -94,7 +92,8 @@ class HuobiGateway(VtGateway): #---------------------------------------------------------------------- def subscribe(self, subscribeReq): """订阅行情""" - self.dataApi.subscribe(subscribeReq) + pass + #self.dataApi.subscribe(subscribeReq) #---------------------------------------------------------------------- def sendOrder(self, orderReq): @@ -179,38 +178,40 @@ class HuobiDataApi(DataApi): self.tickDict = {} - self.subscribeDict = {} + #self.subscribeDict = {} #---------------------------------------------------------------------- - def connect(self, exchange, proxyHost, proxyPort): + def connect(self, exchange, symbols): """连接服务器""" if exchange == 'huobi': url = 'wss://api.huobi.pro/ws' else: url = 'wss://api.hadax.com/ws' + + self.symbols = symbols - if proxyHost: - self.connectionStatus = super(HuobiDataApi, self).connect(url, proxyHost, proxyPort) - else: - self.connectionStatus = super(HuobiDataApi, self).connect(url) + self.connectionStatus = super(HuobiDataApi, self).connect(url) self.gateway.mdConnected = True if self.connectionStatus: self.writeLog(u'行情服务器连接成功') - + + for symbol in self.symbols: + self.subscribe(symbol) # 订阅所有之前订阅过的行情 - for req in self.subscribeDict.values(): - self.subscribe(req) + #for req in self.subscribeDict.values(): + # self.subscribe(req) + #---------------------------------------------------------------------- - def subscribe(self, subscribeReq): + def subscribe(self, symbol): """订阅合约""" - self.subscribeDict[subscribeReq.symbol] = subscribeReq + #self.subscribeDict[subscribeReq.symbol] = subscribeReq if not self.connectionStatus: return - symbol = subscribeReq.symbol + #symbol = subscribeReq.symbol if symbol in self.tickDict: return @@ -354,7 +355,7 @@ class HuobiTradeApi(TradeApi): #self.activeOrderSet = set() # 活动委托集合 #---------------------------------------------------------------------- - def connect(self, exchange, accessKey, secretKey, symbols=''): + def connect(self, exchange, symbols, accessKey, secretKey): """初始化连接""" if not self.connectionStatus: self.symbols = symbols