I setup a Websocket connection and subscribe to the user channel. After the initial messages, there is not much traffic unless a trade is made. After a minute or so, Websocket is getting killed and I have to reconnect. I do not see any keep_alive mechanism. No ping/pong or equivalent.
How are we supposed to keep a trading websocket alive?
Hi @jmedved! We understand that you have set up a Websocket connection and subscribed to a user channel but are getting disconnected after receiving initial messages. We also understand that you are looking for any keep_alive mechanism or its equivalent that could work for the Websocket channel so that this scenario of being disconnected from the channel is prevented. However, we regret to inform you that such a feature/mechanism is not yet available with the Websocket. As a workaround for now, we suggest that you try adding an implementation within your code that will automatically reconnect your Websocket upon disconnecting. Disconnects are normal with Websockets and are sometimes even forced by us when deploying updates. Also, you may consider increasing the timeout window for the library or stack you are using.
Additionally, we also suggest you to avoid having the Websocket connection being established over the public internet as this may also cause intermittent network connection and also cause latency delay in delivering update messages over the channel or being disconnected from it. You can check out this section to know more about the best practices when utilizing Websocket channels.
Lastly, we would like to inform you that we have logged this as a feedback with our internal teams so we can continue improving our user experience. Most new features and improvements to our products come directly from feedback like yours, so it’s very valuable to us. While we can’t offer any specific timeline for adding features, we are constantly working to build products our customers will love. And if you want to stay up to date on the latest from Coinbase Cloud, you can also bookmark the following webpage and subscribe to email updates at the bottom of the page: https://www.coinbase.com/cloud/discover
We hope this is helpful, and please let us know if you have any other questions. Have a nice day!
occational disconnects are expected and we do have reconnect logic in place. This however is very systematic every 70 to 90 seconds, and is inititiated by the server, not some timeout on our end and definitely not caused by internet traffic. Having reconnects so often, even if they are fast, is very bad since that will inevitably lead to some missed messages.
Please put in some simple keep alive mechanism or check on the whole disconnect for inactivity
One workaround is to connect to both the
user and the
ticker_batch on the same stream and just use a single product id for the
ticker_batch subscription, like
BTC-USD. This will send you a ticker snapshot every 5 seconds on the user stream which keeps it from disconnecting.
Y, I like that. kludge but it works