Repository: rotki/rotki

Issue:
Rotki 1.33.0 not displaying cryptocurrency balance on OKX TR
## Problem Definition

<!-- Provide a description of what is the current problem and why you are raising this issue.
If it's a bug please describe what was the unexpected thing that occured and what was the
expected behaviour. -->

I am experiencing an issue with Rotki where it does not display my cryptocurrency balance on OKX, specifically the Turkish version available at https://tr.okx.com/. The expected behavior is that Rotki should be able to show all balances from supported exchanges, including OKX TR.


### System Description

Operating system: MacOS on Apple Silicon MacBook Pro  
Rotki version: 1.33.0




Discussion:
hey @izzetemredemir thanks for the issue and welcome!

Did 1.32.2 or previous versions work with that exchange. Rotki supports OKX normally and it should work. Previous OKX users have confirmed it.

If there is a separate exchange for Turkey, then we do not have any specific support for it and would probably need work to add it. If it's the same one but just has a different api base url that work should not be hard.

But without a test api key it's hard to do so. We don't have any Turkish people in our dev team. Could you perhaps share a test read only key to see how we can support it? You can contact us in discord via DM here: https://discord.rotki.com/
I think that only the API endpoint has changed, and that the API endpoints still work the same way. I believe a region selection feature should be added.
> I think that only the API endpoint has changed, and that the API endpoints still work the same way. I believe a region selection feature should be added.

Sure but without the ability to test it we can't do it and hope it works. It woud be cool to get an api key to test this. And yes our first move would be to just add OKX TR as an option with identical api to OKX and hope it works.

Another option if you don't want to give a key is to just really just add a selection, create a test binary for you and send it to you and tell us if it works.
I built and ran the code on my computer and tested it with OKX for the TR region. It turns out there was no need to change the endpoint. The reason I couldn't see my current balance on Rotki is because I had an active sell order in spot trading using all my funds. When you have an active trading order, it doesn't show up in the balance section, which might be a bug. After I canceled my sell order in spot trading, my balance appeared. This could be another bug; you may close the issue if you want, as I have completed the tests.
> The reason I couldn't see my current balance on Rotki is because I had an active sell order in spot trading using all my funds. When you have an active trading order, it doesn't show up in the balance section

That means the api does not return it, or we use only the "available" part of the balance in the API. Did you say you managed to run rotki by source? That seems like a bug on our side.

Can you then tweak this area of the code: https://github.com/rotki/rotki/blob/7000c024f592c29ebcaabfd7c2d4d244c127b49a/rotkehlchen/exchanges/okx.py#L276 and run it with your account? It seems to indeed only get the available balance.

According to their API: https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-balance there is a lot more types of balance to get and I can't be sure which to try. I would guess that since we get `availBal` we should also get `frozenBal` to have it all but not 100% as the docs don't help.

If you can do this change and run the code to see it would help a lot!
Okey I fixed pls check my pr

Resolving patch:
diff --git a/rotkehlchen/exchanges/okx.py b/rotkehlchen/exchanges/okx.py
--- a/rotkehlchen/exchanges/okx.py
+++ b/rotkehlchen/exchanges/okx.py
@@ -273,7 +273,7 @@ def query_balances(self, **kwargs: Any) -> ExchangeQueryBalances:
                 continue
 
             try:
-                amount = deserialize_asset_amount(currency_data['availBal'])
+                amount = deserialize_asset_amount(currency_data['availBal']) + deserialize_asset_amount(currency_data['frozenBal'])  # noqa: E501
             except DeserializationError as e:
                 self.msg_aggregator.add_error(
                     f'Error processing {self.name} {asset.name} balance result due to inability '


Test patch:
diff --git a/rotkehlchen/tests/exchanges/test_okx.py b/rotkehlchen/tests/exchanges/test_okx.py
--- a/rotkehlchen/tests/exchanges/test_okx.py
+++ b/rotkehlchen/tests/exchanges/test_okx.py
@@ -132,7 +132,7 @@ def mock_okx_balances(method, url):     # pylint: disable=unused-argument
                "eq":"0.00000065312",
                "eqUsd":"0.00000065312",
                "fixedBal":"0",
-               "frozenBal":"0",
+               "frozenBal":"50",
                "interest":"",
                "isoEq":"0",
                "isoLiab":"",
@@ -173,7 +173,7 @@ def mock_okx_balances(method, url):     # pylint: disable=unused-argument
     assert len(balances) == 3
     assert (balances[A_XMR.resolve_to_asset_with_oracles()]).amount == FVal('0.027846')
     assert (balances[A_SOL.resolve_to_asset_with_oracles()]).amount == FVal('299.9920000068')
-    assert (balances[A_USDT.resolve_to_asset_with_oracles()]).amount == FVal('6.5312E-7')
+    assert (balances[A_USDT.resolve_to_asset_with_oracles()]).amount == FVal('50.00000065312')
 
     warnings = mock_okx.msg_aggregator.consume_warnings()
     errors = mock_okx.msg_aggregator.consume_errors()