mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
bbgo: add setAccount for account mutex protection
This commit is contained in:
parent
3ea333fd52
commit
7c59e3ddc4
|
@ -177,12 +177,16 @@ func (session *ExchangeSession) UpdateAccount(ctx context.Context) (*types.Accou
|
|||
return nil, err
|
||||
}
|
||||
|
||||
session.accountMutex.Lock()
|
||||
session.Account = account
|
||||
session.accountMutex.Unlock()
|
||||
session.setAccount(account)
|
||||
return account, nil
|
||||
}
|
||||
|
||||
func (session *ExchangeSession) setAccount(a *types.Account) {
|
||||
session.accountMutex.Lock()
|
||||
session.Account = a
|
||||
session.accountMutex.Unlock()
|
||||
}
|
||||
|
||||
// Init initializes the basic data structure and market information by its exchange.
|
||||
// Note that the subscribed symbols are not loaded in this stage.
|
||||
func (session *ExchangeSession) Init(ctx context.Context, environ *Environment) error {
|
||||
|
@ -268,13 +272,10 @@ func (session *ExchangeSession) Init(ctx context.Context, environ *Environment)
|
|||
return err
|
||||
}
|
||||
|
||||
session.accountMutex.Lock()
|
||||
session.Account = account
|
||||
session.accountMutex.Unlock()
|
||||
session.setAccount(account)
|
||||
logger.Infof("account %s balances:\n%s", session.Name, account.Balances().String())
|
||||
}
|
||||
|
||||
logger.Infof("account %s balances:\n%s", session.Name, account.Balances().String())
|
||||
|
||||
// forward trade updates and order updates to the order executor
|
||||
session.UserDataStream.OnTradeUpdate(session.OrderExecutor.EmitTradeUpdate)
|
||||
session.UserDataStream.OnOrderUpdate(session.OrderExecutor.EmitOrderUpdate)
|
||||
|
|
Loading…
Reference in New Issue
Block a user