From 5208d2191e2d4bc0bd5e56608dd8a47f5c2020a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Rasc=C3=A3o?= Date: Thu, 7 Oct 2021 04:43:06 +0100 Subject: [PATCH] Huobi: symbol, var assignment and UpdateAccountInfo fixes (#793) * huobi futures: GetSwapAccountInfo argument is optional * huobi futures: fetch main account data as well * huobi futures: shut linter up Old warnings not introduced in this scope. --- exchanges/huobi/huobi_cfutures.go | 10 +++++--- exchanges/huobi/huobi_futures.go | 4 +-- exchanges/huobi/huobi_wrapper.go | 42 +++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/exchanges/huobi/huobi_cfutures.go b/exchanges/huobi/huobi_cfutures.go index 73f2fbba..6731e4b2 100644 --- a/exchanges/huobi/huobi_cfutures.go +++ b/exchanges/huobi/huobi_cfutures.go @@ -427,11 +427,13 @@ func (h *HUOBI) GetBasisData(ctx context.Context, code currency.Pair, period, ba func (h *HUOBI) GetSwapAccountInfo(ctx context.Context, code currency.Pair) (SwapAccountInformation, error) { var resp SwapAccountInformation req := make(map[string]interface{}) - codeValue, err := h.FormatSymbol(code, asset.CoinMarginedFutures) - if err != nil { - return resp, err + if !code.IsEmpty() { + codeValue, err := h.FormatSymbol(code, asset.CoinMarginedFutures) + if err != nil { + return resp, err + } + req["contract_code"] = codeValue } - req["contract_code"] = codeValue return resp, h.FuturesAuthenticatedHTTPRequest(ctx, exchange.RestFutures, http.MethodPost, huobiSwapAccInfo, nil, req, &resp) } diff --git a/exchanges/huobi/huobi_futures.go b/exchanges/huobi/huobi_futures.go index 564a54af..b8bb28cf 100644 --- a/exchanges/huobi/huobi_futures.go +++ b/exchanges/huobi/huobi_futures.go @@ -903,9 +903,9 @@ func (h *HUOBI) FGetOrderHistory(ctx context.Context, contractCode currency.Pair return resp, fmt.Errorf("invalid reqType") } req["type"] = rType - var reqStatus string = "0" + reqStatus := "0" if len(status) > 0 { - var firstTime bool = true + firstTime := true for x := range status { sType, ok := validOrderStatus[status[x]] if !ok { diff --git a/exchanges/huobi/huobi_wrapper.go b/exchanges/huobi/huobi_wrapper.go index 72c1ac65..d193adab 100644 --- a/exchanges/huobi/huobi_wrapper.go +++ b/exchanges/huobi/huobi_wrapper.go @@ -705,6 +705,27 @@ func (h *HUOBI) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (ac } case asset.CoinMarginedFutures: + // fetch swap account info + acctInfo, err := h.GetSwapAccountInfo(ctx, currency.Pair{}) + if err != nil { + return info, err + } + + var mainAcctBalances []account.Balance + for x := range acctInfo.Data { + mainAcctBalances = append(mainAcctBalances, account.Balance{ + CurrencyName: currency.NewCode(acctInfo.Data[x].Symbol), + TotalValue: acctInfo.Data[x].MarginBalance, + Hold: acctInfo.Data[x].MarginFrozen, + }) + } + + info.Accounts = append(info.Accounts, account.SubAccount{ + Currencies: mainAcctBalances, + AssetType: assetType, + }) + + // fetch subaccounts data subAccsData, err := h.GetSwapAllSubAccAssets(ctx, currency.Pair{}) if err != nil { return info, err @@ -727,6 +748,27 @@ func (h *HUOBI) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (ac } acc.Currencies = currencyDetails case asset.Futures: + // fetch main account data + mainAcctData, err := h.FGetAccountInfo(ctx, currency.Code{}) + if err != nil { + return info, err + } + + var mainAcctBalances []account.Balance + for x := range mainAcctData.AccData { + mainAcctBalances = append(mainAcctBalances, account.Balance{ + CurrencyName: currency.NewCode(mainAcctData.AccData[x].Symbol), + TotalValue: mainAcctData.AccData[x].MarginBalance, + Hold: mainAcctData.AccData[x].MarginFrozen, + }) + } + + info.Accounts = append(info.Accounts, account.SubAccount{ + Currencies: mainAcctBalances, + AssetType: assetType, + }) + + // fetch subaccounts data subAccsData, err := h.FGetAllSubAccountAssets(ctx, currency.Code{}) if err != nil { return info, err