mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
replace LoadAccount with literal constructor
This commit is contained in:
parent
59af43affd
commit
4c20c9f4ff
|
@ -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()
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user