Merge pull request #938 from c9s/feature/lightweight-mode

bbgo: add lightweight mode
This commit is contained in:
Yo-An Lin 2022-09-12 14:55:45 +08:00 committed by GitHub
commit 99a6daaa57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 2 deletions

View File

@ -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)
}

View File

@ -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
}