Repository: rotki/rotki

Issue:
Feedback on generic impact functionality
Type	Location	Base Currency	Buy Amount	Sell Amount	Quote Currency	Timestamp	Fee	Fee Currency
Sell	binance	ETH	1	2	EUR	1		
Sell	binance	ETH	1	2	EUR	1		
Buy	binance	XMR	1	2.     ETH	1		
Buy	binance	XMR	1	2.     ETH	1		

A few things I just noticed

- if I define "Type" "sell" then rotki will import it as "Buy". If I define "Type" as "Sell" it properly imports it as "Sell"
- the docs say that Fee, Fee Currency and Description are optional, but the importer at least requires the headers. IMO it'd be nice if it could tolerate not getting those headers


Discussion:
Hey @TimDaub since for issues we want to have actionable items let me see if I understand what you are asking.

### Should Error on unknown headers

> if I define "Type" "sell" then rotki will import it as "Buy"

For this I guess you would expect an error and not silently sending it to another type

### Case-insensitive headers

sell, Sell, SELL, sElL should all map to the same.


-------------------------------

> the docs say that Fee, Fee Currency and Description are optional, but the importer at least requires the headers. IMO it'd be nice if it could tolerate not getting those headers

The headers are not optional but the value in the column is optional.
To close this issue up @OjusWiZard take this one as it's easy.

Just do the small stuff I mentioned above and make it against bugfixes.

The stuff I mentioned should essentially all be here: https://github.com/rotki/rotki/blob/b8a8c48d6ff482eb0be02a1599a5fef730c9f79c/rotkehlchen/data_import/importers/rotki_trades.py#L27

Resolving patch:
diff --git a/rotkehlchen/data_import/importers/rotki_trades.py b/rotkehlchen/data_import/importers/rotki_trades.py
--- a/rotkehlchen/data_import/importers/rotki_trades.py
+++ b/rotkehlchen/data_import/importers/rotki_trades.py
@@ -47,7 +47,7 @@ def _consume_rotki_trades(
             rate=Price(amount_sold / amount_bought),
             base_asset=asset,
             quote_asset=symbol_to_asset_or_token(csv_row['Quote Currency']),
-            trade_type=TradeType.SELL if csv_row['Type'] == 'Sell' else TradeType.BUY,
+            trade_type=TradeType.deserialize(csv_row['Type']),
             amount=amount_bought,
             notes=csv_row['Description'],
         )
diff --git a/rotkehlchen/types.py b/rotkehlchen/types.py
--- a/rotkehlchen/types.py
+++ b/rotkehlchen/types.py
@@ -673,13 +673,14 @@ def deserialize(cls: type['TradeType'], symbol: str) -> 'TradeType':
                 f'Failed to deserialize trade type symbol from {type(symbol)} entry',
             )
 
-        if symbol in {'buy', 'LIMIT_BUY', 'BUY', 'Buy'}:
+        sanitized_symbol = symbol.strip().lower()
+        if sanitized_symbol in {'buy', 'limit_buy'}:
             return TradeType.BUY
-        if symbol in {'sell', 'LIMIT_SELL', 'SELL', 'Sell'}:
+        if sanitized_symbol in {'sell', 'limit_sell'}:
             return TradeType.SELL
-        if symbol in {'settlement_buy', 'settlement buy'}:
+        if sanitized_symbol in {'settlement_buy', 'settlement buy'}:
             return TradeType.SETTLEMENT_BUY
-        if symbol in {'settlement_sell', 'settlement sell'}:
+        if sanitized_symbol in {'settlement_sell', 'settlement sell'}:
             return TradeType.SETTLEMENT_SELL
 
         # else


Test patch:
diff --git a/rotkehlchen/tests/data/rotki_generic_trades.csv b/rotkehlchen/tests/data/rotki_generic_trades.csv
--- a/rotkehlchen/tests/data/rotki_generic_trades.csv
+++ b/rotkehlchen/tests/data/rotki_generic_trades.csv
@@ -1,6 +1,6 @@
 Location,Base Currency,Quote Currency,Type,Buy Amount,Sell Amount,Fee,Fee Currency,Description,Timestamp
 binance,eip155:1/erc20:0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48,ETH,Sell,1.0000,1875.64,,,Trade USDC for ETH,1659085200000
-kraken,BTC,LTC,Buy,4.3241,392.8870,,,Trade LTC for BTC,1659171600000
-kucoin,eip155:1/erc20:0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984,eip155:1/erc20:0x6B175474E89094C44Da98b954EedeAC495271d0F,Sell,880.0000,20.0000,0.1040,USD,Trade UNI for DAI,1659344400000
-luno,BCH,ADA,Buy,16.3444,4576.6400,5.1345,USD,Trade ADA for BCH,1659344900000
-bisq,eip155:1/erc20:0x6B175474E89094C44Da98b954EedeAC495271d0F,eip155:1/erc20:0xdAC17F958D2ee523a2206206994597C13D831ec7,Buy,0,4576.6400,5.1345,USD,Trade USDT for DAI,1659345600000
+kraken,BTC,LTC,bUy,4.3241,392.8870,,,Trade LTC for BTC,1659171600000
+kucoin,eip155:1/erc20:0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984,eip155:1/erc20:0x6B175474E89094C44Da98b954EedeAC495271d0F, seLl,880.0000,20.0000,0.1040,USD,Trade UNI for DAI,1659344400000
+luno,BCH,ADA,buY ,16.3444,4576.6400,5.1345,USD,Trade ADA for BCH,1659344900000
+bisq,eip155:1/erc20:0x6B175474E89094C44Da98b954EedeAC495271d0F,eip155:1/erc20:0xdAC17F958D2ee523a2206206994597C13D831ec7, BuY ,0,4576.6400,5.1345,USD,Trade USDT for DAI,1659345600000
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
@@ -1974,7 +1974,7 @@ def assert_rotki_generic_trades_import_results(rotki: Rotkehlchen):
 
     expected_warnings = [
         'Deserialization error during rotki generic trades CSV import. Failed to deserialize Location value luno. Ignoring entry',  # noqa: E501
-        "During rotki generic trades import, csv row {'Location': 'bisq', 'Base Currency': 'eip155:1/erc20:0x6B175474E89094C44Da98b954EedeAC495271d0F', 'Quote Currency': 'eip155:1/erc20:0xdAC17F958D2ee523a2206206994597C13D831ec7', 'Type': 'Buy', 'Buy Amount': '0', 'Sell Amount': '4576.6400', 'Fee': '5.1345', 'Fee Currency': 'USD', 'Description': 'Trade USDT for DAI', 'Timestamp': '1659345600000'} has zero amount bought. Ignoring entry",  # noqa: E501
+        "During rotki generic trades import, csv row {'Location': 'bisq', 'Base Currency': 'eip155:1/erc20:0x6B175474E89094C44Da98b954EedeAC495271d0F', 'Quote Currency': 'eip155:1/erc20:0xdAC17F958D2ee523a2206206994597C13D831ec7', 'Type': ' BuY ', 'Buy Amount': '0', 'Sell Amount': '4576.6400', 'Fee': '5.1345', 'Fee Currency': 'USD', 'Description': 'Trade USDT for DAI', 'Timestamp': '1659345600000'} has zero amount bought. Ignoring entry",  # noqa: E501
     ]
     assert trades == expected_trades
     assert warnings == expected_warnings