mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
Merge pull request #938 from c9s/feature/lightweight-mode
bbgo: add lightweight mode
This commit is contained in:
commit
99a6daaa57
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user