mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
replace LoadAccount with literal constructor
This commit is contained in:
parent
59af43affd
commit
4c20c9f4ff
|
@ -1,7 +1,6 @@
|
|||
package bbgo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
|
@ -12,18 +11,9 @@ import (
|
|||
|
||||
type Account struct {
|
||||
sync.Mutex
|
||||
|
||||
Balances map[string]types.Balance
|
||||
}
|
||||
|
||||
// TODO: rewrite this as NewAccount(map balances)
|
||||
func LoadAccount(ctx context.Context, exchange types.Exchange) (*Account, error) {
|
||||
balances, err := exchange.QueryAccountBalances(ctx)
|
||||
return &Account{
|
||||
Balances: balances,
|
||||
}, err
|
||||
}
|
||||
|
||||
func (a *Account) handleBalanceUpdates(balances map[string]types.Balance) {
|
||||
a.Lock()
|
||||
defer a.Unlock()
|
||||
|
|
|
@ -133,11 +133,13 @@ func (environ *Environment) Init(ctx context.Context) (err error) {
|
|||
session.LastPrices[symbol] = currentPrice
|
||||
}
|
||||
|
||||
session.Account, err = LoadAccount(ctx, session.Exchange)
|
||||
balances, err := session.Exchange.QueryAccountBalances(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
session.Account = &Account{ Balances: balances }
|
||||
|
||||
session.Stream = session.Exchange.NewStream()
|
||||
|
||||
session.Account.BindStream(session.Stream)
|
||||
|
|
Loading…
Reference in New Issue
Block a user