-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Invalid normalization of exchange rate #7770
Comments
where exactly does it happen? |
It is the value stored in the exchange_quotes variable of FxFetcher (or how it's called). And when calling exchange_rate() method it returns a Decimal with the rate, but it has many more numbers after the dot than needed (for usd for example, usually you would have 2-3 decimal places, not ~= 30) |
@ecdsa the root cause is in the exchange-specific json-parsing, e.g. electrum/electrum/exchange_rate.py Line 284 in e992e3a
electrum/electrum/exchange_rate.py Line 307 in e992e3a
note that the historical rates are also affected, sort of independently |
Note that CoinGecko specifically, for historical prices, sends ~max resolution floats, e.g.:
but anyway, @MrNaif2018 is right that we should just convert the raw data to string first |
@MrNaif2018 how did you notice in the first place? the effect should be hidden from the GUI/etc AFAICT, as most methods go through Anyway, the types the internal methods expect/return are quite messy and the faulty float conversion might still somehow leak out, so I've tried to fix this and clean it up a bit at the same time. |
I noticed this via https://github.com/bitcartcc/bitcart/blob/91b4ca933d474b137b5e6c876315dc93840752fe/daemons/btc.py#L438-L444 Will test it now |
Hi! I wonder, why does electrum convert rates got from coingecko API this way? They are returned as floats (with correct number of digits, so assume it is like a string, but in float format). But when casting float to Decimal it uses it's binary representation, which makes no sense for a currency with 2 digits. Maybe we could use
Decimal(str(price))
instead of justDecimal(price)
? I think this applies to most exchange rates providers, but if it were fixed for coingecko and coindesk it would be fine for meThe text was updated successfully, but these errors were encountered: