diff --git a/client.go b/client.go index d78994e..403b692 100644 --- a/client.go +++ b/client.go @@ -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} diff --git a/examples/wallet/WalletBalance/WalletBalance.go b/examples/wallet/WalletBalance/WalletBalance.go new file mode 100644 index 0000000..a71cb89 --- /dev/null +++ b/examples/wallet/WalletBalance/WalletBalance.go @@ -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)) +} diff --git a/wallet.go b/wallet.go index 9be1139..e1a55c0 100644 --- a/wallet.go +++ b/wallet.go @@ -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"` +}