Skip to content

Commit

Permalink
Merge pull request #2929 from mkutny/hitbtc2errors
Browse files Browse the repository at this point in the history
hitbtc2: handleErrors: invalid price + switch to 'exceptions' map pattern
  • Loading branch information
kroitor committed May 23, 2018
2 parents a110d64 + db34f90 commit 6c342e4
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions js/hitbtc2.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,13 @@ module.exports = class hitbtc2 extends hitbtc {
'options': {
'defaultTimeInForce': 'FOK',
},
'exceptions': {},
'exceptions': {
'2010': InvalidOrder, // "Quantity not a valid number"
'2011': InvalidOrder, // "Quantity too low"
'2020': InvalidOrder, // "Price not a valid number"
'20002': OrderNotFound, // canceling non-existent order
'20001': InsufficientFunds,
},
});
}

Expand Down Expand Up @@ -1124,27 +1130,18 @@ module.exports = class hitbtc2 extends hitbtc {
// {"code":504,"message":"Gateway Timeout","description":""}
if ((code === 503) || (code === 504))
throw new ExchangeNotAvailable (feedback);
// {"error":{"code":20002,"message":"Order not found","description":""}}
if (body[0] === '{') {
let response = JSON.parse (body);
const response = JSON.parse (body);
if ('error' in response) {
if ('message' in response['error']) {
let message = response['error']['message'];
let code = this.safeString (response['error'], 'code');
let exceptions = this.exceptions;
if (code in exceptions) {
throw new exceptions[code] (feedback);
}
if (message === 'Order not found') {
throw new OrderNotFound (this.id + ' order not found in active orders');
} else if (message === 'Quantity not a valid number') {
throw new InvalidOrder (feedback);
} else if (message === 'Quantity too low') {
throw new InvalidOrder (feedback);
} else if (message === 'Insufficient funds') {
throw new InsufficientFunds (feedback);
} else if (message === 'Duplicate clientOrderId') {
throw new InvalidOrder (feedback);
}
const code = this.safeString (response['error'], 'code');
const exceptions = this.exceptions;
if (code in exceptions) {
throw new exceptions[code] (feedback);
}
const message = this.safeString (response['error'], 'message');
if (message === 'Duplicate clientOrderId') {
throw new InvalidOrder (feedback);
}
}
}
Expand Down

0 comments on commit 6c342e4

Please sign in to comment.