replace LoadAccount with literal constructor

This commit is contained in:
c9s 2020-10-12 22:49:27 +08:00
parent 59af43affd
commit 4c20c9f4ff
2 changed files with 3 additions and 11 deletions

View File

@ -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()

View File

@ -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)