From 70ed2dfd66561f9ef1eae5d6415645ef0364e084 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Sun, 10 Jun 2018 11:53:09 +0800 Subject: [PATCH] =?UTF-8?q?[Fix]Close=20#906,Bitfinex=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=96=B0=E5=A2=9EonConnect=E5=9B=9E=E8=B0=83=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/api/bitfinex/vnbitfinex.py | 12 +++++++++++- .../gateway/bitfinexGateway/bitfinexGateway.py | 7 +++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/vnpy/api/bitfinex/vnbitfinex.py b/vnpy/api/bitfinex/vnbitfinex.py index 8c55b08a..4e1b10bb 100644 --- a/vnpy/api/bitfinex/vnbitfinex.py +++ b/vnpy/api/bitfinex/vnbitfinex.py @@ -38,11 +38,15 @@ class BitfinexApi(object): self.restThread = Thread(target=self.runRest) self.restThread.start() + + self.onConnect() #---------------------------------------------------------------------- def reconnect(self): """""" - self.ws = websocket.create_connection(WEBSOCKET_V2_URL) + self.ws = websocket.create_connection(WEBSOCKET_V2_URL) + + self.onConnect() #---------------------------------------------------------------------- def run(self): @@ -57,6 +61,12 @@ class BitfinexApi(object): self.onError(msg) self.reconnect() + #---------------------------------------------------------------------- + def onConnect(self): + """""" + print 'connected' + + #---------------------------------------------------------------------- def onData(self, data): """""" diff --git a/vnpy/trader/gateway/bitfinexGateway/bitfinexGateway.py b/vnpy/trader/gateway/bitfinexGateway/bitfinexGateway.py index 5aef41be..005ca85b 100644 --- a/vnpy/trader/gateway/bitfinexGateway/bitfinexGateway.py +++ b/vnpy/trader/gateway/bitfinexGateway/bitfinexGateway.py @@ -182,10 +182,13 @@ class GatewayApi(BitfinexApi): self.start() self.writeLog(u'交易API启动成功') - for symbol in symbols: + #---------------------------------------------------------------------- + def onConnect(self): + """""" + for symbol in self.symbols: self.subscribe(symbol, 'ticker') self.subscribe(symbol, 'book') - self.writeLog(u'行情推送订阅成功') + self.writeLog(u'行情推送订阅成功') self.authenticate() self.writeLog(u'交易推送订阅成功')