From 740cfe6d5c4be72b54ecee99136b6846780b15ad Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 13 Jun 2023 12:27:38 +0800 Subject: [PATCH] xalign: fix session refs --- pkg/strategy/xalign/strategy.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/strategy/xalign/strategy.go b/pkg/strategy/xalign/strategy.go index 8b198ca09..1adc975a1 100644 --- a/pkg/strategy/xalign/strategy.go +++ b/pkg/strategy/xalign/strategy.go @@ -34,6 +34,7 @@ type Strategy struct { UseTakerOrder bool `json:"useTakerOrder"` DryRun bool `json:"dryRun"` + sessions map[string]*bbgo.ExchangeSession orderBooks map[string]*bbgo.ActiveOrderBook } @@ -203,6 +204,7 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se instanceID := s.InstanceID() _ = instanceID + s.sessions = make(map[string]*bbgo.ExchangeSession) s.orderBooks = make(map[string]*bbgo.ActiveOrderBook) for _, sessionName := range s.PreferredSessions { @@ -213,11 +215,13 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se orderBook := bbgo.NewActiveOrderBook("") orderBook.BindStream(session.UserDataStream) + + s.sessions[sessionName] = session s.orderBooks[sessionName] = orderBook } go func() { - s.align(ctx, sessions) + s.align(ctx, s.sessions) ticker := time.NewTicker(s.Interval.Duration()) defer ticker.Stop() @@ -229,7 +233,7 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se return case <-ticker.C: - s.align(ctx, sessions) + s.align(ctx, s.sessions) } } }()