Skip to content

Failed to evaluate message. Data: {"type":"error","message":"too many L2 streams requested in a single session"} #19

@Da-Teach

Description

@Da-Teach

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions