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")
|
|
|
|
}
|
|
|
|
|
2023-02-22 07:25:39 +00:00
|
|
|
if userConfig.Logging != nil {
|
|
|
|
environ.SetLogging(userConfig.Logging)
|
|
|
|
}
|
|
|
|
|
2022-09-12 06:24:18 +00:00
|
|
|
if userConfig.Persistence != nil {
|
2023-03-02 14:33:33 +00:00
|
|
|
if err := ConfigurePersistence(ctx, environ, userConfig.Persistence); err != nil {
|
2022-09-12 06:24:18 +00:00
|
|
|
return errors.Wrap(err, "persistence configure error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-09 05:17:39 +00:00
|
|
|
if userConfig.Service != nil {
|
|
|
|
if err := environ.ConfigureService(ctx, userConfig.Service); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-12 06:24:18 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-09-06 08:50:45 +00:00
|
|
|
func BootstrapEnvironment(ctx context.Context, environ *Environment, userConfig *Config) error {
|
2024-01-24 07:18:31 +00:00
|
|
|
if err := environ.ConfigureDatabase(ctx, userConfig); err != nil {
|
2022-09-06 08:50:45 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := environ.ConfigureExchangeSessions(userConfig); err != nil {
|
|
|
|
return errors.Wrap(err, "exchange session configure error")
|
|
|
|
}
|
|
|
|
|
2023-02-22 07:25:39 +00:00
|
|
|
if userConfig.Logging != nil {
|
|
|
|
environ.SetLogging(userConfig.Logging)
|
|
|
|
}
|
|
|
|
|
2022-09-06 08:50:45 +00:00
|
|
|
if userConfig.Persistence != nil {
|
2023-03-02 14:33:33 +00:00
|
|
|
if err := ConfigurePersistence(ctx, environ, userConfig.Persistence); err != nil {
|
2022-09-06 08:50:45 +00:00
|
|
|
return errors.Wrap(err, "persistence configure error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-09 05:17:39 +00:00
|
|
|
if userConfig.Service != nil {
|
|
|
|
if err := environ.ConfigureService(ctx, userConfig.Service); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-25 16:37:13 +00:00
|
|
|
if err := environ.ConfigureNotificationSystem(ctx, userConfig); err != nil {
|
2022-09-06 08:50:45 +00:00
|
|
|
return errors.Wrap(err, "notification configure error")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func BootstrapBacktestEnvironment(ctx context.Context, environ *Environment) error {
|
2024-01-24 07:18:31 +00:00
|
|
|
return environ.ConfigureDatabase(ctx, nil)
|
2023-04-25 16:37:13 +00:00
|
|
|
}
|