Implements endpoint GetAggregatedBalance for Hadax too. (#330)

This commit is contained in:
Scott
2019-07-19 17:00:54 +10:00
committed by Adrian Gallagher
parent e0aea96a5c
commit eb07c7e495
3 changed files with 41 additions and 0 deletions

View File

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

View File

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

View File

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