From eb07c7e4952cbe35a5bc9880d4e3e79d2ef198e5 Mon Sep 17 00:00:00 2001 From: Scott Date: Fri, 19 Jul 2019 17:00:54 +1000 Subject: [PATCH] Implements endpoint GetAggregatedBalance for Hadax too. (#330) --- exchanges/huobihadax/huobihadax.go | 23 +++++++++++++++++++++++ exchanges/huobihadax/huobihadax_test.go | 12 ++++++++++++ exchanges/huobihadax/huobihadax_types.go | 6 ++++++ 3 files changed, 41 insertions(+) diff --git a/exchanges/huobihadax/huobihadax.go b/exchanges/huobihadax/huobihadax.go index 1160edde..35d8d0a8 100644 --- a/exchanges/huobihadax/huobihadax.go +++ b/exchanges/huobihadax/huobihadax.go @@ -36,6 +36,7 @@ const ( huobihadaxCurrencies = "common/currencys" huobihadaxTimestamp = "common/timestamp" huobihadaxAccounts = "account/accounts" + huobihadaxAggregatedBalance = "subuser/aggregate-balance" huobihadaxAccountBalance = "account/accounts/%s/balance" huobihadaxOrderPlace = "order/orders/place" huobihadaxOrderCancel = "order/orders/%s/submitcancel" @@ -389,6 +390,28 @@ func (h *HUOBIHADAX) GetAccountBalance(accountID string) ([]AccountBalanceDetail return result.AccountBalanceData.AccountBalanceDetails, err } +// GetAggregatedBalance returns the balances of all the sub-account aggregated. +func (h *HUOBIHADAX) GetAggregatedBalance() ([]AggregatedBalance, error) { + type response struct { + Response + AggregatedBalances []AggregatedBalance `json:"data"` + } + + var result response + + err := h.SendAuthenticatedHTTPRequest( + http.MethodGet, + huobihadaxAggregatedBalance, + url.Values{}, + &result, + ) + + if result.ErrorMessage != "" { + return nil, errors.New(result.ErrorMessage) + } + return result.AggregatedBalances, err +} + // SpotNewOrder submits an order to Huobi func (h *HUOBIHADAX) SpotNewOrder(arg SpotNewOrderRequestParams) (int64, error) { vals := make(map[string]string) diff --git a/exchanges/huobihadax/huobihadax_test.go b/exchanges/huobihadax/huobihadax_test.go index 0647d55c..c6d16bb8 100644 --- a/exchanges/huobihadax/huobihadax_test.go +++ b/exchanges/huobihadax/huobihadax_test.go @@ -202,6 +202,18 @@ func TestGetAccountBalance(t *testing.T) { } } +func TestGetAggregatedBalance(t *testing.T) { + t.Parallel() + if h.APIKey == "" || h.APISecret == "" || h.APIAuthPEMKey == "" { + t.Skip() + } + + _, err := h.GetAggregatedBalance() + if err != nil { + t.Errorf("Test failed - Huobi GetAggregatedBalance: %s", err) + } +} + func TestSpotNewOrder(t *testing.T) { t.Parallel() diff --git a/exchanges/huobihadax/huobihadax_types.go b/exchanges/huobihadax/huobihadax_types.go index 20ee992b..787c9b14 100644 --- a/exchanges/huobihadax/huobihadax_types.go +++ b/exchanges/huobihadax/huobihadax_types.go @@ -113,6 +113,12 @@ type AccountBalanceDetail struct { Balance float64 `json:"balance,string"` } +// AggregatedBalance stores balances of all the sub-account +type AggregatedBalance struct { + Currency string `json:"currency"` + Balance float64 `json:"balance,string"` +} + // CancelOrderBatch stores the cancel order batch data type CancelOrderBatch struct { Success []string `json:"success"`