From a9e25c08d7c3fb760445bee30fc930478aae7cf2 Mon Sep 17 00:00:00 2001 From: c9s Date: Mon, 13 Jul 2020 01:06:04 +0800 Subject: [PATCH] fix reconnect close --- bbgo/exchange/binance/stream.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/bbgo/exchange/binance/stream.go b/bbgo/exchange/binance/stream.go index b80b865ec..0fa76d37e 100644 --- a/bbgo/exchange/binance/stream.go +++ b/bbgo/exchange/binance/stream.go @@ -147,12 +147,20 @@ func (s *PrivateStream) read(ctx context.Context, eventC chan interface{}) { mt, message, err := s.Conn.ReadMessage() if err != nil { - log.WithError(err).Errorf("read error: %s", err.Error()) + if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway) { + log.WithError(err).Errorf("read error: %s", err.Error()) + } // reconnect for err != nil { - err = s.connect(ctx) - time.Sleep(5 * time.Second) + select { + case <-ctx.Done(): + return + + default: + err = s.connect(ctx) + time.Sleep(5 * time.Second) + } } continue