diff --git a/pkg/bbgo/persistence.go b/pkg/bbgo/persistence.go index fffcfadbb..5915783e5 100644 --- a/pkg/bbgo/persistence.go +++ b/pkg/bbgo/persistence.go @@ -136,6 +136,10 @@ func loadPersistenceFields(obj interface{}, id string, persistence service.Persi // inf := value.Interface() store := persistence.NewStore(id, tag) if err := store.Load(&newValueInf); err != nil { + if err == service.ErrPersistenceNotExists { + return nil + } + return err } diff --git a/pkg/bbgo/trader.go b/pkg/bbgo/trader.go index 146cd3e68..f5bcdb2c4 100644 --- a/pkg/bbgo/trader.go +++ b/pkg/bbgo/trader.go @@ -252,7 +252,10 @@ func (trader *Trader) RunSingleExchangeStrategy(ctx context.Context, strategy Si // 1) scan the struct fields and find the persistence field // 2) load the data and set the value into the persistence field. - _ = trader.environment.PersistenceServiceFacade + ps := trader.environment.PersistenceServiceFacade.Get() + if err := loadPersistenceFields(strategy, strategy.ID(), ps); err != nil { + return err + } return strategy.Run(ctx, orderExecutor, session) } @@ -319,6 +322,7 @@ func (trader *Trader) Run(ctx context.Context) error { router.executors[sessionID] = orderExecutor } + ps := trader.environment.PersistenceServiceFacade.Get() for _, strategy := range trader.crossExchangeStrategies { rs := reflect.ValueOf(strategy) @@ -332,6 +336,10 @@ func (trader *Trader) Run(ctx context.Context) error { return err } + if err := loadPersistenceFields(strategy, strategy.ID(), ps); err != nil { + return err + } + if err := strategy.CrossRun(ctx, router, trader.environment.sessions); err != nil { return err }