Repository: rotki/rotki

Issue:
Nexo CSV not being correctly imported
## Problem Definition

One user reported that the description field raised a key error. After (s)he provided a CSV mocked file I could verify 
that several columns had different names and there where new columns

## Steps

1. Asked the original author of the issue for more information and if he could confirm that he had the same file
2. If indeed we had outdated information it's only a matter of renaming keys and it should be fixed
3. If there are several valid CSV files we should investigate different approaches 

Data that the user provided

```
Transaction,Type,Currency,Amount,USD Equivalent,Details,Outstanding Loan,Date / Time
NXT0000000001,LockingTermDeposit,EURX,-1,$1.1226435,approved / Transfer from Savings Wallet to Term Wallet,$0.00,2021-03-06 09:51
NXT0000000002,Interest,EURX,1,$1.16806918161,approved / EURx Interest Earned,$0.00,2021-03-06 01:20
NXT0000000003,ExchangeDepositedOn,EUR,10,$15.1411,approved / EUR,$0.00,2021-02-26 19:09
NXT0000000004,DepositToExchange,EUR,100,$120.1509,approved / EUR Top Up,$0.00,2021-02-26 14:58
NXT0000000005,WithdrawExchanged,EUR,-2000.79,$2500.63591346,approved / EUR Withdrawal,$0.00,2020-12-16 15:09
NXT0000000006,ExchangeToWithdraw,EURX,-2000.79,$2500.5364681,approved / User,$0.00,2020-12-16 21:18
NXT0000000007,Dividend,NEXO,10.3585507,$3.43448965222,approved / Loyalty Dividend,$0.00,2020-08-15 12:01
NXT0000000008,ExchangeToWithdraw,EURX,-2000,$2500.5,rejected / USER,$0.00,2020-08-15 01:10
NXT0000000009,Dividend,NEXO,22.5653042,$16.0708424630,approved / Base Dividend,$0.00,2019-08-15 17:01
NXT0000000010,ExchangeDepositedOn,EUR,10000,$11174.47,approved / EURx,$0.00,2019-08-15 23:47
NXT0000000011,Deposit,NEXO,1.00001,$5487.0248909704,approved / 0x999999999849662f1106541b0d2e78be4445e6d8d870ac8616a3cf79de969c9b,$0.00,2019-05-24 17:50
NXT0000000012,Withdrawal,BTC,-0.9995,$5574.2115,approved / BTC withdrawal,$0.00,2019-04-24 16:18
NXT0000000013,Deposit,BTC,1,$5579.7,approved / 3699999999999999999999999,$0.00,2019-04-24 14:42
```


### System Description

Rotki version: 1.17.1



Discussion:

Resolving patch:
diff --git a/rotkehlchen/data/importer.py b/rotkehlchen/data/importer.py
--- a/rotkehlchen/data/importer.py
+++ b/rotkehlchen/data/importer.py
@@ -792,10 +792,12 @@ def _consume_nexo(self, csv_row: Dict[str, Any]) -> None:
         - UnknownAsset
         - DeserializationError
         """
-        if 'rejected' not in csv_row['Description']:
+        ignored_entries = ('ExchangeToWithdraw', 'DepositToExchange')
+
+        if 'rejected' not in csv_row['Details']:
             timestamp = deserialize_timestamp_from_date(
-                date=csv_row['DateTime'],
-                formatstr='%Y-%m-%d %H:%M:%S',
+                date=csv_row['Date / Time'],
+                formatstr='%Y-%m-%d %H:%M',
                 location='NEXO',
             )
         else:
@@ -805,8 +807,9 @@ def _consume_nexo(self, csv_row: Dict[str, Any]) -> None:
         asset = symbol_to_asset_or_token(csv_row['Currency'])
         amount = deserialize_asset_amount_force_positive(csv_row['Amount'])
         entry_type = csv_row['Type']
+        transaction = csv_row['Transaction']
 
-        if entry_type in ('Deposit', 'ExchangeDepositedOn'):
+        if entry_type in ('Deposit', 'ExchangeDepositedOn', 'LockingTermDeposit'):
             asset_movement = AssetMovement(
                 location=Location.NEXO,
                 category=AssetMovementCategory.DEPOSIT,
@@ -817,7 +820,7 @@ def _consume_nexo(self, csv_row: Dict[str, Any]) -> None:
                 amount=amount,
                 fee=Fee(ZERO),
                 fee_asset=A_USD,
-                link='',
+                link=transaction,
             )
             self.db.add_asset_movements([asset_movement])
         elif entry_type in ('Withdrawal', 'WithdrawExchanged'):
@@ -831,7 +834,7 @@ def _consume_nexo(self, csv_row: Dict[str, Any]) -> None:
                 amount=amount,
                 fee=Fee(ZERO),
                 fee_asset=A_USD,
-                link='',
+                link=transaction,
             )
             self.db.add_asset_movements([asset_movement])
         elif entry_type == 'Withdrawal Fee':
@@ -848,7 +851,7 @@ def _consume_nexo(self, csv_row: Dict[str, Any]) -> None:
                 notes=f'{entry_type} from Nexo',
             )
             self.db_ledger.add_ledger_action(action)
-        elif entry_type in ('Interest', 'Bonus'):
+        elif entry_type in ('Interest', 'Bonus', 'Dividend'):
             action = LedgerAction(
                 identifier=0,  # whatever is not used at insertion
                 timestamp=timestamp,
@@ -858,10 +861,12 @@ def _consume_nexo(self, csv_row: Dict[str, Any]) -> None:
                 asset=asset,
                 rate=None,
                 rate_asset=None,
-                link=None,
+                link=transaction,
                 notes=f'{entry_type} from Nexo',
             )
             self.db_ledger.add_ledger_action(action)
+        elif entry_type in ignored_entries:
+            pass
         else:
             raise UnsupportedCSVEntry(f'Unsuported entry {entry_type}. Data: {csv_row}')
 


Test patch:
diff --git a/rotkehlchen/tests/data/nexo.csv b/rotkehlchen/tests/data/nexo.csv
--- a/rotkehlchen/tests/data/nexo.csv
+++ b/rotkehlchen/tests/data/nexo.csv
@@ -1,5 +1,14 @@
-TransactionID,Type,Currency,Amount,Description,OutstandingLoanValue,DateTime
-1,Deposit,ETH,1,approved / ETH deposit,,2021-01-01 01:00:00
-2,Withdrawal,ETH,0.5,approved / ETH Withdrawal,,2021-01-10 01:00:00
-3,Withdrawal Fee,ETH,0.001,approved / ETH Withdrawal Fee,,2021-01-11 02:00:00
-4,Interest,BTC,0.001,approved / BTC Interest Earned,,2021-01-11 02:10:00
\ No newline at end of file
+Transaction,Type,Currency,Amount,USD Equivalent,Details,Outstanding Loan,Date / Time
+NXT0000000001,LockingTermDeposit,USDC,-1,$1.1226435,approved / Transfer from Savings Wallet to Term Wallet,$0.00,2021-03-06 09:51
+NXT0000000002,Interest,USDC,1,$1.16806918161,approved / USDC Interest Earned,$0.00,2021-03-06 01:20
+NXT0000000003,ExchangeDepositedOn,EUR,10,$15.1411,approved / EUR,$0.00,2021-02-26 19:09
+NXT0000000004,DepositToExchange,EUR,100,$120.1509,approved / EUR Top Up,$0.00,2021-02-26 14:58
+NXT0000000005,WithdrawExchanged,EUR,-2000.79,$2500.63591346,approved / EUR Withdrawal,$0.00,2020-12-16 15:09
+NXT0000000006,ExchangeToWithdraw,USDC,-2000.79,$2500.5364681,approved / User,$0.00,2020-12-16 21:18
+NXT0000000007,Dividend,NEXO,10.3585507,$3.43448965222,approved / Loyalty Dividend,$0.00,2020-08-15 12:01
+NXT0000000008,ExchangeToWithdraw,USDC,-2000,$2500.5,rejected / USER,$0.00,2020-08-15 01:10
+NXT0000000009,Dividend,NEXO,22.5653042,$16.0708424630,approved / Base Dividend,$0.00,2019-08-15 17:01
+NXT0000000010,ExchangeDepositedOn,EUR,10000,$11174.47,approved / USDC,$0.00,2019-08-15 23:47
+NXT0000000011,Deposit,NEXO,1.00001,$5487.0248909704,approved / 0x999999999849662f1106541b0d2e78be4445e6d8d870ac8616a3cf79de969c9b,$0.00,2019-05-24 17:50
+NXT0000000012,Withdrawal,BTC,-0.9995,$5574.2115,approved / BTC withdrawal,$0.00,2019-04-24 16:18
+NXT0000000013,Deposit,BTC,1,$5579.7,approved / 3699999999999999999999999,$0.00,2019-04-24 14:42
\ No newline at end of file
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
@@ -480,52 +480,117 @@ def assert_nexo_results(rotki: Rotkehlchen):
     assert len(warnings) == 0
 
     expected_actions = [LedgerAction(
-        identifier=1,
-        timestamp=Timestamp(1610330400),
-        action_type=LedgerActionType.EXPENSE,
+        identifier=3,
+        timestamp=Timestamp(1565888460),
+        action_type=LedgerActionType.INCOME,
         location=Location.NEXO,
-        amount=AssetAmount(FVal('0.001')),
-        asset=A_ETH,
+        amount=AssetAmount(FVal('22.5653042')),
+        asset=symbol_to_asset_or_token('NEXO'),
         rate=None,
         rate_asset=None,
-        link=None,
-        notes='Withdrawal Fee from Nexo',
+        link='NXT0000000009',
+        notes='Dividend from Nexo',
     ), LedgerAction(
         identifier=2,
-        timestamp=Timestamp(1610331000),
+        timestamp=Timestamp(1597492860),
         action_type=LedgerActionType.INCOME,
         location=Location.NEXO,
-        amount=AssetAmount(FVal('0.001')),
-        asset=A_BTC,
+        amount=AssetAmount(FVal('10.3585507')),
+        asset=symbol_to_asset_or_token('NEXO'),
         rate=None,
         rate_asset=None,
-        link=None,
+        link='NXT0000000007',
+        notes='Dividend from Nexo',
+    ), LedgerAction(
+        identifier=1,
+        timestamp=Timestamp(1614993600),
+        action_type=LedgerActionType.INCOME,
+        location=Location.NEXO,
+        amount=AssetAmount(FVal('1')),
+        asset=symbol_to_asset_or_token('USDC'),
+        rate=None,
+        rate_asset=None,
+        link='NXT0000000002',
         notes='Interest from Nexo',
     )]
 
     expected_movements = [AssetMovement(
         location=Location.NEXO,
         category=AssetMovementCategory.DEPOSIT,
-        timestamp=Timestamp(1609462800),
+        timestamp=Timestamp(1556116920),
         address=None,
         transaction_id=None,
-        asset=A_ETH,
+        asset=A_BTC,
         amount=AssetAmount(FVal('1')),
         fee_asset=A_USD,
         fee=Fee(ZERO),
-        link='',
+        link='NXT0000000013',
     ), AssetMovement(
         location=Location.NEXO,
         category=AssetMovementCategory.WITHDRAWAL,
-        timestamp=Timestamp(1610240400),
+        timestamp=Timestamp(1556122680),
         address=None,
         transaction_id=None,
-        asset=A_ETH,
-        amount=AssetAmount(FVal('0.5')),
+        asset=A_BTC,
+        amount=AssetAmount(FVal('0.9995')),
         fee_asset=A_USD,
         fee=Fee(ZERO),
-        link='',
+        link='NXT0000000012',
+    ), AssetMovement(
+        location=Location.NEXO,
+        category=AssetMovementCategory.DEPOSIT,
+        timestamp=Timestamp(1558720200),
+        address=None,
+        transaction_id=None,
+        asset=symbol_to_asset_or_token('NEXO'),
+        amount=AssetAmount(FVal('1.00001')),
+        fee_asset=A_USD,
+        fee=Fee(ZERO),
+        link='NXT0000000011',
+    ), AssetMovement(
+        location=Location.NEXO,
+        category=AssetMovementCategory.DEPOSIT,
+        timestamp=Timestamp(1565912820),
+        address=None,
+        transaction_id=None,
+        asset=A_EUR,
+        amount=AssetAmount(FVal('10000')),
+        fee_asset=A_USD,
+        fee=Fee(ZERO),
+        link='NXT0000000010',
+    ), AssetMovement(
+        location=Location.NEXO,
+        category=AssetMovementCategory.WITHDRAWAL,
+        timestamp=Timestamp(1608131340),
+        address=None,
+        transaction_id=None,
+        asset=A_EUR,
+        amount=AssetAmount(FVal('2000.79')),
+        fee_asset=A_USD,
+        fee=Fee(ZERO),
+        link='NXT0000000005',
+    ), AssetMovement(
+        location=Location.NEXO,
+        category=AssetMovementCategory.DEPOSIT,
+        timestamp=Timestamp(1614366540),
+        address=None,
+        transaction_id=None,
+        asset=A_EUR,
+        amount=AssetAmount(FVal('10')),
+        fee_asset=A_USD,
+        fee=Fee(ZERO),
+        link='NXT0000000003',
+    ), AssetMovement(
+        location=Location.NEXO,
+        category=AssetMovementCategory.DEPOSIT,
+        timestamp=Timestamp(1615024260),
+        address=None,
+        transaction_id=None,
+        asset=symbol_to_asset_or_token('USDC'),
+        amount=AssetAmount(FVal('1')),
+        fee_asset=A_USD,
+        fee=Fee(ZERO),
+        link='NXT0000000001',
     )]
-
     assert ledger_actions == expected_actions
     assert asset_movements == expected_movements