From d5e294ca806b99fdffa7ae9d2fb6019aab739ebf Mon Sep 17 00:00:00 2001 From: Max Kutny Date: Sun, 31 Dec 2017 11:29:42 +0200 Subject: [PATCH 1/3] virwox: fetchTrades fixed --- js/virwox.js | 51 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/js/virwox.js b/js/virwox.js index c0d82985eff9..9d2aab316666 100644 --- a/js/virwox.js +++ b/js/virwox.js @@ -182,13 +182,32 @@ module.exports = class virwox extends Exchange { }; } + parseTrade (trade, symbol = undefined) { + let timestamp = trade['time'] * 1000; + return { + 'id': trade['tid'], + 'timestamp': timestamp, + 'datetime': this.iso8601 (timestamp), + 'order': undefined, + 'symbol': symbol, + 'type': undefined, + 'side': undefined, + 'price': this.safeFloat(trade, 'price'), + 'amount': this.safeFloat(trade, 'vol'), + 'fee': undefined, + 'info': trade, + }; + } + async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) { await this.loadMarkets (); - let market = this.market (symbol); - return await this.publicGetRawTradeData (this.extend ({ - 'instrument': market['id'], + let response = await this.publicGetRawTradeData (this.extend ({ + 'instrument': symbol, 'timespan': 3600, }, params)); + let result = response['result']; + let trades = result['data']; + return this.parseTrades (trades, symbol); } async createOrder (market, type, side, amount, price = undefined, params = {}) { @@ -239,11 +258,25 @@ module.exports = class virwox extends Exchange { return { 'url': url, 'method': method, 'body': body, 'headers': headers }; } - async request (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) { - let response = await this.fetch2 (path, api, method, params, headers, body); - if ('error' in response) - if (response['error']) - throw new ExchangeError (this.id + ' ' + this.json (response)); - return response; + handleErrors (code, reason, url, method, headers, body) { + if (code == 200) { + if ((body[0] == '{') || (body[0] == '[')) { + let response = JSON.parse (body); + if ('result' in response) { + let result = response['result']; + if ('errorCode' in result) { + let errorCode = result['errorCode']; + if (errorCode != 'OK') { + throw new ExchangeError (this.id + ' error returned: ' + body); + } + } + } else { + throw new ExchangeError (this.id + ' malformed response: no result in response: ' + body); + } + } else { + // if not a JSON response + throw new ExchangeError (this.id + ' returned a non-JSON reply: ' + body); + } + } } } From ac10bbba6170e34143092ddbe519d720ee54e382 Mon Sep 17 00:00:00 2001 From: Max Kutny Date: Sun, 31 Dec 2017 12:13:52 +0200 Subject: [PATCH 2/3] virwox: transpilation errors --- js/virwox.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/virwox.js b/js/virwox.js index 9d2aab316666..f7b2e830e3f3 100644 --- a/js/virwox.js +++ b/js/virwox.js @@ -192,8 +192,8 @@ module.exports = class virwox extends Exchange { 'symbol': symbol, 'type': undefined, 'side': undefined, - 'price': this.safeFloat(trade, 'price'), - 'amount': this.safeFloat(trade, 'vol'), + 'price': this.safeFloat (trade, 'price'), + 'amount': this.safeFloat (trade, 'vol'), 'fee': undefined, 'info': trade, }; From 7830f60592656e88772f04accf5731b906f732de Mon Sep 17 00:00:00 2001 From: Max Kutny Date: Sun, 31 Dec 2017 12:52:21 +0200 Subject: [PATCH 3/3] virwox: transpilation fixes --- js/virwox.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/virwox.js b/js/virwox.js index f7b2e830e3f3..88ab48d0cb1c 100644 --- a/js/virwox.js +++ b/js/virwox.js @@ -183,7 +183,8 @@ module.exports = class virwox extends Exchange { } parseTrade (trade, symbol = undefined) { - let timestamp = trade['time'] * 1000; + let sec = this.safeInteger (trade, 'time'); + let timestamp = sec * 1000; return { 'id': trade['tid'], 'timestamp': timestamp,