Skip to content

Commit

Permalink
currencies precision
Browse files Browse the repository at this point in the history
  • Loading branch information
kroitor committed Dec 22, 2017
1 parent 0a62af0 commit ada760d
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 70 deletions.
13 changes: 11 additions & 2 deletions js/base/Exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ const { deepExtend
, extend
, sleep
, timeout
, flatten
, indexBy
, sortBy
, groupBy
, aggregate
, uuid
, precisionFromString } = functions
Expand Down Expand Up @@ -485,15 +487,22 @@ module.exports = class Exchange {
.map (market => ({
id: market.baseId || market.base,
code: market.base,
precision: market.precision ? (market.precision.base || market.precision.amount) : 8,
}))
const quoteCurrencies =
values.filter (market => 'quote' in market)
.map (market => ({
id: market.quoteId || market.quote,
code: market.quote,
precision: market.precision ? (market.precision.quote || market.precision.price) : 8,
}))
const currencies = sortBy (baseCurrencies.concat (quoteCurrencies), 'code')
this.currencies = deepExtend (indexBy (currencies, 'code'), this.currencies)
const allCurrencies = baseCurrencies.concat (quoteCurrencies)
const groupedCurrencies = groupBy (allCurrencies, 'code')
const currencies = Object.keys (groupedCurrencies).map (code =>
groupedCurrencies[code].reduce ((previous, current) =>
((previous.precision > current.precision) ? previous : current), groupedCurrencies[code][0]))
const sortedCurrencies = sortBy (flatten (currencies), 'code')
this.currencies = deepExtend (indexBy (sortedCurrencies, 'code'), this.currencies)
}
return this.markets
}
Expand Down
2 changes: 2 additions & 0 deletions js/binance.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ module.exports = class binance extends Exchange {
let symbol = base + '/' + quote;
let filters = this.indexBy (market['filters'], 'filterType');
let precision = {
'base': market['baseAssetPrecision'],
'quote': market['quotePrecision'],
'amount': market['baseAssetPrecision'],
'price': market['quotePrecision'],
};
Expand Down
15 changes: 6 additions & 9 deletions js/bittrex.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,7 @@ module.exports = class bittrex extends Exchange {
// to add support for multiple withdrawal/deposit methods and
// differentiated fees for each particular method
let code = this.commonCurrencyCode (id);
let precision = {
'amount': 8, // default precision, todo: fix "magic constants"
'price': 8,
};
let precision = 8; // default precision, todo: fix "magic constants"
result[code] = {
'id': id,
'code': code,
Expand All @@ -294,20 +291,20 @@ module.exports = class bittrex extends Exchange {
'precision': precision,
'limits': {
'amount': {
'min': Math.pow (10, -precision['amount']),
'max': Math.pow (10, precision['amount']),
'min': Math.pow (10, -precision),
'max': Math.pow (10, precision),
},
'price': {
'min': Math.pow (10, -precision['price']),
'max': Math.pow (10, precision['price']),
'min': Math.pow (10, -precision),
'max': Math.pow (10, precision),
},
'cost': {
'min': undefined,
'max': undefined,
},
'withdraw': {
'min': currency['TxFee'],
'max': Math.pow (10, precision['amount']),
'max': Math.pow (10, precision),
},
},
};
Expand Down
13 changes: 5 additions & 8 deletions js/coinmarketcap.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,7 @@ module.exports = class coinmarketcap extends Exchange {
// todo: will need to rethink the fees
// to add support for multiple withdrawal/deposit methods and
// differentiated fees for each particular method
let precision = {
'amount': 8, // default precision, todo: fix "magic constants"
'price': 8,
};
let precision = 8; // default precision, todo: fix "magic constants"
let code = this.commonCurrencyCode (id);
result[code] = {
'id': id,
Expand All @@ -215,12 +212,12 @@ module.exports = class coinmarketcap extends Exchange {
'precision': precision,
'limits': {
'amount': {
'min': Math.pow (10, -precision['amount']),
'max': Math.pow (10, precision['amount']),
'min': Math.pow (10, -precision),
'max': Math.pow (10, precision),
},
'price': {
'min': Math.pow (10, -precision['price']),
'max': Math.pow (10, precision['price']),
'min': Math.pow (10, -precision),
'max': Math.pow (10, precision),
},
'cost': {
'min': undefined,
Expand Down
11 changes: 4 additions & 7 deletions js/cryptopia.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,7 @@ module.exports = class cryptopia extends Exchange {
// todo: will need to rethink the fees
// to add support for multiple withdrawal/deposit methods and
// differentiated fees for each particular method
let precision = {
'amount': 8, // default precision, todo: fix "magic constants"
'price': 8,
};
let precision = 8; // default precision, todo: fix "magic constants"
let code = this.commonCurrencyCode (id);
let active = (currency['ListingStatus'] == 'Active');
let status = currency['Status'].toLowerCase ();
Expand All @@ -322,11 +319,11 @@ module.exports = class cryptopia extends Exchange {
'limits': {
'amount': {
'min': currency['MinBaseTrade'],
'max': Math.pow (10, precision['amount']),
'max': Math.pow (10, precision),
},
'price': {
'min': Math.pow (10, -precision['price']),
'max': Math.pow (10, precision['price']),
'min': Math.pow (10, -precision),
'max': Math.pow (10, precision),
},
'cost': {
'min': undefined,
Expand Down
15 changes: 6 additions & 9 deletions js/hitbtc2.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,10 +585,7 @@ module.exports = class hitbtc2 extends hitbtc {
// todo: will need to rethink the fees
// to add support for multiple withdrawal/deposit methods and
// differentiated fees for each particular method
let precision = {
'amount': 8, // default precision, todo: fix "magic constants"
'price': 8,
};
let precision = 8; // default precision, todo: fix "magic constants"
let code = this.commonCurrencyCode (id);
let payin = currency['payinEnabled'];
let payout = currency['payoutEnabled'];
Expand All @@ -614,20 +611,20 @@ module.exports = class hitbtc2 extends hitbtc {
'precision': precision,
'limits': {
'amount': {
'min': Math.pow (10, -precision['amount']),
'max': Math.pow (10, precision['amount']),
'min': Math.pow (10, -precision),
'max': Math.pow (10, precision),
},
'price': {
'min': Math.pow (10, -precision['price']),
'max': Math.pow (10, precision['price']),
'min': Math.pow (10, -precision),
'max': Math.pow (10, precision),
},
'cost': {
'min': undefined,
'max': undefined,
},
'withdraw': {
'min': undefined,
'max': Math.pow (10, precision['amount']),
'max': Math.pow (10, precision),
},
},
};
Expand Down
15 changes: 6 additions & 9 deletions js/kraken.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,7 @@ module.exports = class kraken extends Exchange {
// to add support for multiple withdrawal/deposit methods and
// differentiated fees for each particular method
let code = this.commonCurrencyCode (currency['altname']);
let precision = {
'amount': currency['decimals'], // default precision, todo: fix "magic constants"
'price': currency['decimals'],
};
let precision = currency['decimals'];
result[code] = {
'id': id,
'code': code,
Expand All @@ -315,20 +312,20 @@ module.exports = class kraken extends Exchange {
'precision': precision,
'limits': {
'amount': {
'min': Math.pow (10, -precision['amount']),
'max': Math.pow (10, precision['amount']),
'min': Math.pow (10, -precision),
'max': Math.pow (10, precision),
},
'price': {
'min': Math.pow (10, -precision['price']),
'max': Math.pow (10, precision['price']),
'min': Math.pow (10, -precision),
'max': Math.pow (10, precision),
},
'cost': {
'min': undefined,
'max': undefined,
},
'withdraw': {
'min': undefined,
'max': Math.pow (10, precision['amount']),
'max': Math.pow (10, precision),
},
},
};
Expand Down
15 changes: 6 additions & 9 deletions js/kucoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,7 @@ module.exports = class kucoin extends Exchange {
// to add support for multiple withdrawal/deposit methods and
// differentiated fees for each particular method
let code = this.commonCurrencyCode (id);
let precision = {
'amount': currency['tradePrecision'],
'price': currency['tradePrecision'],
};
let precision = currency['tradePrecision'];
let deposit = currency['enableDeposit'];
let withdraw = currency['enableWithdraw'];
let active = (deposit && withdraw);
Expand All @@ -180,20 +177,20 @@ module.exports = class kucoin extends Exchange {
'precision': precision,
'limits': {
'amount': {
'min': Math.pow (10, -precision['amount']),
'max': Math.pow (10, precision['amount']),
'min': Math.pow (10, -precision),
'max': Math.pow (10, precision),
},
'price': {
'min': Math.pow (10, -precision['price']),
'max': Math.pow (10, precision['price']),
'min': Math.pow (10, -precision),
'max': Math.pow (10, precision),
},
'cost': {
'min': undefined,
'max': undefined,
},
'withdraw': {
'min': currency['withdrawMinAmount'],
'max': Math.pow (10, precision['amount']),
'max': Math.pow (10, precision),
},
},
};
Expand Down
13 changes: 5 additions & 8 deletions js/livecoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,7 @@ module.exports = class livecoin extends Exchange {
// to add support for multiple withdrawal/deposit methods and
// differentiated fees for each particular method
let code = this.commonCurrencyCode (id);
let precision = {
'amount': 8, // default precision, todo: fix "magic constants"
'price': 5,
};
let precision = 8; // default precision, todo: fix "magic constants"
let active = (currency['walletStatus'] == 'normal');
result[code] = {
'id': id,
Expand All @@ -155,19 +152,19 @@ module.exports = class livecoin extends Exchange {
'limits': {
'amount': {
'min': currency['minOrderAmount'],
'max': Math.pow (10, precision['amount']),
'max': Math.pow (10, precision),
},
'price': {
'min': Math.pow (10, -precision['price']),
'max': Math.pow (10, precision['price']),
'min': Math.pow (10, -precision),
'max': Math.pow (10, precision),
},
'cost': {
'min': currency['minOrderAmount'],
'max': undefined,
},
'withdraw': {
'min': currency['minWithdrawAmount'],
'max': Math.pow (10, precision['amount']),
'max': Math.pow (10, precision),
},
'deposit': {
'min': currency['minDepositAmount'],
Expand Down
15 changes: 6 additions & 9 deletions js/poloniex.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,7 @@ module.exports = class poloniex extends Exchange {
// todo: will need to rethink the fees
// to add support for multiple withdrawal/deposit methods and
// differentiated fees for each particular method
let precision = {
'amount': 8, // default precision, todo: fix "magic constants"
'price': 8,
};
let precision = 8; // default precision, todo: fix "magic constants"
let code = this.commonCurrencyCode (id);
let active = (currency['delisted'] == 0);
let status = (currency['disabled']) ? 'disabled' : 'ok';
Expand All @@ -326,20 +323,20 @@ module.exports = class poloniex extends Exchange {
'precision': precision,
'limits': {
'amount': {
'min': Math.pow (10, -precision['amount']),
'max': Math.pow (10, precision['amount']),
'min': Math.pow (10, -precision),
'max': Math.pow (10, precision),
},
'price': {
'min': Math.pow (10, -precision['price']),
'max': Math.pow (10, precision['price']),
'min': Math.pow (10, -precision),
'max': Math.pow (10, precision),
},
'cost': {
'min': undefined,
'max': undefined,
},
'withdraw': {
'min': currency['txFee'],
'max': Math.pow (10, precision['amount']),
'max': Math.pow (10, precision),
},
},
};
Expand Down

0 comments on commit ada760d

Please sign in to comment.