Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
add a new api for subAccounts balance info
Browse files Browse the repository at this point in the history
  • Loading branch information
fenzheng1991 committed Jul 19, 2023
1 parent aa4478f commit 808ab80
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
33 changes: 33 additions & 0 deletions account.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,36 @@ type DeleteSubApiKeyRes struct {
ApiKey string `json:"apiKey"`
SubName string `json:"subName"`
}

// SubAccountsBalance Get All Sub-Accounts Balance - Futures
func (as *ApiService) SubAccountsBalance(currency string) (*ApiResponse, error) {
p := map[string]string{
"currency": currency,
}
req := NewRequest(http.MethodGet, "/api/v1/account-overview-all", p)
return as.Call(req)
}

type SubAccountBalanceModel struct {
Summary struct {
AccountEquityTotal json.Number `json:"accountEquityTotal"`
UnrealisedPNLTotal json.Number `json:"unrealisedPNLTotal"`
MarginBalanceTotal json.Number `json:"marginBalanceTotal"`
PositionMarginTotal json.Number `json:"positionMarginTotal"`
OrderMarginTotal json.Number `json:"orderMarginTotal"`
FrozenFundsTotal json.Number `json:"frozenFundsTotal"`
AvailableBalanceTotal json.Number `json:"availableBalanceTotal"`
Currency string `json:"currency"`
} `json:"summary"`
Accounts []struct {
AccountName string `json:"accountName"`
AccountEquity json.Number `json:"accountEquity"`
UnrealisedPNL json.Number `json:"unrealisedPNL"`
MarginBalance json.Number `json:"marginBalance"`
PositionMargin json.Number `json:"positionMargin"`
OrderMargin json.Number `json:"orderMargin"`
FrozenFunds json.Number `json:"frozenFunds"`
AvailableBalance json.Number `json:"availableBalance"`
Currency string `json:"currency"`
} `json:"accounts"`
}
17 changes: 17 additions & 0 deletions account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,20 @@ func TestApiService_DeleteSubApiKey(t *testing.T) {
}
t.Log(ToJsonString(w))
}

func TestApiService_SubAccountsBalance(t *testing.T) {
s := NewApiServiceFromEnv()
rsp, err := s.SubAccountsBalance("USDT")
if err != nil {
t.Fatal(err)
}
w := SubAccountBalanceModel{}
if err := rsp.ReadData(&w); err != nil {
t.Fatal(err)
}

t.Log(ToJsonString(w.Summary))
for _, account := range w.Accounts {
t.Log(ToJsonString(account))
}
}

0 comments on commit 808ab80

Please sign in to comment.