From f6c70bdfcb656e8ea83b5f2be52b97d49098dacf Mon Sep 17 00:00:00 2001 From: Lee Date: Sat, 15 Jan 2022 05:12:45 +0800 Subject: [PATCH] ftx: Separate the lastClosed record for different interval --- pkg/exchange/ftx/stream.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/exchange/ftx/stream.go b/pkg/exchange/ftx/stream.go index 07f64c96e..bc2dcb8aa 100644 --- a/pkg/exchange/ftx/stream.go +++ b/pkg/exchange/ftx/stream.go @@ -133,16 +133,16 @@ func (s *Stream) Subscribe(channel types.Channel, symbol string, option types.Su func (s *Stream) pollKLines(ctx context.Context) { - lastClosed := time.Time{} + lastClosed := map[types.Interval]time.Time{} // get current kline candle for _, sub := range s.klineSubscriptions { klines := getLast2KLine(s.exchange, ctx, sub.symbol, sub.interval) if len(klines) > 0 { // handle mutiple klines, get the latest one - if lastClosed.Unix() < klines[0].StartTime.Unix() { + if lastClosed[sub.interval].Unix() < klines[0].StartTime.Unix() { s.EmitKLine(klines[0]) s.EmitKLineClosed(klines[0]) - lastClosed = klines[0].StartTime.Time() + lastClosed[sub.interval] = klines[0].StartTime.Time() } if len(klines) > 1 { @@ -174,10 +174,10 @@ func (s *Stream) pollKLines(ctx context.Context) { if len(klines) > 0 { // handle mutiple klines, get the latest one - if lastClosed.Unix() < klines[0].StartTime.Unix() { + if lastClosed[sub.interval].Unix() < klines[0].StartTime.Unix() { s.EmitKLine(klines[0]) s.EmitKLineClosed(klines[0]) - lastClosed = klines[0].StartTime.Time() + lastClosed[sub.interval] = klines[0].StartTime.Time() } if len(klines) > 1 {