Repository: rotki/rotki

Issue:
Binance API: sapi/v1/futures/loan/wallet - Error -1000
## Problem Definition

Since a few days, the binance API throws error -1000 (Unknown Error) on requests to sapi/v1/futures/loan/wallet.

## Logs

```
Could not save the balance snapshot at Binance. Binance account API request failed.
Could not reach binance due to Binance API request https://api.binance.com/sapi/v1/futures/loan/wallet?[...]
for futures/loan/wallet failed with
HTTP status code: 500,
error code: -1000 and
error message: An unknown error occurred while processing the request.
```

### System Description


Operating system:  LMDE 5, linux x64 5.10.0-16-amd64
Rotki version: 1.25.2



This is most probably a screwup on Binance side, removing API endpoints without warning.

Still, imho, an error on _one_ endpoint should not fail the whole backend. I think it would be better to throw a warning about that endpoint (as it does now), and keep going with the others, in order to get as much info from the backend as possible.



Discussion:
Seeing same issue as well
Yeah I am seeing the same. No idea why. Binance broke something: https://twitter.com/LefterisJP/status/1565449236673662976

The API endpoint is still there in their docs so they did not yolo remove it: https://binance-docs.github.io/apidocs/spot/en/#cross-collateral-repayment-history-user_data

Even if they had it should be a 404 not a 500 error.

Resolving patch:
diff --git a/rotkehlchen/exchanges/binance.py b/rotkehlchen/exchanges/binance.py
--- a/rotkehlchen/exchanges/binance.py
+++ b/rotkehlchen/exchanges/binance.py
@@ -661,6 +661,14 @@ def _query_cross_collateral_futures_balances(
 
         return balances
 
+    def _query_margined_fapi(self, balances: DefaultDict[Asset, Balance]) -> DefaultDict[Asset, Balance]:  # noqa: E501
+        """Only a convenience function to give same interface as other query methods"""
+        return self._query_margined_futures_balances('fapi', balances)
+
+    def _query_margined_dapi(self, balances: DefaultDict[Asset, Balance]) -> DefaultDict[Asset, Balance]:  # noqa: E501
+        """Only a convenience function to give same interface as other query methods"""
+        return self._query_margined_futures_balances('dapi', balances)
+
     def _query_margined_futures_balances(
             self,
             api_type: Literal['fapi', 'dapi'],
@@ -816,11 +824,17 @@ def query_balances(self) -> ExchangeQueryBalances:
             returned_balances: DefaultDict[Asset, Balance] = defaultdict(Balance)
             returned_balances = self._query_spot_balances(returned_balances)
             if self.location != Location.BINANCEUS:
-                returned_balances = self._query_lending_balances(returned_balances)
-                returned_balances = self._query_cross_collateral_futures_balances(returned_balances)  # noqa: E501
-                returned_balances = self._query_margined_futures_balances('fapi', returned_balances)  # noqa: E501
-                returned_balances = self._query_margined_futures_balances('dapi', returned_balances)  # noqa: E501
-                returned_balances = self._query_pools_balances(returned_balances)
+                for method in (
+                        self._query_lending_balances,
+                        self._query_cross_collateral_futures_balances,
+                        self._query_margined_fapi,
+                        self._query_margined_dapi,
+                        self._query_pools_balances,
+                ):
+                    try:
+                        returned_balances = method(returned_balances)
+                    except RemoteError as e:  # errors in any of these methods should not be fatal
+                        log.warning(f'Failed to query binance method {method.__name__} due to {str(e)}')  # noqa: E501
 
         except RemoteError as e:
             msg = (


Test patch: