implement account balance query

This commit is contained in:
c9s 2020-07-13 12:28:40 +08:00
parent 791a745951
commit a4a5231d78
2 changed files with 46 additions and 0 deletions

View File

@ -39,6 +39,37 @@ func (e *Exchange) NewPrivateStream() (*PrivateStream, error) {
}, nil
}
func (e *Exchange) QueryAccountBalances(ctx context.Context) (map[string]types.Balance, error) {
account, err := e.QueryAccount(ctx)
if err != nil {
return nil, err
}
return account.Balances, nil
}
func (e *Exchange) QueryAccount(ctx context.Context) (*types.Account, error) {
account, err := e.Client.NewGetAccountService().Do(ctx)
if err != nil {
return nil, err
}
var balances = map[string]types.Balance{}
for _, b := range account.Balances {
balances[b.Asset] = types.Balance{
Currency: b.Asset,
Available: util.MustParseFloat(b.Free),
Locked: util.MustParseFloat(b.Locked),
}
}
return &types.Account{
MakerCommission: account.MakerCommission,
TakerCommission: account.TakerCommission,
Balances: balances,
}, nil
}
func (e *Exchange) SubmitOrder(ctx context.Context, order *types.Order) error {
/*
limit order example

15
bbgo/types/account.go Normal file
View File

@ -0,0 +1,15 @@
package types
type Balance struct {
Currency string
Available float64
Locked float64
}
type Account struct {
MakerCommission int64
TakerCommission int64
AccountType string
Balances map[string]Balance
}