From 424a1dec3f1ec694ea62fcb4ab6ba5d959b88293 Mon Sep 17 00:00:00 2001 From: c9s Date: Mon, 12 Sep 2022 14:24:18 +0800 Subject: [PATCH] bbgo: add lightweight mode --- pkg/bbgo/bootstrap.go | 18 +++++++++++++++++- pkg/cmd/run.go | 15 ++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/pkg/bbgo/bootstrap.go b/pkg/bbgo/bootstrap.go index 879a4df3b..73188c7d2 100644 --- a/pkg/bbgo/bootstrap.go +++ b/pkg/bbgo/bootstrap.go @@ -6,6 +6,23 @@ import ( "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 { if err := environ.ConfigureDatabase(ctx); err != nil { return err @@ -31,4 +48,3 @@ func BootstrapEnvironment(ctx context.Context, environ *Environment, userConfig func BootstrapBacktestEnvironment(ctx context.Context, environ *Environment) error { return environ.ConfigureDatabase(ctx) } - diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go index d4368afa7..ef622671b 100644 --- a/pkg/cmd/run.go +++ b/pkg/cmd/run.go @@ -28,6 +28,7 @@ func init() { 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().String("webserver-bind", ":8080", "webserver binding") + RunCmd.Flags().Bool("lightweight", false, "lightweight mode") RunCmd.Flags().Bool("enable-grpc", false, "enable grpc server") 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() environ := bbgo.NewEnvironment() - if err := bbgo.BootstrapEnvironment(ctx, environ, userConfig); err != nil { + + lightweight, err := cmd.Flags().GetBool("lightweight") + if err != nil { 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 { return err }