Repository: rotki/rotki

Issue:
Change FTX endpoint used to validate API keys
## Problem Definition

Before 1.18 to test that a pair of keys are valid we tried to query the `all_balances` endpoint. This was intended because the keys needed to be able to query all the endpoints.

With the introduction of subaccounts this will fail unless the keys have permission for all the accounts. I didn't detect this since the Keys I used had full permissions but my guess is that this could fail. The endpoint we should query now is https://docs.ftx.com/#get-account-information



Discussion:
Ah nice catch @yabirgb. Should be trivial to change.

Resolving patch:
diff --git a/rotkehlchen/exchanges/ftx.py b/rotkehlchen/exchanges/ftx.py
--- a/rotkehlchen/exchanges/ftx.py
+++ b/rotkehlchen/exchanges/ftx.py
@@ -136,12 +136,19 @@ def edit_exchange_credentials(
 
     def validate_api_key(self) -> Tuple[bool, str]:
         """Validates that the FTX API key is good for usage in rotki"""
+        endpoint: Literal['account', 'wallet/all_balances']
+
+        if self.subaccount is None:
+            endpoint = 'wallet/all_balances'
+        else:
+            endpoint = 'account'
+
         try:
-            self._api_query('wallet/all_balances', paginate=False)
+            self._api_query(endpoint=endpoint, paginate=False)
         except RemoteError as e:
             error = str(e)
             if 'Not logged in' in error:
-                return False, 'Bad combination of API Keys'
+                return False, 'Error validating API Keys'
             raise
         return True, ''
 
@@ -237,6 +244,17 @@ def _api_query(  # pylint: disable=no-self-use
     ) -> List[Dict[str, Any]]:
         ...
 
+    @overload
+    def _api_query(  # pylint: disable=no-self-use
+            self,
+            endpoint: Literal['account'],
+            start_time: Optional[Timestamp] = None,
+            end_time: Optional[Timestamp] = None,
+            limit: int = PAGINATION_LIMIT,
+            paginate: bool = True,
+    ) -> Dict[str, Any]:
+        ...
+
     @overload
     def _api_query(
             self,
@@ -261,7 +279,7 @@ def _api_query(
             end_time: Optional[Timestamp] = None,
             limit: int = PAGINATION_LIMIT,
             paginate: bool = True,
-    ) -> Union[List[Dict[str, Any]], Dict[str, List[Any]]]:
+    ) -> Union[List[Dict[str, Any]], Dict[str, List[Any]], Dict[str, Any]]:
         """Query FTX endpoint and retrieve all available information if pagination
         is requested. In case of paginate being set to False only one request is made.
         Can raise:


Test patch:
diff --git a/rotkehlchen/tests/api/test_exchanges.py b/rotkehlchen/tests/api/test_exchanges.py
--- a/rotkehlchen/tests/api/test_exchanges.py
+++ b/rotkehlchen/tests/api/test_exchanges.py
@@ -107,7 +107,7 @@ def test_setup_exchange(rotkehlchen_api_server):
                 BITSTAMP_API_KEY_ERROR_CODE_ACTION['API0011'],
                 BITFINEX_API_KEY_ERROR_MESSAGE,
                 KUCOIN_API_KEY_ERROR_CODE[400003],
-                'Bad combination of API Keys',
+                'Error validating API Keys',
                 'ApiKey has invalid value',
             ],
             status_code=HTTPStatus.CONFLICT,