diff --git a/gdax/listener_service.go b/gdax/listener_service.go index 9053769..b1363b5 100644 --- a/gdax/listener_service.go +++ b/gdax/listener_service.go @@ -19,6 +19,9 @@ type ListenerService struct { closed bool shouldRestart bool restMu sync.Mutex + + errorsMu sync.Mutex + sendErrors bool } func (s *ListenerService) Open() error { @@ -95,13 +98,19 @@ func (s *ListenerService) listen() { go func() { for err := range s.Client.Error() { s.Logger.Info("Error from GDAX client: %v", err) - s.err <- err + + if s.SendErrors() { + s.err <- err + } } + s.Logger.Info("Error closed") + if s.restart() { err := s.Open() if err != nil { s.Logger.Info("GDAX Unable to reastablish connection") + s.Close() return } s.Subscribe(s.subs...) @@ -123,3 +132,17 @@ func (s *ListenerService) setRestart(restart bool) { s.shouldRestart = restart } + +func (s *ListenerService) SendErrors() bool { + s.errorsMu.Lock() + defer s.errorsMu.Unlock() + + return s.sendErrors +} + +func (s *ListenerService) SetSendErrors(send bool) { + s.errorsMu.Lock() + defer s.errorsMu.Unlock() + + s.sendErrors = send +} diff --git a/gdax/websocket/client.go b/gdax/websocket/client.go index 8ac263e..44861fe 100644 --- a/gdax/websocket/client.go +++ b/gdax/websocket/client.go @@ -50,12 +50,13 @@ func (c *Client) Open() error { websocket.CloseNormalClosure) { c.sendClose(false) c.err <- err - break } + break } c.msgs <- msg } + close(c.msgs) close(c.err) }()