JKorf / HTX.Net

A C# .netstandard client library for the Huobi REST and Websocket Spot and Swap API focusing on clear usage and models
https://jkorf.github.io/HTX.Net/
MIT License
73 stars 52 forks source link

Error in GetBalancesAsync(accountId) #112

Closed heavymanto closed 4 months ago

heavymanto commented 4 months ago

Describe the bug There is a strange bug on call method in title, seem a cast error of accountid from string to long. I think there is a mask format that introduce coma separator. Note that, the lenght char of source not match with number in error message

To Reproduce HTX_Account_KO

Thank you for your great work ;)

heavymanto commented 4 months ago

doing various tests I realized that what HTX indicates as accountId is actually not. In fact, if I ask for the list of active accounts, I receive a different ID code. With this the balance works and returns the correct data. To overcome this problem I made myself a small wrap, which first retrieves the account ID, then uses it for the abalnce, by doing so I don't need to indicate it explicitly.

 public XtraCrypto_BalanceData GetBalance(XtraCrypto_SymbolPair symbol, string? accountId = null)
  {
      try
      {
          string singleAccount = accountId ?? _exchange.Key_Pass;

          //recupero accountid dalle key, se solo 1 lo assegno come default
          if (singleAccount.isNullOrEmpty())
          {
              var account = _client.SpotApi.Account.GetAccountsAsync();
              account.Wait();

              if (account.Result.Success)
              {
                  singleAccount = account.Result.Data.SingleOrDefault()?.Id.ToString();
              }
              else
              {
                  string msg = $"GetAccounts --> {account.Result.ResponseStatusCode},{account.Result.Error.Message}";
                  throw new Exception(msg);
              }
          }

          var balance = _clientCommon.GetBalance(symbol, singleAccount);
          return balance;
      }
      catch (Exception ex)
      {
          throw new Exception($@"ApiClient_{Name}.{ex.Message}");
      }
  }