mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
split environment start and init
This commit is contained in:
parent
14eedecd0e
commit
6bbd66a4f9
|
@ -198,6 +198,7 @@ func (e Exchange) QueryKLines(ctx context.Context, symbol string, interval types
|
|||
if options.EndTime != nil {
|
||||
return e.srv.QueryKLinesBackward(e.sourceName, symbol, interval, *options.EndTime)
|
||||
}
|
||||
|
||||
if options.StartTime != nil {
|
||||
return e.srv.QueryKLinesForward(e.sourceName, symbol, interval, *options.StartTime)
|
||||
}
|
||||
|
|
|
@ -274,27 +274,33 @@ func (environ *Environment) AddExchangesFromSessionConfig(sessions map[string]*E
|
|||
return nil
|
||||
}
|
||||
|
||||
|
||||
// Init prepares the data that will be used by the strategies
|
||||
func (environ *Environment) Init(ctx context.Context) (err error) {
|
||||
for n := range environ.sessions {
|
||||
var session = environ.sessions[n]
|
||||
|
||||
if err := session.Init(ctx, environ); err != nil {
|
||||
if err = session.Init(ctx, environ); err != nil {
|
||||
// we can skip initialized sessions
|
||||
if err != ErrSessionAlreadyInitialized {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := session.InitSymbols(ctx, environ); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
func (environ *Environment) Start(ctx context.Context) (err error) {
|
||||
for n := range environ.sessions {
|
||||
var session = environ.sessions[n]
|
||||
if err = session.InitSymbols(ctx, environ); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
func (environ *Environment) ConfigurePersistence(conf *PersistenceConfig) error {
|
||||
if conf.Redis != nil {
|
||||
if err := env.Set(conf.Redis); err != nil {
|
||||
|
@ -552,10 +558,6 @@ func (environ *Environment) SyncSession(ctx context.Context, session *ExchangeSe
|
|||
}
|
||||
|
||||
func (environ *Environment) syncSession(ctx context.Context, session *ExchangeSession, defaultSymbols ...string) error {
|
||||
if err := session.Init(ctx, environ); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
symbols, err := getSessionSymbols(session, defaultSymbols...)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -295,7 +295,7 @@ func (trader *Trader) RunAllSingleExchangeStrategy(ctx context.Context) error {
|
|||
func (trader *Trader) Run(ctx context.Context) error {
|
||||
trader.Subscribe()
|
||||
|
||||
if err := trader.environment.Init(ctx); err != nil {
|
||||
if err := trader.environment.Start(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user