mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
add GetAccount api
This commit is contained in:
parent
76f122d998
commit
be7e9f551a
|
@ -26,7 +26,7 @@ var rootCmd = &cobra.Command{
|
|||
SilenceUsage: true,
|
||||
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
accounts, err := client.AccountService.QueryAccounts()
|
||||
accounts, err := client.AccountService.ListAccounts()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -12,7 +12,17 @@ var accountsCmd = &cobra.Command{
|
|||
SilenceUsage: true,
|
||||
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
accounts, err := client.AccountService.QueryAccounts()
|
||||
if len(args) > 0 {
|
||||
account, err := client.AccountService.GetAccount(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Infof("account: %+v", account)
|
||||
return nil
|
||||
}
|
||||
|
||||
accounts, err := client.AccountService.ListAccounts()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -21,3 +31,4 @@ var accountsCmd = &cobra.Command{
|
|||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ type Account struct {
|
|||
Holds fixedpoint.Value `json:"holds"`
|
||||
}
|
||||
|
||||
func (s *AccountService) QueryAccounts() ([]Account, error) {
|
||||
func (s *AccountService) ListAccounts() ([]Account, error) {
|
||||
req, err := s.client.newAuthenticatedRequest("GET", "/api/v1/accounts", nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -69,3 +69,27 @@ func (s *AccountService) QueryAccounts() ([]Account, error) {
|
|||
|
||||
return apiResponse.Data, nil
|
||||
}
|
||||
|
||||
func (s *AccountService) GetAccount(accountID string) (*Account, error) {
|
||||
req, err := s.client.newAuthenticatedRequest("GET", "/api/v1/accounts/" + accountID, nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response, err := s.client.sendRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var apiResponse struct {
|
||||
Code string `json:"code"`
|
||||
Message string `json:"msg"`
|
||||
Data *Account `json:"data"`
|
||||
}
|
||||
|
||||
if err := response.DecodeJSON(&apiResponse); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return apiResponse.Data, nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user