mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
bbgo: add lightweight mode
This commit is contained in:
parent
da5b1691b3
commit
424a1dec3f
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user