fix ftx pollKines bug

This commit is contained in:
kfrico 2022-04-19 21:29:45 +08:00
parent 9b507d8c3d
commit bd4a932571
2 changed files with 8 additions and 6 deletions

View File

@ -145,17 +145,17 @@ func (s *Stream) Subscribe(channel types.Channel, symbol string, option types.Su
}
func (s *Stream) pollKLines(ctx context.Context) {
lastClosed := map[types.Interval]time.Time{}
lastClosed := make(map[string]map[types.Interval]time.Time, 0)
// get current kline candle
for _, sub := range s.klineSubscriptions {
klines := getLast2KLine(s.exchange, ctx, sub.symbol, sub.interval)
lastClosed[sub.symbol] = make(map[types.Interval]time.Time, 0)
if len(klines) > 0 {
// handle mutiple klines, get the latest one
if lastClosed[sub.interval].Unix() < klines[0].StartTime.Unix() {
if lastClosed[sub.symbol][sub.interval].Unix() < klines[0].StartTime.Unix() {
s.EmitKLine(klines[0])
s.EmitKLineClosed(klines[0])
lastClosed[sub.interval] = klines[0].StartTime.Time()
lastClosed[sub.symbol][sub.interval] = klines[0].StartTime.Time()
}
if len(klines) > 1 {
@ -187,10 +187,10 @@ func (s *Stream) pollKLines(ctx context.Context) {
if len(klines) > 0 {
// handle mutiple klines, get the latest one
if lastClosed[sub.interval].Unix() < klines[0].StartTime.Unix() {
if lastClosed[sub.symbol][sub.interval].Unix() < klines[0].StartTime.Unix() {
s.EmitKLine(klines[0])
s.EmitKLineClosed(klines[0])
lastClosed[sub.interval] = klines[0].StartTime.Time()
lastClosed[sub.symbol][sub.interval] = klines[0].StartTime.Time()
}
if len(klines) > 1 {

View File

@ -813,4 +813,6 @@ var symbolMap = map[string]string{
"ZMUSD": "ZM/USD",
"ZRX-PERP": "ZRX-PERP",
"ZRXUSD": "ZRX/USD",
"GMTUSD": "GMT/USD",
"GMT-PERP": "GMT-PERP",
}