fix backtest Initialize call

This commit is contained in:
c9s 2024-01-28 14:29:54 +08:00
parent 4b70f864ff
commit 9efd8bd604
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
4 changed files with 9 additions and 3 deletions

View File

@ -26,7 +26,7 @@ backtest:
endTime: "2022-03-01" endTime: "2022-03-01"
symbols: symbols:
- BTCUSDT - BTCUSDT
sessions: [max,binance] sessions: [binance]
# syncSecKLines: true # syncSecKLines: true
accounts: accounts:
binance: binance:

View File

@ -357,7 +357,6 @@ func (trader *Trader) Run(ctx context.Context) error {
} }
func (trader *Trader) Initialize(ctx context.Context) error { func (trader *Trader) Initialize(ctx context.Context) error {
log.Infof("initializing strategies...")
return trader.IterateStrategies(func(strategy StrategyID) error { return trader.IterateStrategies(func(strategy StrategyID) error {
if initializer, ok := strategy.(StrategyInitializer); ok { if initializer, ok := strategy.(StrategyInitializer); ok {
return initializer.Initialize() return initializer.Initialize()

View File

@ -303,6 +303,10 @@ var BacktestCmd = &cobra.Command{
return err return err
} }
if err := trader.Initialize(ctx); err != nil {
return err
}
if err := trader.Run(ctx); err != nil { if err := trader.Run(ctx); err != nil {
return err return err
} }

View File

@ -37,7 +37,10 @@ type Strategy struct {
} }
func (s *Strategy) Initialize() error { func (s *Strategy) Initialize() error {
if s.Strategy == nil {
s.Strategy = &common.Strategy{} s.Strategy = &common.Strategy{}
}
return nil return nil
} }