Repository: rotki/rotki

Issue:
Cryptocom CSV import inconsistant rate
## Problem Definition

A BTC to CRO crypto exchange transaction(single exchange CSV line) and a BTC to CRO dust conversion transaction (from 2 CSV lines, one debit, one credit) does not have the same computation rule. 

One is inverted

_consume_cryptocom_entry()
rate = Price(abs(**quote_amount_sold** / base_amount_bought))

_import_cryptocom_associated_entries()
rate = Price(abs(base_amount_bought / **quote_amount_sold**))




Discussion:
Thank you for opening an issue @CyBHFal!

Do you have an example csv file where these rules are touched along with what you would expect to happen as opposed to what is happening?

Timestamp (UTC),Transaction Description,Currency,Amount,To Currency,To Amount,Native Currency,Native Amount,Native Amount (in USD),Transaction Kind
2021-12-23 13:13:03,Convert Dust,CRO,0.686163538568182018,,,EUR,0.33,0.374813076,dust_conversion_credited
2021-12-23 13:13:03,Convert Dust,BTC,-0.00000782,,,EUR,-0.33,-0.374813076,dust_conversion_debited
2021-12-23 11:46:07,BTC -> CRO,BTC,-0.0822767,CRO,7248.8,EUR,3481.74,3954.550543128,crypto_exchange

![image](https://user-images.githubusercontent.com/32815303/147422441-1cb3120e-60a4-43c1-9995-9b2ef052c0f6.png)

Same direction (BTC to CRO) but see rates ... 

Resolving patch:
diff --git a/rotkehlchen/data/importer.py b/rotkehlchen/data/importer.py
--- a/rotkehlchen/data/importer.py
+++ b/rotkehlchen/data/importer.py
@@ -580,7 +580,7 @@ def _import_cryptocom_associated_entries(
                     base_amount_bought = deserialize_asset_amount(
                         credited_row['Amount'],
                     ) * part_of_total
-                    rate = Price(abs(base_amount_bought / quote_amount_sold))
+                    rate = Price(abs(quote_amount_sold / base_amount_bought))
 
                     trade = Trade(
                         timestamp=timestamp,
diff --git a/rotkehlchen/db/dbhandler.py b/rotkehlchen/db/dbhandler.py
--- a/rotkehlchen/db/dbhandler.py
+++ b/rotkehlchen/db/dbhandler.py
@@ -1970,6 +1970,12 @@ def edit_exchange(
             try:
                 exchange_name = new_name if new_name is not None else name
                 self.set_binance_pairs(exchange_name, binance_markets, location)
+                # Also delete used query ranges to allow fetching missing trades
+                # from the possible new pairs
+                cursor.execute(
+                    'DELETE FROM used_query_ranges WHERE name LIKE ? ESCAPE ?;',
+                    (f'{str(location)}\\_trades_%', '\\'),
+                )
             except sqlcipher.DatabaseError as e:  # pylint: disable=no-member
                 self.conn.rollback()
                 raise InputError(f'Could not update DB user_credentials_mappings due to {str(e)}') from e  # noqa: E501


Test patch:
diff --git a/rotkehlchen/tests/utils/dataimport.py b/rotkehlchen/tests/utils/dataimport.py
--- a/rotkehlchen/tests/utils/dataimport.py
+++ b/rotkehlchen/tests/utils/dataimport.py
@@ -202,7 +202,7 @@ def assert_cryptocom_import_results(rotki: Rotkehlchen):
         quote_asset=A_MCO,
         trade_type=TradeType.BUY,
         amount=AssetAmount(FVal('1382.306147552291')),
-        rate=Price(FVal('27.6439')),
+        rate=Price(FVal('0.03617434587739067208317205604')),
         fee=Fee(ZERO),
         fee_currency=A_USD,
         link='',
@@ -214,7 +214,7 @@ def assert_cryptocom_import_results(rotki: Rotkehlchen):
         quote_asset=A_MCO,
         trade_type=TradeType.BUY,
         amount=AssetAmount(FVal('1301.64')),
-        rate=Price(FVal('26.0328')),
+        rate=Price(FVal('0.03841307888509879843889247411')),
         fee=Fee(ZERO),
         fee_currency=A_USD,
         link='',
@@ -262,7 +262,7 @@ def assert_cryptocom_import_results(rotki: Rotkehlchen):
         quote_asset=A_DAI,
         trade_type=TradeType.BUY,
         amount=AssetAmount(FVal('0.007231228760408149')),
-        rate=Price(FVal('14.26830000900286970270179629')),
+        rate=Price(FVal('0.07008543409999999780915783127')),
         fee=Fee(ZERO),
         fee_currency=A_USD,
         link='',
@@ -274,7 +274,7 @@ def assert_cryptocom_import_results(rotki: Rotkehlchen):
         quote_asset=A_UNI,
         trade_type=TradeType.BUY,
         amount=AssetAmount(FVal('105.9475889306405164438345865')),
-        rate=Price(FVal('144.1809293808791657040427665')),
+        rate=Price(FVal('0.006935730018484795149371149556')),
         fee=Fee(ZERO),
         fee_currency=A_USD,
         link='',
@@ -286,7 +286,7 @@ def assert_cryptocom_import_results(rotki: Rotkehlchen):
         quote_asset=A_DOT,
         trade_type=TradeType.BUY,
         amount=AssetAmount(FVal('87.08021007997850666616541352')),
-        rate=Price(FVal('306.6322128582378511862892551')),
+        rate=Price(FVal('0.003261235963040581838377118706')),
         fee=Fee(ZERO),
         fee_currency=A_USD,
         link='',
@@ -502,7 +502,7 @@ def assert_cryptocom_special_events_import_results(rotki: Rotkehlchen):
         quote_asset=symbol_to_asset_or_token('MCO'),
         trade_type=TradeType.BUY,
         amount=AssetAmount(FVal('1')),
-        rate=Price(FVal('10')),
+        rate=Price(FVal('0.1')),
         fee=Fee(ZERO),
         fee_currency=A_USD,
         link='',