Repository: rotki/rotki

Issue:
Large numbers appear in exported trades.csv
Currently, I'm creating tax reports for a specific year. One of the exchanges I'm using is Bittrex.
Rotki presents me with a usable output after generation. However, some of the values in the exported trades.csv file are most likely wrong, as I'm haven't traded these large amounts. Here is an example:

type | location | asset | price_in_EUR | fee_in_EUR | gained_or_invested_EUR | amount | taxable_amount | exchanged_for | exchanged_asset_EUR_exchange_rate | taxable_bought_cost_in_EUR | taxable_gain_in_EUR | taxable_profit_loss_in_EUR | time | is_virtual
-- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | --
sell | bittrex | USD | 23475264.75 | 8462.169168 | 8559476.693 | 0.04320853 | 0.04320853 | BTC | 9573.475 | 0 | 8365895.524 | -8563.475 | 14/05/2019 22:43:33 | FALSE
-- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | -- | --

(numbers are scrambled)

There are other assets where prices seem incorrect too. I'm happy to share more examples privately somehow. For now, it looks like this has specifically to do with the Bittrex exchange.



Discussion:
Hey @TimDaub can you find and send me the corresponding log entry from rotkehlchen.log to see the bittrex format of the trade?
You can also do so in Discord in a pm. https://discord.gg/aGCxHG7

Resolving patch:
diff --git a/rotkehlchen/exchanges/bittrex.py b/rotkehlchen/exchanges/bittrex.py
--- a/rotkehlchen/exchanges/bittrex.py
+++ b/rotkehlchen/exchanges/bittrex.py
@@ -21,12 +21,7 @@
     UnprocessableTradePair,
     UnsupportedAsset,
 )
-from rotkehlchen.exchanges.data_structures import (
-    AssetMovement,
-    Trade,
-    get_pair_position_asset,
-    trade_pair_from_assets,
-)
+from rotkehlchen.exchanges.data_structures import AssetMovement, Trade, get_pair_position_asset
 from rotkehlchen.exchanges.exchange import ExchangeInterface
 from rotkehlchen.fval import FVal
 from rotkehlchen.inquirer import Inquirer
@@ -79,13 +74,9 @@ def bittrex_pair_to_world(given_pair: str) -> TradePair:
             f'but found {type(given_pair)}',
         )
     pair = TradePair(given_pair.replace('-', '_'))
-    base_currency = asset_from_bittrex(get_pair_position_str(pair, 'first'))
-    quote_currency = asset_from_bittrex(get_pair_position_str(pair, 'second'))
-
-    # Since in Bittrex the base currency is the cost currency, iow in Bittrex
-    # for BTC_ETH we buy ETH with BTC and sell ETH for BTC, we need to turn it
-    # into the Rotkehlchen way which is following the base/quote approach.
-    pair = trade_pair_from_assets(quote_currency, base_currency)
+    # Check that there is no unsupported asset in the trade
+    _ = asset_from_bittrex(get_pair_position_str(pair, 'first'))
+    _ = asset_from_bittrex(get_pair_position_str(pair, 'second'))
     return pair
 
 


Test patch:
diff --git a/rotkehlchen/tests/exchanges/test_bittrex.py b/rotkehlchen/tests/exchanges/test_bittrex.py
--- a/rotkehlchen/tests/exchanges/test_bittrex.py
+++ b/rotkehlchen/tests/exchanges/test_bittrex.py
@@ -95,7 +95,7 @@ def mock_unknown_asset_return(method, url, json):  # pylint: disable=unused-argu
 BITTREX_LIMIT_TRADE = """
     {
       "id": "fd97d393-e9b9-4dd1-9dbf-f288fc72a185",
-      "marketSymbol": "BTC-LTC",
+      "marketSymbol": "LTC-BTC",
       "direction": "BUY",
       "type": "LIMIT",
       "fillQuantity": 667.03644955,
@@ -108,7 +108,7 @@ def mock_unknown_asset_return(method, url, json):  # pylint: disable=unused-argu
 BITTREX_MARKET_TRADE = """
     {
       "id": "ad97d393-19b9-6dd1-9dbf-f288fc72a185",
-      "marketSymbol": "BTC-ETH",
+      "marketSymbol": "ETH-BTC",
       "direction": "SELL",
       "type": "MARKET",
       "fillQuantity": 2,
@@ -221,14 +221,14 @@ def query_bittrex_and_test(
 
     # Check that for non-string pairs we give a graceful error
     input_str = history.replace(
-        '"marketSymbol": "BTC-LTC"',
+        '"marketSymbol": "LTC-BTC"',
         '"marketSymbol": 4324234',
     )
     query_bittrex_and_test(input_str, expected_warnings_num=0, expected_errors_num=1)
 
     # Check that for unsupported assets in the pair are caught
     input_str = history.replace(
-        '"marketSymbol": "BTC-LTC"',
+        '"marketSymbol": "LTC-BTC"',
         '"marketSymbol": "BTC-PTON"',
     )
     query_bittrex_and_test(
@@ -240,7 +240,7 @@ def query_bittrex_and_test(
 
     # Check that unprocessable pair is caught
     input_str = history.replace(
-        '"marketSymbol": "BTC-LTC"',
+        '"marketSymbol": "LTC-BTC"',
         '"marketSymbol": "SSSS"',
     )
     query_bittrex_and_test(
diff --git a/rotkehlchen/tests/utils/history.py b/rotkehlchen/tests/utils/history.py
--- a/rotkehlchen/tests/utils/history.py
+++ b/rotkehlchen/tests/utils/history.py
@@ -315,7 +315,7 @@ def mock_bittrex_api_queries(url, method, json):  # pylint: disable=unused-argum
             payload = """
 [{
       "id": "fd97d393-e9b9-4dd1-9dbf-f288fc72a185",
-      "marketSymbol": "BTC-LTC",
+      "marketSymbol": "LTC-BTC",
       "closedAt": "2017-05-01T15:00:00.00Z",
       "direction": "BUY",
       "type": "LIMIT",
@@ -324,7 +324,7 @@ def mock_bittrex_api_queries(url, method, json):  # pylint: disable=unused-argum
       "commission": 0.00004921
     }, {
       "id": "ad97d393-e9b9-4dd1-9dbf-f288fc72a185",
-      "marketSymbol": "ETH-LTC",
+      "marketSymbol": "LTC-ETH",
       "closedAt": "2017-05-02T15:00:00.00Z",
       "direction": "SELL",
       "type": "LIMIT",
@@ -342,7 +342,7 @@ def mock_bittrex_api_queries(url, method, json):  # pylint: disable=unused-argum
       "limit": 0.0000295
     }, {
       "id": "1d97d393-e9b9-4dd1-9dbf-f288fc72a185",
-      "marketSymbol": "ETH-IDONTEXIST",
+      "marketSymbol": "IDONTEXIST-ETH",
       "closedAt": "2017-05-02T15:00:00.00Z",
       "direction": "SELL",
       "type": "LIMIT",