mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
fix sync issue for pnl command
This commit is contained in:
parent
d315c12f2d
commit
34fe915a9f
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user