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 package bbgo
import ( import (
"context"
"sync" "sync"
"github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/types"
@ -12,18 +11,9 @@ import (
type Account struct { type Account struct {
sync.Mutex sync.Mutex
Balances map[string]types.Balance 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) { func (a *Account) handleBalanceUpdates(balances map[string]types.Balance) {
a.Lock() a.Lock()
defer a.Unlock() defer a.Unlock()

View File

@ -133,11 +133,13 @@ func (environ *Environment) Init(ctx context.Context) (err error) {
session.LastPrices[symbol] = currentPrice session.LastPrices[symbol] = currentPrice
} }
session.Account, err = LoadAccount(ctx, session.Exchange) balances, err := session.Exchange.QueryAccountBalances(ctx)
if err != nil { if err != nil {
return err return err
} }
session.Account = &Account{ Balances: balances }
session.Stream = session.Exchange.NewStream() session.Stream = session.Exchange.NewStream()
session.Account.BindStream(session.Stream) session.Account.BindStream(session.Stream)