bbgo: should get isolation from the ctx when saving state

This commit is contained in:
c9s 2023-03-15 22:47:40 +08:00
parent 4ac5a2a9e9
commit 2378951c85
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 7 additions and 7 deletions

View File

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

View File

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