bbgo: add lightweight mode

This commit is contained in:
c9s 2022-09-12 14:24:18 +08:00
parent da5b1691b3
commit 424a1dec3f
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 31 additions and 2 deletions

View File

@ -6,6 +6,23 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
) )
// 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 := environ.ConfigurePersistence(userConfig.Persistence); err != nil {
return errors.Wrap(err, "persistence configure error")
}
}
return nil
}
func BootstrapEnvironment(ctx context.Context, environ *Environment, userConfig *Config) error { func BootstrapEnvironment(ctx context.Context, environ *Environment, userConfig *Config) error {
if err := environ.ConfigureDatabase(ctx); err != nil { if err := environ.ConfigureDatabase(ctx); err != nil {
return err return err
@ -31,4 +48,3 @@ func BootstrapEnvironment(ctx context.Context, environ *Environment, userConfig
func BootstrapBacktestEnvironment(ctx context.Context, environ *Environment) error { func BootstrapBacktestEnvironment(ctx context.Context, environ *Environment) error {
return environ.ConfigureDatabase(ctx) return environ.ConfigureDatabase(ctx)
} }

View File

@ -28,6 +28,7 @@ func init() {
RunCmd.Flags().Bool("enable-webserver", false, "enable webserver") RunCmd.Flags().Bool("enable-webserver", false, "enable webserver")
RunCmd.Flags().Bool("enable-web-server", false, "legacy option, this is renamed to --enable-webserver") RunCmd.Flags().Bool("enable-web-server", false, "legacy option, this is renamed to --enable-webserver")
RunCmd.Flags().String("webserver-bind", ":8080", "webserver binding") RunCmd.Flags().String("webserver-bind", ":8080", "webserver binding")
RunCmd.Flags().Bool("lightweight", false, "lightweight mode")
RunCmd.Flags().Bool("enable-grpc", false, "enable grpc server") RunCmd.Flags().Bool("enable-grpc", false, "enable grpc server")
RunCmd.Flags().String("grpc-bind", ":50051", "grpc server binding") RunCmd.Flags().String("grpc-bind", ":50051", "grpc server binding")
@ -122,10 +123,22 @@ func runConfig(basectx context.Context, cmd *cobra.Command, userConfig *bbgo.Con
defer cancelTrading() defer cancelTrading()
environ := bbgo.NewEnvironment() environ := bbgo.NewEnvironment()
if err := bbgo.BootstrapEnvironment(ctx, environ, userConfig); err != nil {
lightweight, err := cmd.Flags().GetBool("lightweight")
if err != nil {
return err return err
} }
if lightweight {
if err := bbgo.BootstrapEnvironmentLightweight(ctx, environ, userConfig); err != nil {
return err
}
} else {
if err := bbgo.BootstrapEnvironment(ctx, environ, userConfig); err != nil {
return err
}
}
if err := environ.Init(ctx); err != nil { if err := environ.Init(ctx); err != nil {
return err return err
} }