diff --git a/pkg/bbgo/environment.go b/pkg/bbgo/environment.go index a9be344c0..4aef7855e 100644 --- a/pkg/bbgo/environment.go +++ b/pkg/bbgo/environment.go @@ -285,9 +285,6 @@ func (environ *Environment) Init(ctx context.Context) (err error) { } } - if err := session.InitSymbols(ctx, environ); err != nil { - return err - } } return nil diff --git a/pkg/bbgo/session.go b/pkg/bbgo/session.go index 884643c03..c09f44b1d 100644 --- a/pkg/bbgo/session.go +++ b/pkg/bbgo/session.go @@ -267,18 +267,17 @@ func (session *ExchangeSession) Init(ctx context.Context, environ *Environment) session.lastPrices[kline.Symbol] = kline.Close }) + if err := session.initUsedSymbols(ctx, environ); err != nil { + return err + } + session.IsInitialized = true return nil } -// InitSymbols uses usedSymbols to initialize the related data structure -func (session *ExchangeSession) InitSymbols(ctx context.Context, environ *Environment) error { +// initUsedSymbols uses usedSymbols to initialize the related data structure +func (session *ExchangeSession) initUsedSymbols(ctx context.Context, environ *Environment) error { for symbol := range session.usedSymbols { - // skip initialized symbols - if _, ok := session.initializedSymbols[symbol]; ok { - continue - } - if err := session.InitSymbol(ctx, environ, symbol); err != nil { return err } @@ -291,7 +290,8 @@ func (session *ExchangeSession) InitSymbols(ctx context.Context, environ *Enviro // please note, InitSymbol can not be called for the same symbol for twice func (session *ExchangeSession) InitSymbol(ctx context.Context, environ *Environment, symbol string) error { if _, ok := session.initializedSymbols[symbol]; ok { - return fmt.Errorf("symbol %s is already initialized", symbol) + // return fmt.Errorf("symbol %s is already initialized", symbol) + return nil } market, ok := session.markets[symbol] diff --git a/pkg/cmd/pnl.go b/pkg/cmd/pnl.go index 692d76ea4..93e0848d8 100644 --- a/pkg/cmd/pnl.go +++ b/pkg/cmd/pnl.go @@ -81,16 +81,12 @@ var PnLCmd = &cobra.Command{ return err } - if err := environ.Init(ctx) ; err != nil { - return err - } - session, ok := environ.Session(sessionName) if !ok { return fmt.Errorf("session %s not found", sessionName) } - if err := environ.Sync(ctx) ; err != nil { + if err := environ.SyncSession(ctx, session) ; err != nil { return err }