emacross, scmaker: fix strategy initialization

This commit is contained in:
c9s 2023-12-19 21:58:50 +08:00
parent 6abb320bce
commit 3dd93b65db
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 10 additions and 2 deletions

View File

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

View File

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