Skip to content

Commit

Permalink
Merge pull request #2932 from egorFiNE/ef-gatecoin6
Browse files Browse the repository at this point in the history
gatecoin: error handling, cancelOrder and createOrder fixes
  • Loading branch information
kroitor committed May 31, 2018
2 parents 6a1fc6b + bdfa10d commit e738f3f
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions js/gatecoin.js
Expand Up @@ -3,7 +3,7 @@
// ---------------------------------------------------------------------------

const Exchange = require ('./base/Exchange');
const { ExchangeError, AuthenticationError, InvalidAddress, InsufficientFunds } = require ('./base/errors');
const { ExchangeError, AuthenticationError, InvalidAddress, InsufficientFunds, OrderNotFound, InvalidOrder, PermissionDenied } = require ('./base/errors');

// ---------------------------------------------------------------------------

Expand Down Expand Up @@ -198,6 +198,9 @@ module.exports = class gatecoin extends Exchange {
},
'exceptions': {
'1005': InsufficientFunds,
'1008': OrderNotFound,
'1057': InvalidOrder,
'1044': OrderNotFound, // already canceled
},
});
}
Expand Down Expand Up @@ -447,19 +450,27 @@ module.exports = class gatecoin extends Exchange {
throw new AuthenticationError (this.id + ' two-factor authentication requires a missing ValidationCode parameter');
}
let response = await this.privatePostTradeOrders (this.extend (order, params));
// At this point response.responseStatus.message has been verified
// in handleErrors() to be == 'OK', so we assume the order has
// indeed been opened.
return {
'info': response,
'id': response['clOrderId'],
'status': 'open',
'id': this.safeString (response, 'clOrderId'), // response['clOrderId'],
};
}

async cancelOrder (id, symbol = undefined, params = {}) {
await this.loadMarkets ();
return await this.privateDeleteTradeOrdersOrderID ({ 'OrderID': id });
const response = await this.privateDeleteTradeOrdersOrderID ({ 'OrderID': id });
return response;
}

parseOrderStatus (status) {
const statuses = {
'1': 'open', // New
'2': 'open', // Filling
'4': 'canceled',
'6': 'closed',
};
if (status in statuses)
Expand Down Expand Up @@ -595,15 +606,6 @@ module.exports = class gatecoin 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 ('responseStatus' in response)
if ('message' in response['responseStatus'])
if (response['responseStatus']['message'] === 'OK')
return response;
throw new ExchangeError (this.id + ' ' + this.json (response));
}

async withdraw (code, amount, address, tag = undefined, params = {}) {
this.checkAddress (address);
await this.loadMarkets ();
Expand Down Expand Up @@ -679,17 +681,24 @@ module.exports = class gatecoin extends Exchange {
return; // fallback to default error handler
if (body.length < 2)
return; // fallback to default error handler
if (body.indexOf ('You are not authorized') >= 0) {
throw new PermissionDenied (body);
}
if (body[0] === '{') {
let response = JSON.parse (body);
if ('responseStatus' in response) {
let errorCode = this.safeString (response['responseStatus'], 'errorCode');
let message = this.safeString (response['responseStatus'], 'message');
const feedback = this.id + ' ' + body;
if (typeof errorCode !== 'undefined') {
const feedback = this.id + ' ' + body;
const exceptions = this.exceptions;
if (errorCode in exceptions) {
throw new exceptions[errorCode] (feedback);
}
throw new ExchangeError (feedback);
// Sometimes there isn't 'errorCode' but 'message' is present and is not 'OK'
} else if (typeof message !== 'undefined' && message !== 'OK') {
throw new ExchangeError (feedback);
}
}
}
Expand Down

0 comments on commit e738f3f

Please sign in to comment.