Merge pull request #547 from kfrico/fix_ftx_bug

fix ftx pollKines bug
This commit is contained in:
Yo-An Lin 2022-04-20 11:52:16 +08:00 committed by GitHub
commit 522e6b9aaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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",
}