Merge pull request #382 from tony1223/bug/ftx-kline-crash

exchange/ftx: add more guard condition
This commit is contained in:
Yo-An Lin 2021-12-21 20:52:37 +08:00 committed by GitHub
commit 11818e99f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -177,11 +177,14 @@ func (s *Stream) pollKLines(ctx context.Context) {
s.EmitKLineClosed(klines[0])
lastClosed = klines[0].StartTime.Time()
}
if len(klines) > 1 {
s.EmitKLine(klines[1])
}
}
}
}
}
}
func getLast2KLine(e *Exchange, ctx context.Context, symbol string, interval types.Interval) []types.KLine {
@ -202,6 +205,9 @@ func getLast2KLine(e *Exchange, ctx context.Context, symbol string, interval typ
func getLastClosedKLine(e *Exchange, ctx context.Context, symbol string, interval types.Interval) []types.KLine {
// set since to more 30s ago to avoid getting no kline candle
klines := getLast2KLine(e, ctx, symbol, interval)
if len(klines) == 0 {
return []types.KLine{}
}
return []types.KLine{klines[0]}
}