mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
implement account balance query
This commit is contained in:
parent
791a745951
commit
a4a5231d78
|
@ -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
15
bbgo/types/account.go
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user