Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
frosty00 committed Oct 20, 2020
1 parent 33def91 commit fbd52a4
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 entireRequest = this.extend (request, params);
let response = undefined;
try {
response = await this.privateGetBalances (entireRequest);
} catch (e) {
if (e instanceof InvalidAddress) {
const walletAddress = entireRequest['wallet'];
await this.associateWallet (walletAddress);
response = await this.privateGetBalances (entireRequest);
} 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 All @@ -598,6 +609,7 @@ module.exports = class idex extends Exchange {
if (limit !== undefined) {
request['limit'] = limit;
}
const entireRequest = this.extend (request, params);
// [
// {
// fillId: '48582d10-b9bb-3c4b-94d3-e67537cf2472',
Expand All @@ -618,7 +630,18 @@ module.exports = class idex extends Exchange {
// txStatus: 'mined'
// }
// ]
const response = await this.privateGetFills (this.extend (request, params));
let response = undefined;
try {
response = await this.privateGetFills (entireRequest);
} catch (e) {
if (e instanceof InvalidAddress) {
const walletAddress = entireRequest['wallet'];
await this.associateWallet (walletAddress);
response = await this.privateGetFills (entireRequest);
} 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 fbd52a4

Please sign in to comment.