Add Huobi GetAggregatedBalance api (#329)

Add Huobi GetAggregatedBalance api that returns the balances of all the
sub-account aggregated.

See also
  - https://huobiapi.github.io/docs/spot/v1/en/#get-the-aggregated-balance-of-all-sub-accounts-of-the-current-user
This commit is contained in:
Yunseok
2019-07-18 12:10:30 +09:00
committed by Adrian Gallagher
parent 4222b327c6
commit e0aea96a5c
3 changed files with 43 additions and 0 deletions

View File

@@ -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 {

View File

@@ -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()

View File

@@ -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"`