diff --git a/cmd/bbgo-lorca/main.go b/cmd/bbgo-lorca/main.go index b44a225d8..3718ee572 100644 --- a/cmd/bbgo-lorca/main.go +++ b/cmd/bbgo-lorca/main.go @@ -101,7 +101,7 @@ func main() { return } - if err := trader.LoadState(); err != nil { + if err := trader.LoadState(ctx); err != nil { log.WithError(err).Error("failed to load strategy states") return } diff --git a/cmd/bbgo-webview/main.go b/cmd/bbgo-webview/main.go index 340237090..7cc5060e2 100644 --- a/cmd/bbgo-webview/main.go +++ b/cmd/bbgo-webview/main.go @@ -109,7 +109,7 @@ func main() { return } - if err := trader.LoadState(); err != nil { + if err := trader.LoadState(ctx); err != nil { log.WithError(err).Error("failed to load strategy states") return } diff --git a/pkg/bbgo/trader.go b/pkg/bbgo/trader.go index 53fc2086f..fee49d90f 100644 --- a/pkg/bbgo/trader.go +++ b/pkg/bbgo/trader.go @@ -365,16 +365,14 @@ func (trader *Trader) Run(ctx context.Context) error { return trader.environment.Connect(ctx) } -func (trader *Trader) LoadState() error { +func (trader *Trader) LoadState(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("loading strategies states...") diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go index 975ede42a..bc601e0dc 100644 --- a/pkg/cmd/run.go +++ b/pkg/cmd/run.go @@ -163,7 +163,7 @@ func runConfig(basectx context.Context, cmd *cobra.Command, userConfig *bbgo.Con return err } - if err := trader.LoadState(); err != nil { + if err := trader.LoadState(tradingCtx); err != nil { return err }