diff --git a/exchanges/huobi/huobi.go b/exchanges/huobi/huobi.go index 27a893a3..483f284f 100644 --- a/exchanges/huobi/huobi.go +++ b/exchanges/huobi/huobi.go @@ -42,6 +42,7 @@ const ( huobiTimestamp = "common/timestamp" huobiAccounts = "account/accounts" huobiAccountBalance = "account/accounts/%s/balance" + huobiAggregatedBalance = "subuser/aggregate-balance" huobiOrderPlace = "order/orders/place" huobiOrderCancel = "order/orders/%s/submitcancel" huobiOrderCancelBatch = "order/orders/batchcancel" @@ -399,6 +400,29 @@ func (h *HUOBI) GetAccountBalance(accountID string) ([]AccountBalanceDetail, err return result.AccountBalanceData.AccountBalanceDetails, err } +// GetAggregatedBalance returns the balances of all the sub-account aggregated. +func (h *HUOBI) GetAggregatedBalance() ([]AggregatedBalance, error) { + type response struct { + Response + AggregatedBalances []AggregatedBalance `json:"data"` + } + + var result response + + err := h.SendAuthenticatedHTTPRequest( + http.MethodGet, + huobiAggregatedBalance, + nil, + nil, + &result, + ) + + if result.ErrorMessage != "" { + return nil, errors.New(result.ErrorMessage) + } + return result.AggregatedBalances, err +} + // SpotNewOrder submits an order to Huobi func (h *HUOBI) SpotNewOrder(arg SpotNewOrderRequestParams) (int64, error) { data := struct { diff --git a/exchanges/huobi/huobi_test.go b/exchanges/huobi/huobi_test.go index 422fad7e..fea3413f 100644 --- a/exchanges/huobi/huobi_test.go +++ b/exchanges/huobi/huobi_test.go @@ -210,6 +210,19 @@ 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/huobi/huobi_types.go b/exchanges/huobi/huobi_types.go index 958a09ad..feb83195 100644 --- a/exchanges/huobi/huobi_types.go +++ b/exchanges/huobi/huobi_types.go @@ -131,6 +131,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"`