So I have an application which listens to the orderbook updates and trade updates for all symbols. However I'm running into an arbitrary "too many L2 streams" limit. Coinbase doesn't really specify any limits, but it apparently exist.
The limit is either 16 or between 16 and 31 (I only tested 32 and 16, 32 failed, 16 worked).
Now I can work a bit on my 'reconnect' strategy (which happens when trading symbols change), but I ended up creating a CoinbaseSocketClient in chunks of 16 symbols for both orderbook updates and trade updates.
private async Task Reconnect()
{
Log.ForContext<ConnectionService>().Information("Reconnecting websocket");
foreach (var socketClient in _socketClients)
{
await socketClient.UnsubscribeAllAsync();
socketClient.Dispose();
}
foreach (var chunk in _symbols.Chunk(16))
{
var socketClient = ActivatorUtilities.CreateInstance<CoinbaseSocketClient>(serviceProvider);
await socketClient.AdvancedTradeApi.SubscribeToOrderBookUpdatesAsync(chunk, OnOrderBookUpdates);
_socketClients.Add(socketClient);
socketClient = ActivatorUtilities.CreateInstance<CoinbaseSocketClient>(serviceProvider);
await socketClient.AdvancedTradeApi.SubscribeToTradeUpdatesAsync(chunk, OnTradeUpdates);
_socketClients.Add(socketClient);
}
var authenticatedSocketClient = ActivatorUtilities.CreateInstance<CoinbaseSocketClient>(serviceProvider);
authenticatedSocketClient.SetApiCredentials(new ApiCredentials(credentials.ApiKey, credentials.PrivateKey));
await authenticatedSocketClient.AdvancedTradeApi.SubscribeToUserUpdatesAsync(OnUserUpdates);
_socketClients.Add(authenticatedSocketClient);
}
Now it would be nice if this logic could be moved into CoinbaseSocketClient, as far as I understand it supports multiple websocket connections. But couldn't find an example client where this was done. Binance had such a limit a long time ago (around 32 per connection). Not sure if that limit is still imposed (I can't trade on Binance anymore). But, unless I'm mistaken, it's not implemented in the Binance.Net client.
So I have an application which listens to the orderbook updates and trade updates for all symbols. However I'm running into an arbitrary "too many L2 streams" limit. Coinbase doesn't really specify any limits, but it apparently exist.
The limit is either 16 or between 16 and 31 (I only tested 32 and 16, 32 failed, 16 worked).
Now I can work a bit on my 'reconnect' strategy (which happens when trading symbols change), but I ended up creating a CoinbaseSocketClient in chunks of 16 symbols for both orderbook updates and trade updates.
Now it would be nice if this logic could be moved into CoinbaseSocketClient, as far as I understand it supports multiple websocket connections. But couldn't find an example client where this was done. Binance had such a limit a long time ago (around 32 per connection). Not sure if that limit is still imposed (I can't trade on Binance anymore). But, unless I'm mistaken, it's not implemented in the Binance.Net client.