From c027f1d7c6a0e529ef4a4707280d7a4e56818c06 Mon Sep 17 00:00:00 2001 From: carlosmiei <43336371+carlosmiei@users.noreply.github.com> Date: Fri, 8 Jul 2022 10:23:44 +0100 Subject: [PATCH] fix reconnection --- js/hollaex.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/js/hollaex.js b/js/hollaex.js index afe9bee2b13c..ca1475dfe495 100644 --- a/js/hollaex.js +++ b/js/hollaex.js @@ -159,7 +159,7 @@ module.exports = class hollaex extends ccxt.hollaex { symbol = market['symbol']; messageHash += ':' + market['id']; } - const trades = await this.watchPrivate (messageHash, 'watchOrders', params); + const trades = await this.watchPrivate (messageHash, params); if (this.newUpdates) { limit = trades.getLimit (symbol, limit); } @@ -231,7 +231,7 @@ module.exports = class hollaex extends ccxt.hollaex { symbol = market['symbol']; messageHash += ':' + market['id']; } - const orders = await this.watchPrivate (messageHash, 'watchOrders', params); + const orders = await this.watchPrivate (messageHash, params); if (this.newUpdates) { limit = orders.getLimit (symbol, limit); } @@ -336,7 +336,7 @@ module.exports = class hollaex extends ccxt.hollaex { async watchBalance (params = {}) { const messageHash = 'wallet'; - return await this.watchPrivate (messageHash, 'watchBalance', params); + return await this.watchPrivate (messageHash, params); } handleBalance (client, message) { @@ -384,18 +384,17 @@ module.exports = class hollaex extends ccxt.hollaex { return await this.watch (url, messageHash, message, messageHash); } - async watchPrivate (messageHash, method, params = {}) { - const options = this.safeValue (this.options, method, {}); - let expires = this.safeString (options, 'api-expires'); + async watchPrivate (messageHash, params = {}) { + this.checkRequiredCredentials (); + let expires = this.safeString (this.options, 'ws-expires'); if (expires === undefined) { const timeout = parseInt (this.timeout / 1000); expires = this.sum (this.seconds (), timeout); expires = expires.toString (); // we need to memoize these values to avoid generating a new url on each method execution // that would trigger a new connection on each received message - this.options[method]['api-expires'] = expires; + this.options['ws-expires'] = expires; } - this.checkRequiredCredentials (); const url = this.urls['api']['ws']; const auth = 'CONNECT' + '/stream' + expires; const signature = this.hmac (this.encode (auth), this.encode (this.secret)); @@ -549,4 +548,14 @@ module.exports = class hollaex extends ccxt.hollaex { client.lastPong = this.milliseconds (); return message; } + + onError (client, error) { + this.options['ws-expires'] = undefined; + super.onError (client, error); + } + + onClose (client, error) { + this.options['ws-expires'] = undefined; + super.onError (client, error); + } };