bbgo_origin/pkg/bbgo/bootstrap.go

51 lines
1.4 KiB
Go
Raw Permalink Normal View History

2022-09-06 08:50:45 +00:00
package bbgo
import (
"context"
"github.com/pkg/errors"
)
2022-09-12 06:24:18 +00:00
// BootstrapEnvironmentLightweight bootstrap the environment in lightweight mode
// - no database configuration
// - no notification
func BootstrapEnvironmentLightweight(ctx context.Context, environ *Environment, userConfig *Config) error {
if err := environ.ConfigureExchangeSessions(userConfig); err != nil {
return errors.Wrap(err, "exchange session configure error")
}
if userConfig.Persistence != nil {
if err := ConfigurePersistence(ctx, userConfig.Persistence); err != nil {
2022-09-12 06:24:18 +00:00
return errors.Wrap(err, "persistence configure error")
}
}
return nil
}
2022-09-06 08:50:45 +00:00
func BootstrapEnvironment(ctx context.Context, environ *Environment, userConfig *Config) error {
if err := environ.ConfigureDatabase(ctx); err != nil {
return err
}
if err := environ.ConfigureExchangeSessions(userConfig); err != nil {
return errors.Wrap(err, "exchange session configure error")
}
if userConfig.Persistence != nil {
if err := ConfigurePersistence(ctx, userConfig.Persistence); err != nil {
2022-09-06 08:50:45 +00:00
return errors.Wrap(err, "persistence configure error")
}
}
if err := environ.ConfigureNotificationSystem(userConfig); err != nil {
return errors.Wrap(err, "notification configure error")
}
return nil
}
func BootstrapBacktestEnvironment(ctx context.Context, environ *Environment) error {
return environ.ConfigureDatabase(ctx)
}