mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
move bootstrap functions
This commit is contained in:
parent
3f27facd83
commit
8f363677bc
|
@ -15,7 +15,6 @@ import (
|
|||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/bbgo"
|
||||
"github.com/c9s/bbgo/pkg/cmd"
|
||||
"github.com/c9s/bbgo/pkg/server"
|
||||
)
|
||||
|
||||
|
@ -92,7 +91,7 @@ func main() {
|
|||
|
||||
// we could initialize the environment from the settings
|
||||
if setup == nil {
|
||||
if err := cmd.BootstrapEnvironment(ctx, environ, userConfig); err != nil {
|
||||
if err := bbgo.BootstrapEnvironment(ctx, environ, userConfig); err != nil {
|
||||
log.WithError(err).Error("failed to bootstrap environment")
|
||||
return
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ import (
|
|||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/bbgo"
|
||||
"github.com/c9s/bbgo/pkg/cmd"
|
||||
"github.com/c9s/bbgo/pkg/server"
|
||||
)
|
||||
|
||||
|
@ -93,7 +92,7 @@ func main() {
|
|||
|
||||
// we could initialize the environment from the settings
|
||||
if setup == nil {
|
||||
if err := cmd.BootstrapEnvironment(ctx, environ, userConfig); err != nil {
|
||||
if err := bbgo.BootstrapEnvironment(ctx, environ, userConfig); err != nil {
|
||||
log.WithError(err).Error("failed to bootstrap environment")
|
||||
return
|
||||
}
|
||||
|
|
34
pkg/bbgo/bootstrap.go
Normal file
34
pkg/bbgo/bootstrap.go
Normal file
|
@ -0,0 +1,34 @@
|
|||
package bbgo
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func BootstrapEnvironment(ctx context.Context, environ *Environment, userConfig *Config) error {
|
||||
if err := environ.ConfigureDatabase(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
if err := environ.ConfigureNotificationSystem(userConfig); err != nil {
|
||||
return errors.Wrap(err, "notification configure error")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func BootstrapBacktestEnvironment(ctx context.Context, environ *Environment) error {
|
||||
return environ.ConfigureDatabase(ctx)
|
||||
}
|
||||
|
|
@ -155,7 +155,7 @@ var BacktestCmd = &cobra.Command{
|
|||
log.Infof("starting backtest with startTime %s", startTime.Format(time.RFC3339))
|
||||
|
||||
environ := bbgo.NewEnvironment()
|
||||
if err := BootstrapBacktestEnvironment(ctx, environ); err != nil {
|
||||
if err := bbgo.BootstrapBacktestEnvironment(ctx, environ); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -80,32 +80,6 @@ func runSetup(baseCtx context.Context, userConfig *bbgo.Config, enableApiServer
|
|||
return nil
|
||||
}
|
||||
|
||||
func BootstrapBacktestEnvironment(ctx context.Context, environ *bbgo.Environment) error {
|
||||
return environ.ConfigureDatabase(ctx)
|
||||
}
|
||||
|
||||
func BootstrapEnvironment(ctx context.Context, environ *bbgo.Environment, userConfig *bbgo.Config) error {
|
||||
if err := environ.ConfigureDatabase(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
if err := environ.ConfigureNotificationSystem(userConfig); err != nil {
|
||||
return errors.Wrap(err, "notification configure error")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func runConfig(basectx context.Context, cmd *cobra.Command, userConfig *bbgo.Config) error {
|
||||
noSync, err := cmd.Flags().GetBool("no-sync")
|
||||
if err != nil {
|
||||
|
@ -148,7 +122,7 @@ func runConfig(basectx context.Context, cmd *cobra.Command, userConfig *bbgo.Con
|
|||
defer cancelTrading()
|
||||
|
||||
environ := bbgo.NewEnvironment()
|
||||
if err := BootstrapEnvironment(ctx, environ, userConfig); err != nil {
|
||||
if err := bbgo.BootstrapEnvironment(ctx, environ, userConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ var TransferHistoryCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
environ := bbgo.NewEnvironment()
|
||||
if err := BootstrapEnvironment(ctx, environ, userConfig); err != nil {
|
||||
if err := bbgo.BootstrapEnvironment(ctx, environ, userConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user