Skip to content

Commit

Permalink
Merge pull request #7843 from frosty00/associateWalletFix
Browse files Browse the repository at this point in the history
fix idex associateWallet bug #7842
  • Loading branch information
kroitor committed Oct 21, 2020
2 parents dd3531b + 0edebcf commit cf1ed9b
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions js/idex.js
Expand Up @@ -4,7 +4,7 @@

const Exchange = require ('./base/Exchange');
const { PAD_WITH_ZERO } = require ('./base/functions/number');
const { InvalidOrder, InsufficientFunds, ExchangeError, ExchangeNotAvailable, DDoSProtection, BadRequest, NotSupported } = require ('./base/errors');
const { InvalidOrder, InsufficientFunds, ExchangeError, ExchangeNotAvailable, DDoSProtection, BadRequest, NotSupported, InvalidAddress, AuthenticationError } = require ('./base/errors');

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

Expand Down Expand Up @@ -102,14 +102,15 @@ module.exports = class idex extends Exchange {
'options': {
'defaultTimeInForce': 'gtc',
'defaultSelfTradePrevention': 'cn',
'associatedWallets': {},
},
'exceptions': {
'INVALID_ORDER_QUANTITY': InvalidOrder,
'INSUFFICIENT_FUNDS': InsufficientFunds,
'SERVICE_UNAVAILABLE': ExchangeNotAvailable,
'EXCEEDED_RATE_LIMIT': DDoSProtection,
'INVALID_PARAMETER': BadRequest,
'WALLET_NOT_ASSOCIATED': InvalidAddress,
'INVALID_WALLET_SIGNATURE': AuthenticationError,
},
'requiredCredentials': {
'walletAddress': true,
Expand Down Expand Up @@ -545,7 +546,6 @@ module.exports = class idex extends Exchange {

async fetchBalance (params = {}) {
await this.loadMarkets ();
await this.associateWallet (this.walletAddress);
const nonce1 = this.uuidv1 ();
const request = {
'nonce': nonce1,
Expand All @@ -560,7 +560,19 @@ module.exports = class idex extends Exchange {
// usdValue: null
// }, ...
// ]
const response = await this.privateGetBalances (this.extend (request, params));
const extendedRequest = this.extend (request, params);
let response = undefined;
try {
response = await this.privateGetBalances (extendedRequest);
} catch (e) {
if (e instanceof InvalidAddress) {
const walletAddress = extendedRequest['wallet'];
await this.associateWallet (walletAddress);
response = await this.privateGetBalances (extendedRequest);
} else {
throw e;
}
}
const result = {
'info': response,
};
Expand All @@ -582,7 +594,6 @@ module.exports = class idex extends Exchange {

async fetchMyTrades (symbol = undefined, since = undefined, limit = undefined, params = {}) {
await this.loadMarkets ();
await this.associateWallet (this.walletAddress);
let market = undefined;
const request = {
'nonce': this.uuidv1 (),
Expand Down Expand Up @@ -618,7 +629,19 @@ module.exports = class idex extends Exchange {
// txStatus: 'mined'
// }
// ]
const response = await this.privateGetFills (this.extend (request, params));
const extendedRequest = this.extend (request, params);
let response = undefined;
try {
response = await this.privateGetFills (extendedRequest);
} catch (e) {
if (e instanceof InvalidAddress) {
const walletAddress = extendedRequest['wallet'];
await this.associateWallet (walletAddress);
response = await this.privateGetFills (extendedRequest);
} else {
throw e;
}
}
return this.parseTrades (response, market, since, limit);
}

Expand Down Expand Up @@ -828,10 +851,6 @@ module.exports = class idex extends Exchange {
}

async associateWallet (walletAddress, params = {}) {
const alreadyAssociated = this.safeValue (this.options, 'associatedWallets', {});
if (walletAddress in alreadyAssociated) {
return;
}
const nonce = this.uuidv1 ();
const noPrefix = this.remove0xPrefix (walletAddress);
const byteArray = [
Expand All @@ -854,8 +873,6 @@ module.exports = class idex extends Exchange {
'signature': signature,
};
const result = await this.privatePostWallets (request);
alreadyAssociated[walletAddress] = true;
this.options['alreadyAssociated'] = alreadyAssociated;
return result;
}

Expand Down

0 comments on commit cf1ed9b

Please sign in to comment.