From 3dd93b65dbeb09e5fb137b8affe7914a211f1fc4 Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 19 Dec 2023 21:58:50 +0800 Subject: [PATCH] emacross, scmaker: fix strategy initialization --- pkg/strategy/emacross/strategy.go | 8 +++++++- pkg/strategy/scmaker/strategy.go | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/strategy/emacross/strategy.go b/pkg/strategy/emacross/strategy.go index 1ece94b76..6762a4419 100644 --- a/pkg/strategy/emacross/strategy.go +++ b/pkg/strategy/emacross/strategy.go @@ -46,12 +46,18 @@ func (s *Strategy) InstanceID() string { return fmt.Sprintf("%s:%s:%s:%d-%d", ID, s.Symbol, s.Interval, s.FastWindow, s.SlowWindow) } +func (s *Strategy) Initialize() error { + if s.Strategy == nil { + s.Strategy = &common.Strategy{} + } + return nil +} + func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) { session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.Interval}) } func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.ExchangeSession) error { - s.Strategy = &common.Strategy{} s.Strategy.Initialize(ctx, s.Environment, session, s.Market, ID, s.InstanceID()) session.MarketDataStream.OnKLineClosed(types.KLineWith(s.Symbol, types.Interval5m, func(k types.KLine) { diff --git a/pkg/strategy/scmaker/strategy.go b/pkg/strategy/scmaker/strategy.go index 7ad5042c2..5292ef662 100644 --- a/pkg/strategy/scmaker/strategy.go +++ b/pkg/strategy/scmaker/strategy.go @@ -70,7 +70,9 @@ type Strategy struct { } func (s *Strategy) Initialize() error { - s.Strategy = &common.Strategy{} + if s.Strategy == nil { + s.Strategy = &common.Strategy{} + } return nil }