Skip to content
This repository has been archived by the owner on Feb 16, 2020. It is now read-only.

Commit

Permalink
improved kraken error logging, see #931
Browse files Browse the repository at this point in the history
  • Loading branch information
askmike committed Aug 22, 2017
1 parent 4a42614 commit 2a7344d
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions exchanges/kraken.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ var Trader = function(config) {
this.kraken = new Kraken(this.key, this.secret);
}

Trader.prototype.retry = function(method, args, err) {
Trader.prototype.retry = function(method, args) {
var wait = +moment.duration(10, 'seconds');
log.debug(this.name, 'returned an error, retrying..', err);
log.debug(this.name, 'returned an error, retrying..');

var self = this;

Expand All @@ -102,8 +102,10 @@ Trader.prototype.retry = function(method, args, err) {
Trader.prototype.getTrades = function(since, callback, descending) {
var args = _.toArray(arguments);
var process = function(err, trades) {
if (err || !trades || trades.length === 0)
return this.retry(this.getTrades, args, err);
if (err || !trades || trades.length === 0) {
log.error('error getting trades', err);
return this.retry(this.getTrades, args);
}

var parsedTrades = [];
_.each(trades.result[this.pair], function(trade) {
Expand Down Expand Up @@ -142,8 +144,10 @@ Trader.prototype.getPortfolio = function(callback) {
else if(!_.isEmpty(data.error))
err = data.error;

if (err || !data.result)
return this.retry(this.getPortfolio, args, JSON.stringify(err));
if (err || !data.result) {
log.error(err);
return this.retry(this.getPortfolio, args);
}

var assetAmount = parseFloat( data.result[addPrefix(this.asset)] );
var currencyAmount = parseFloat( data.result[addPrefix(this.currency)] );
Expand Down Expand Up @@ -212,17 +216,18 @@ Trader.prototype.addOrder = function(tradeType, amount, price, callback) {
log.debug(tradeType.toUpperCase(), amount, this.asset, '@', price, this.currency);

var set = function(err, data) {

// console.log('blap', err, data);

if(!err && _.isEmpty(data))
err = 'no data';
else if(!err && !_.isEmpty(data.error))
err = data.error;

if(err)
return this.retry(
this.addOrder,
args,
'unable to ' + tradeType.toLowerCase() + ': ' + JSON.stringify(err)
);
if(err) {
log.error('unable to ' + tradeType.toLowerCase(), err);
return this.retry(this.addOrder, args);
}

var txid = data.result.txid[0];
log.debug('added order with txid:', txid);
Expand Down

0 comments on commit 2a7344d

Please sign in to comment.