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'交易推送订阅成功')