bitfinexcom / bitfinex-api-go

BITFINEX Go trading API - Bitcoin, Litecoin, and Ether exchange
https://www.bitfinex.com/
MIT License
309 stars 220 forks source link

Client stops receiving data #28

Closed subiol closed 7 years ago

subiol commented 7 years ago

I am running go 1.8 on Ubuntu 16.10.

I have created a client that is basically a copy of the ws-book example, but on top of printing the received data for debug from the subscribed channels, it sends the data out through a zmq socket.

The problem I am having is that the feed stops receiving data. The program does not end or segfaults, it keeps running but not more data comes in, while I can see in the bitfinex webpage that trades are happening in the pairs the channel is subscribed to.

I have taken a quick look at the code and have not found a way to set a reconnect variable (in case the websocket was not reconnecting) or any way to know if the websocket has disconnected for whatever reason (apart from the ending error coming from c.WebSocket.Subscribe() ).

Am I correct if I assume that the websocket will try to reconnect automatically if a disconnection occurs? How can I find out what is happening with the websocket to find out the reason the program stops receiving data?

knarz commented 7 years ago

Do you have any sorts of proxies between you and the API? I just had the same example running for about ten minutes without any problems, so I'd assume that it is something on your end.

Also if the websocket connection were to time out then you'd get an actual error back, so that's a bit strange—but the default read timeout also tends to be really high, or might even be infinite, so it could be a couple of (or infinite) minutes before you actually get a timeout. I'm currently working on an overhaul for this library which would also include providing methods to adjust read timeouts etc. but that's still in the works.

As far as I know the https://github.com/gorilla/websocket implementation has no automatic reconnects.

So the next step for you should most likely be trying to figure out what is happening between you and the API server, that might interrupt your connection.

subiol commented 7 years ago

I do not have any proxies between me and the API. I just did the same test, run the example unmodified, and same happened. After a couple of hours no more data would come through without any error or any other indication, the program still "running".

Can you tell me where can I check the default timeout?

knarz commented 7 years ago

If you want to play around then you should start here: https://github.com/bitfinexcom/bitfinex-api-go/blob/master/v1/websocket.go#L79

And consider these: https://godoc.org/github.com/gorilla/websocket#Conn.SetReadDeadline https://golang.org/pkg/net/#Conn

Unfortunately none of these support golang's context but I hope that helps anyway.

subiol commented 7 years ago

After adding a timeout to the websocket, I am getting an error from Subscribe once the connection drops, instead of getting stuck doing nothing.

I have created a pull request https://github.com/bitfinexcom/bitfinex-api-go/pull/30

LRonHubs commented 6 years ago

I have this problem in the NodeJS version