Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

precisionFromString update #14206

Merged
merged 10 commits into from Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions js/base/functions/number.js
Expand Up @@ -87,8 +87,18 @@ const truncate_regExpCache = []
}
, truncate = (num, precision = 0) => parseFloat (truncate_to_string (num, precision))

function precisionFromString (string) {
const split = string.replace (/0+$/g, '').split ('.')
function precisionFromString (str) {
// support string formats like '1e-4'
if (str.indexOf ('e') > -1) {
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 ('.')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this 101th and next line was not touched.

return (split.length > 1) ? (split[1].length) : 0
}

Expand Down
17 changes: 7 additions & 10 deletions js/digifinex.js
Expand Up @@ -408,25 +408,22 @@ 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 = {
'info': currency,
'id': networkId,
'network': networkCode,
'active': active,
'fee': this.parseNumber (feeString),
'fee': fee,
'precision': precision,
'deposit': deposit,
'withdraw': withdraw,
Expand Down Expand Up @@ -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': {
Expand Down
14 changes: 12 additions & 2 deletions php/Exchange.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions python/ccxt/base/exchange.py
Expand Up @@ -1433,8 +1433,16 @@ 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('.')
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
# 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

def load_markets(self, reload=False, params={}):
Expand Down