From fbcb38ecbccdf68a430ea096718a3bd68d6812e8 Mon Sep 17 00:00:00 2001 From: "T.Todua" <7117978+ttodua@users.noreply.github.com> Date: Mon, 4 Jul 2022 18:50:44 +0400 Subject: [PATCH 1/9] precisionFromString update --- js/base/functions/number.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/js/base/functions/number.js b/js/base/functions/number.js index 4a8765586ca8..3d989a9c451b 100644 --- a/js/base/functions/number.js +++ b/js/base/functions/number.js @@ -87,9 +87,16 @@ const truncate_regExpCache = [] } , truncate = (num, precision = 0) => parseFloat (truncate_to_string (num, precision)) -function precisionFromString (string) { - const split = string.replace (/0+$/g, '').split ('.') - return (split.length > 1) ? (split[1].length) : 0 +function precisionFromString (str) { + // support string formats like '1e-4' + if (str.indexOf ('e') > -1) { + const numStr = str.replace (/\de/, ''); + return parseInt (numStr) * -1 + } else { + // default strings like '0.0001' + const split = str.replace (/0+$/g, '').split ('.') + return (split.length > 1) ? (split[1].length) : 0 + } } /* ------------------------------------------------------------------------ */ From b376ade6d171ec5fac5d88e3f879faf80c9c3d1b Mon Sep 17 00:00:00 2001 From: "T.Todua" <7117978+ttodua@users.noreply.github.com> Date: Mon, 4 Jul 2022 19:51:50 +0400 Subject: [PATCH 2/9] python & --- python/ccxt/base/exchange.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/python/ccxt/base/exchange.py b/python/ccxt/base/exchange.py index 746cc46d758d..c8b29649c341 100644 --- a/python/ccxt/base/exchange.py +++ b/python/ccxt/base/exchange.py @@ -1429,9 +1429,15 @@ def check_address(self, address): raise InvalidAddress(self.id + ' address is invalid or has less than ' + str(self.minFundingAddressLength) + ' characters: "' + str(address) + '"') return address - def precision_from_string(self, string): - parts = re.sub(r'0+$', '', string).split('.') - return len(parts[1]) if len(parts) > 1 else 0 + def precision_from_string(self, str): + # support string formats like '1e-4' + if ('e' in str): + numStr = re.sub(r'\de', '', str) + return int(numStr) * -1 + else: + parts = re.sub(r'0+$', '', str).split('.') + return len(parts[1]) if len(parts) > 1 else 0 + def load_markets(self, reload=False, params={}): if not reload: From 4aeca86773b43756d516e08bd22245e4dd4c5382 Mon Sep 17 00:00:00 2001 From: "T.Todua" <7117978+ttodua@users.noreply.github.com> Date: Mon, 4 Jul 2022 19:52:05 +0400 Subject: [PATCH 3/9] php --- php/Exchange.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/php/Exchange.php b/php/Exchange.php index 9f0f603209e6..188e16e42cc4 100644 --- a/php/Exchange.php +++ b/php/Exchange.php @@ -1918,9 +1918,16 @@ public function fetch_currencies($params = array()) { return $this->currencies ? $this->currencies : array(); } - public function precision_from_string($string) { - $parts = explode('.', preg_replace('/0+$/', '', $string)); - return (count($parts) > 1) ? strlen($parts[1]) : 0; + public function precision_from_string($str) { + // support string formats like '1e-4' + if (strpos($str, 'e') > -1) { + $numStr = preg_replace ('/\de/', '', $str); + return ((int)$numStr) * -1; + } else { + // default strings like '0.0001' + $parts = explode('.', preg_replace('/0+$/', '', $str)); + return (count($parts) > 1) ? strlen($parts[1]) : 0; + } } public function __call($function, $params) { From d1e830ce3d87570a2d69dfeba7c7cabf5f0cbd07 Mon Sep 17 00:00:00 2001 From: "T.Todua" <7117978+ttodua@users.noreply.github.com> Date: Mon, 4 Jul 2022 19:52:13 +0400 Subject: [PATCH 4/9] js --- js/base/functions/number.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/base/functions/number.js b/js/base/functions/number.js index 3d989a9c451b..a9f22fd79366 100644 --- a/js/base/functions/number.js +++ b/js/base/functions/number.js @@ -90,7 +90,7 @@ const truncate_regExpCache = [] function precisionFromString (str) { // support string formats like '1e-4' if (str.indexOf ('e') > -1) { - const numStr = str.replace (/\de/, ''); + const numStr = str.replace (/\de/, '') return parseInt (numStr) * -1 } else { // default strings like '0.0001' From 77b757a322791b85a7b8cd22ef065d03133d2565 Mon Sep 17 00:00:00 2001 From: "T.Todua" <7117978+ttodua@users.noreply.github.com> Date: Mon, 4 Jul 2022 19:58:26 +0400 Subject: [PATCH 5/9] lint --- python/ccxt/base/exchange.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/ccxt/base/exchange.py b/python/ccxt/base/exchange.py index c8b29649c341..5495de1e6290 100644 --- a/python/ccxt/base/exchange.py +++ b/python/ccxt/base/exchange.py @@ -1437,7 +1437,6 @@ def precision_from_string(self, str): else: parts = re.sub(r'0+$', '', str).split('.') return len(parts[1]) if len(parts) > 1 else 0 - def load_markets(self, reload=False, params={}): if not reload: From 2623c1a37317aafe8dc40a80cac47f2195e09e82 Mon Sep 17 00:00:00 2001 From: "T. Todua" <7117978+ttodua@users.noreply.github.com> Date: Thu, 29 Dec 2022 15:03:31 +0400 Subject: [PATCH 6/9] Update number.js --- js/base/functions/number.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/js/base/functions/number.js b/js/base/functions/number.js index a9f22fd79366..16dc1b98748b 100644 --- a/js/base/functions/number.js +++ b/js/base/functions/number.js @@ -92,11 +92,10 @@ function precisionFromString (str) { if (str.indexOf ('e') > -1) { const numStr = str.replace (/\de/, '') return parseInt (numStr) * -1 - } else { - // default strings like '0.0001' - const split = str.replace (/0+$/g, '').split ('.') - return (split.length > 1) ? (split[1].length) : 0 } + // default strings like '0.0001' + const split = str.replace (/0+$/g, '').split ('.') + return (split.length > 1) ? (split[1].length) : 0 } /* ------------------------------------------------------------------------ */ From 2dc772ac7c1e492a9c69676dd0cce957694d2319 Mon Sep 17 00:00:00 2001 From: "T. Todua" <7117978+ttodua@users.noreply.github.com> Date: Thu, 29 Dec 2022 15:04:00 +0400 Subject: [PATCH 7/9] Update Exchange.php --- php/Exchange.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/php/Exchange.php b/php/Exchange.php index 188e16e42cc4..16068428d878 100644 --- a/php/Exchange.php +++ b/php/Exchange.php @@ -1923,11 +1923,10 @@ public function precision_from_string($str) { if (strpos($str, 'e') > -1) { $numStr = preg_replace ('/\de/', '', $str); return ((int)$numStr) * -1; - } else { - // default strings like '0.0001' - $parts = explode('.', preg_replace('/0+$/', '', $str)); - return (count($parts) > 1) ? strlen($parts[1]) : 0; } + // default strings like '0.0001' + $parts = explode('.', preg_replace('/0+$/', '', $str)); + return (count($parts) > 1) ? strlen($parts[1]) : 0; } public function __call($function, $params) { From b7e1d26730980f7611b1f12afa79d0cf97d597c4 Mon Sep 17 00:00:00 2001 From: "T. Todua" <7117978+ttodua@users.noreply.github.com> Date: Thu, 29 Dec 2022 15:04:53 +0400 Subject: [PATCH 8/9] Update exchange.py --- python/ccxt/base/exchange.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/ccxt/base/exchange.py b/python/ccxt/base/exchange.py index 5495de1e6290..c03c923eb751 100644 --- a/python/ccxt/base/exchange.py +++ b/python/ccxt/base/exchange.py @@ -1434,9 +1434,9 @@ def precision_from_string(self, str): if ('e' in str): numStr = re.sub(r'\de', '', str) return int(numStr) * -1 - else: - parts = re.sub(r'0+$', '', str).split('.') - return len(parts[1]) if len(parts) > 1 else 0 + # default strings like '0.0001' + parts = re.sub(r'0+$', '', str).split('.') + return len(parts[1]) if len(parts) > 1 else 0 def load_markets(self, reload=False, params={}): if not reload: From f33592a35d872a84c138dc840956f3b6ec86b70b 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 9/9] 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..f1b37c3f0991 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 [Note: bug in decimalToPrecision, so this should not be used atm] + // 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..5fba9349e0a9 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 [Note: bug in decimalToPrecision, so this should not be used atm] + // 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..1e3a1461e3e3 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 [Note: bug in decimalToPrecision, so this should not be used atm] + # 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