xgap: share sourceKLineHandler

This commit is contained in:
c9s 2024-11-15 23:47:25 +08:00
parent e67a6c56c9
commit 050d1ca794
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -159,16 +159,13 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se
})
// from here, set data binding
s.sourceSession.MarketDataStream.OnKLine(func(kline types.KLine) {
sourceKLineHandler := func(kline types.KLine) {
s.mu.Lock()
s.lastSourceKLine = kline
s.mu.Unlock()
})
s.tradingSession.MarketDataStream.OnKLine(func(kline types.KLine) {
s.mu.Lock()
s.lastTradingKLine = kline
s.mu.Unlock()
})
}
s.sourceSession.MarketDataStream.OnKLine(sourceKLineHandler)
s.tradingSession.MarketDataStream.OnKLine(sourceKLineHandler)
if s.SourceExchange != "" && s.SourceSymbol != "" {
s.sourceBook = types.NewStreamBook(s.SourceSymbol, sourceSession.ExchangeName)