fix sync issue for pnl command

This commit is contained in:
c9s 2021-04-09 12:43:13 +08:00
parent d315c12f2d
commit 34fe915a9f
3 changed files with 9 additions and 16 deletions

View File

@ -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

View File

@ -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]

View File

@ -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
}