From 8589c52cda976bc4cd32d2172526feb0cef018d3 Mon Sep 17 00:00:00 2001 From: "T.Todua" <7117978+ttodua@users.noreply.github.com> Date: Fri, 30 Dec 2022 16:02:03 +0400 Subject: [PATCH] precision update --- js/base/functions/number.js | 4 ++++ js/digifinex.js | 17 +++++++---------- php/Exchange.php | 4 ++++ python/ccxt/base/exchange.py | 5 ++++- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/js/base/functions/number.js b/js/base/functions/number.js index 16dc1b98748b..1ee8e049215a 100644 --- a/js/base/functions/number.js +++ b/js/base/functions/number.js @@ -93,6 +93,10 @@ function precisionFromString (str) { const numStr = str.replace (/\de/, '') return parseInt (numStr) * -1 } + // support integer formats (without dot) like '1', '10' etc + if (str.indexOf ('.') === -1) { + return str.length * -1 + } // default strings like '0.0001' const split = str.replace (/0+$/g, '').split ('.') return (split.length > 1) ? (split[1].length) : 0 diff --git a/js/digifinex.js b/js/digifinex.js index 6045c66d5e7c..e243c71b5f72 100644 --- a/js/digifinex.js +++ b/js/digifinex.js @@ -408,17 +408,14 @@ module.exports = class digifinex extends Exchange { const withdraw = withdrawStatus > 0; const active = deposit && withdraw; const feeString = this.safeString (currency, 'min_withdraw_fee'); // withdraw_fee_rate was zero for all currencies, so this was the worst case scenario - const fee = this.parseNumber (feeString); const minWithdrawString = this.safeString (currency, 'min_withdraw_amount'); - const minWithdraw = this.parseNumber (minWithdrawString); const minDepositString = this.safeString (currency, 'min_deposit_amount'); - const minDepositPrecisionLength = this.precisionFromString (minDepositString); - // define precision with temporary way - const feePrecisionLength = this.precisionFromString (feeString); - const minWithdrawPrecisionLength = this.precisionFromString (minWithdrawString); const minDeposit = this.parseNumber (minDepositString); - const maxFoundPrecision = Math.max (feePrecisionLength, Math.max (minWithdrawPrecisionLength, minDepositPrecisionLength)); - const precision = this.parseNumber (this.parsePrecision (this.numberToString (maxFoundPrecision))); + const minWithdraw = this.parseNumber (minWithdrawString); + const fee = this.parseNumber (feeString); + // define precision with temporary way + const minFoundPrecision = Precise.stringMin (feeString, Precise.stringMin (minDepositString, minWithdrawString)); + const precision = this.parseNumber (minFoundPrecision); const networkId = this.safeString (currency, 'chain'); const networkCode = this.networkIdToCode (networkId); const network = { @@ -426,7 +423,7 @@ module.exports = class digifinex extends Exchange { 'id': networkId, 'network': networkCode, 'active': active, - 'fee': this.parseNumber (feeString), + 'fee': fee, 'precision': precision, 'deposit': deposit, 'withdraw': withdraw, @@ -472,7 +469,7 @@ module.exports = class digifinex extends Exchange { 'active': active, 'deposit': deposit, 'withdraw': withdraw, - 'fee': fee, + 'fee': this.parseNumber (feeString), 'precision': undefined, 'limits': { 'amount': { diff --git a/php/Exchange.php b/php/Exchange.php index d803c7019b25..3764d6019ae6 100644 --- a/php/Exchange.php +++ b/php/Exchange.php @@ -1949,6 +1949,10 @@ public function precision_from_string($str) { $numStr = preg_replace ('/\de/', '', $str); return ((int)$numStr) * -1; } + // support integer formats (without dot) like '1', '10' etc + if (strpos($str, '.') === -1) { + return strlen(str) * -1; + } // default strings like '0.0001' $parts = explode('.', preg_replace('/0+$/', '', $str)); return (count($parts) > 1) ? strlen($parts[1]) : 0; diff --git a/python/ccxt/base/exchange.py b/python/ccxt/base/exchange.py index ece48cf2927a..62009d94e07c 100644 --- a/python/ccxt/base/exchange.py +++ b/python/ccxt/base/exchange.py @@ -1435,9 +1435,12 @@ def check_address(self, address): def precision_from_string(self, str): # support string formats like '1e-4' - if ('e' in str): + if 'e' in str: numStr = re.sub(r'\de', '', str) return int(numStr) * -1 + # support integer formats (without dot) like '1', '10' etc + if not ('.' in str): + return len(str) * -1 # default strings like '0.0001' parts = re.sub(r'0+$', '', str).split('.') return len(parts[1]) if len(parts) > 1 else 0