Skip to content

Commit

Permalink
Merge pull request adshao#603 from mdawar/balances
Browse files Browse the repository at this point in the history
Added support for getting the non-zero balances of an account
  • Loading branch information
xyq-c-cpp authored Aug 7, 2024
2 parents 639815a + e0bbc76 commit d45dcb3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
14 changes: 13 additions & 1 deletion v2/account_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ import (

// GetAccountService get account info
type GetAccountService struct {
c *Client
c *Client
omitZeroBalances *bool
}

// OmitZeroBalances sets the omitZeroBalances parameter on the request.
// When set to true, the API will return the non-zero balances of an account.
func (s *GetAccountService) OmitZeroBalances(v bool) *GetAccountService {
s.omitZeroBalances = &v
return s
}

// Do send request
Expand All @@ -17,6 +25,10 @@ func (s *GetAccountService) Do(ctx context.Context, opts ...RequestOption) (res
endpoint: "/api/v3/account",
secType: secTypeSigned,
}
if s.omitZeroBalances != nil {
r.setParam("omitZeroBalances", *s.omitZeroBalances)
}

data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
Expand Down
9 changes: 7 additions & 2 deletions v2/account_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,17 @@ func (s *accountServiceTestSuite) TestGetAccount() {
}`)
s.mockDo(data, nil)
defer s.assertDo()

omitZeroBalances := true

s.assertReq(func(r *request) {
e := newSignedRequest()
e := newSignedRequest().setParams(params{
"omitZeroBalances": omitZeroBalances,
})
s.assertRequestEqual(e, r)
})

res, err := s.client.NewGetAccountService().Do(newContext())
res, err := s.client.NewGetAccountService().OmitZeroBalances(omitZeroBalances).Do(newContext())
s.r().NoError(err)
e := &Account{
MakerCommission: 15,
Expand Down

0 comments on commit d45dcb3

Please sign in to comment.