Repository: rotki/rotki

Issue:
Bitmex API request failed due to: Signature not valid.
I added a Bitmex API key with no special permissions:

<img width="925" alt="Screen Shot 2020-08-07 at 12 30 54" src="https://user-images.githubusercontent.com/2758453/89637013-d900c380-d8a9-11ea-82c1-9a114a5aa6b5.png">

In rotki, I get:

```
[07/08/2020 12:25:54 CEST] rotkehlchen.exchanges.bitmex: Bitmex API request failed due to: Signature not valid.
```

Update:

```
python -m pytest rotkehlchen/tests/exchanges/test_bitmex.py::test_bitmex_api_signature
// passed
```


Discussion:
Hey @TimDaub thanks. We will look into the problem. Bitmex is a very special exchange due to the way it handles only contracts and not spot trades.

I have not used it myself since we made the integration, and have only used their sandbox version in order to create some tests which are working fine.

This is why you get

> python -m pytest rotkehlchen/tests/exchanges/test_bitmex.py::test_bitmex_api_signature
> // passed

This issue may take more time to investigate and as such probably won't make it in v1.6.2. But since you use the develop version it will be easy for you to test when we find out why this happens.

Additionally, if you have any time to look into the code and help us debug it since I assume you actively use bitmex that would be great.
Actually I debugged for a while but got tired. But I was able to narrow it to this section of the code: https://github.com/rotki/rotki/blob/develop/rotkehlchen/exchanges/bitmex.py#L216-L224

It's weird, because it seems that this call: https://github.com/rotki/rotki/blob/develop/rotkehlchen/exchanges/bitmex.py#L104 succeeds. However, the one with the query param `?currency=XBt` doesn't...

I imagine 

```
returned_balances = {}
usd_price = Inquirer().find_usd_price(A_BTC)
```

shouldn't be in the try statement too. 
Hey @LefterisJP @TimDaub the issue remains. Here is a documentation of the Bitmex Api with examples maybe it could help
https://www.bitmex.com/app/apiKeysUsage
Thank you @bugatsinho , indeed the issue remains as it has not been closed. Unless someone can provide us with a full debug log of the issue happening it's hard to debug without reproducing.

I will try to have another look and try reproducing with latest rotki. And also put it in a milestone for us to look at.
i would like to help. is there any way to provide you my debug log? What i have to do? 
@bugatsinho Definitely!

So (1) run rotki with debug log on: https://rotki.readthedocs.io/en/latest/contribute.html#id2

Then (2) once the problem occurs go to Help-> Logs directory and send us the `rotkehlchen.log` file.

Do not post it here. It may contain sensitive info and should not be public. Either join our discord and DM me: https://discord.gg/aGCxHG7

or send it via email to support@rotki.com

In any case joining the discord is a nice idea. Lots of stuff going on there :smile: 
thank you for the instructions!  i saw the option when i restart the app and i have the debug log! i will join discord asap 

Resolving patch:
diff --git a/rotkehlchen/exchanges/bitmex.py b/rotkehlchen/exchanges/bitmex.py
--- a/rotkehlchen/exchanges/bitmex.py
+++ b/rotkehlchen/exchanges/bitmex.py
@@ -148,13 +148,15 @@ def _api_query(
         data = ''
         if not options:
             request_path = request_path_no_args
+            signature_path = request_path
         else:
             request_path = request_path_no_args + '?' + urlencode(options)
+            signature_path = request_path_no_args if path == 'user/wallet' else request_path
 
         if path in BITMEX_PRIVATE_ENDPOINTS:
             self._generate_signature(
                 verb=verb,
-                path=request_path,
+                path=signature_path,
                 expires=expires,
                 data=data,
             )


Test patch: