Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the wallet balance service #39

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,10 @@ func (c *Client) NewAutoConvertStableCoinService() *AutoConvertStableCoinService
return &AutoConvertStableCoinService{c: c}
}

func (c *Client) NewWalletBalanceService() *WalletBalanceService {
return &WalletBalanceService{c: c}
}

// User Data Streams:
func (c *Client) NewCreateListenKeyService() *CreateListenKey {
return &CreateListenKey{c: c}
Expand Down
28 changes: 28 additions & 0 deletions examples/wallet/WalletBalance/WalletBalance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import (
"context"
"fmt"

binance_connector "github.com/binance/binance-connector-go"
)

func main() {
WalletBalance()
}

func WalletBalance() {
apiKey := "your api key"
secretKey := "your secret key"
baseURL := "https://api.binance.com"

client := binance_connector.NewClient(apiKey, secretKey, baseURL)

// WalletBalanceService - /sapi/v1/asset/wallet/balance
walletBalance, err := client.NewWalletBalanceService().Do(context.Background())
if err != nil {
fmt.Println(err)
return
}
fmt.Println(binance_connector.PrettyPrint(walletBalance))
}
35 changes: 35 additions & 0 deletions wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1764,3 +1764,38 @@ type AutoConvertStableCoinResponse struct {
Asset string `json:"coin"`
} `json:"exchangeRates"`
}

// Wallet Balance (USER_DATA)
const (
walletBalanceEndpoint = "/sapi/v1/asset/wallet/balance"
)

// WalletBalanceService gets the user wallet balance in BTC.
type WalletBalanceService struct {
c *Client
}

func (s *WalletBalanceService) Do(ctx context.Context) (res []*WalletBalanceResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: walletBalanceEndpoint,
secType: secTypeSigned,
}
data, err := s.c.callAPI(ctx, r)
if err != nil {
return nil, err
}
res = make([]*WalletBalanceResponse, 0)
err = json.Unmarshal(data, &res)
if err != nil {
return nil, err
}
return res, nil
}

// WalletBalanceResponse defines the response of WalletBalanceService
type WalletBalanceResponse struct {
Activate bool `json:"activate"`
Balance string `json:"balance"`
WalletName string `json:"walletName"`
}