From e0d3013866825660aad493f5d482c578a60b0b0d Mon Sep 17 00:00:00 2001 From: c9s Date: Sat, 16 Nov 2024 02:47:22 +0800 Subject: [PATCH] xdepthmaker: separate a stream for order book --- pkg/strategy/xdepthmaker/strategy.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pkg/strategy/xdepthmaker/strategy.go b/pkg/strategy/xdepthmaker/strategy.go index e31ccfda0..10843d995 100644 --- a/pkg/strategy/xdepthmaker/strategy.go +++ b/pkg/strategy/xdepthmaker/strategy.go @@ -323,11 +323,6 @@ func (s *Strategy) CrossSubscribe(sessions map[string]*bbgo.ExchangeSession) { panic(err) } - hedgeSession.Subscribe(types.BookChannel, s.HedgeSymbol, types.SubscribeOptions{ - Depth: types.DepthLevelFull, - Speed: types.SpeedLow, - }) - hedgeSession.Subscribe(types.KLineChannel, s.HedgeSymbol, types.SubscribeOptions{Interval: "1m"}) hedgeSession.Subscribe(types.KLineChannel, hedgeSession.Exchange.PlatformFeeCurrency()+"USDT", types.SubscribeOptions{Interval: "1m"}) @@ -569,8 +564,19 @@ func (s *Strategy) CrossRun( return err } + sourceMarketStream := s.hedgeSession.Exchange.NewStream() + sourceMarketStream.SetPublicOnly() + sourceMarketStream.Subscribe(types.BookChannel, s.HedgeSymbol, types.SubscribeOptions{ + Depth: types.DepthLevelFull, + Speed: types.SpeedLow, + }) + s.sourceBook = types.NewStreamBook(s.HedgeSymbol, s.hedgeSession.ExchangeName) - s.sourceBook.BindStream(s.hedgeSession.MarketDataStream) + s.sourceBook.BindStream(sourceMarketStream) + + if err := sourceMarketStream.Connect(ctx); err != nil { + return err + } s.priceSolver = pricesolver.NewSimplePriceResolver(s.makerSession.Markets()) s.priceSolver.BindStream(s.hedgeSession.MarketDataStream)