Websocket ticker channel slowing down

I am trying to get ticker data via Coinbase’s Websocket interface, but am running into problems doing so.

I subscribe to the ticker channel via Websockets, and everything goes okay for the first minute or first few minutes. Then, the ticker messages slow down or just stop coming entirely. (This appears to be incorrect because other sources say there are no entire minutes in which there are literally zero BTC-USD trades, but Coinbase’s Websockets ticker channel gives zero BTC-USD messages in that time.) If I close the connection, wait a minute, then reconnect everything goes fine for a minute or a few minutes, then the slowdown resumes. If I wait just a second, the slowdown persists.

Here is the message I use to subscribe:
{“type”:“subscribe”,“channels”:[{“name”:“ticker”,“product_ids”:[“BTC-USD”,“ETH-USD”,“LTC-USD”,“BCH-USD”,“DOGE-USD”,“LINK-USD”,“AVAX-USD”,“DOT-USD”]}]}

The documentation says that the ticker channel does not require authentication, so I am not going through authentication for this. (I just started interfacing with Coinbase Websockets this past week, so I’m keeping it simple to start.)

This doesn’t seem to happen if I only subscribe to BTC-USD, and restart the connection (unsubscribe, close the Websocket, reopen, and resubscribe) every minute.

For what you are using that channel?

To get the latest prices, as up to the second as possible. I understand that e.g. ticker_batch is only every 5 seconds, and the REST API lags by up to 5 minutes. I tried using match and ticker_batch as well; both of them had the same issue.

Hi @ATymes! Thank you for being part of the forum community! We understand that you are facing an issue with the ticker channel.

For now can you please try the below troubleshooting steps:

  1. Check the documentation: Make sure you have correctly formatted your subscription message and that you have included all the necessary parameters

  2. Authentication: Ensure that you are not using authentication when subscribing to the ticker channel, as it is not required for this channel

  3. Heartbeat channel: Coinbase provides a heartbeat channel that sends real-time server pings to keep all connections open
    (Advanced Trade WebSocket Channels | Coinbase Cloud). You can subscribe to the heartbeat channel to ensure that no messages are missed and to help track the last trade ID

  4. Reconnection: If you have tried reconnecting the WebSocket after a certain period, make sure to use the correct parameters and format your subscription message as described in the documentation.

  5. Monitor network issues: Check if there are any network issues or interruptions that might be causing the slowdown or disconnection.

We hope this helps.

In case these steps do not help, let us know and we will try our best to resolve this issue for you.
Thank you :slight_smile:

Is that true? I can not connect to that channel without authentication…

But I guess this is not about Advanced Trade WebSocket! Based on his subscribe message he is using Exchange/Pro WebSocket.

The problem has gotten worse since I posted: even just monitoring BTC-USD and ETH-USD, or just BTC-USD, the ticker feed far too often starts dropping trades, going several seconds between trades when other sources confirm that there have been multiple trades on these symbols on Coinbase during those seconds.

Check the documentation

I did that, and it seems correct. I included my subscribe message in my initial post so y’all could double check and confirm.

Authentication

Correct, I am not using authentication.

Heartbeat channel

Yes, I am missing a bunch of trades. My question is not, “What can I do about it?”, but rather, “How can I not miss a bunch of trades in the first place?”

Reconnection

Yes, I am doing this. See above about the documentation. I send the same subscribe message upon reconnection.

Monitor network issues

Seems fine from my end. I can ping www.google.com just fine.

In case these steps do not help, let us know

They did not help. I was already following those steps and the problem continues to exist.

But I guess this is not about Advanced Trade WebSocket! Based on his subscribe message he is using Exchange/Pro WebSocket.

This seemed like the subforum for Coinbase’s Websocket interface. I am connecting to wss://ws-feed.exchange.coinbase.com . Should I have posted to the Exchange/Pro API subforum instead?

Yes, at least I think so. Both have websockets and they are different…

Have you increased receive buffer as suggested by documentation? Maybe buffer is small enough that it fills too fast and your websocket implementation silently drops messages?