mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
bbgo: should get isolation from the ctx when saving state
This commit is contained in:
parent
4ac5a2a9e9
commit
2378951c85
|
@ -88,6 +88,8 @@ type Trader struct {
|
|||
crossExchangeStrategies []CrossExchangeStrategy
|
||||
exchangeStrategies map[string][]SingleExchangeStrategy
|
||||
|
||||
// gracefulShutdown is used for registering strategy's Shutdown calls
|
||||
// when strategy implements Shutdown(ctx), the func ref will be stored in the callback.
|
||||
gracefulShutdown GracefulShutdown
|
||||
|
||||
logger Logger
|
||||
|
@ -400,18 +402,16 @@ func (trader *Trader) IterateStrategies(f func(st StrategyID) error) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (trader *Trader) SaveState() error {
|
||||
func (trader *Trader) SaveState(ctx context.Context) error {
|
||||
if trader.environment.BacktestService != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if persistenceServiceFacade == nil {
|
||||
return nil
|
||||
}
|
||||
isolation := GetIsolationFromContext(ctx)
|
||||
|
||||
ps := persistenceServiceFacade.Get()
|
||||
ps := isolation.persistenceServiceFacade.Get()
|
||||
|
||||
log.Infof("saving strategies states...")
|
||||
log.Debugf("saving strategy persistence states...")
|
||||
return trader.IterateStrategies(func(strategy StrategyID) error {
|
||||
id := dynamic.CallID(strategy)
|
||||
if len(id) == 0 {
|
||||
|
|
|
@ -206,7 +206,7 @@ func runConfig(basectx context.Context, cmd *cobra.Command, userConfig *bbgo.Con
|
|||
bbgo.Shutdown(shtCtx)
|
||||
cancelShutdown()
|
||||
|
||||
if err := trader.SaveState(); err != nil {
|
||||
if err := trader.SaveState(nil); err != nil {
|
||||
log.WithError(err).Errorf("can not save strategy states")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user