Marfusios / bitfinex-client-websocket

🛠️ C# client for Bitfinex & Ethfinex websocket API version 2.0
Apache License 2.0
55 stars 38 forks source link

API Update – September 1st, 2018 - Rate limiting #18

Closed InTheta closed 5 years ago

InTheta commented 6 years ago

http://blog.bitfinex.com/api/api-update-september-2018/

"As of September 1st, every WebSocket connection will have a limit of 50 subscriptions to market data feed channels (tickers, book, candles, trades, …)."

They are already rolling this out, as I have spent 2 day debugging thining I have a threading issue, but its actually this.

How can we fix this?

Split the pairs into groups?

Here is a log with the errors i'm receiving https://pastebin.com/vcLy9SpL (log dump with errors)

Marfusios commented 6 years ago

Hello,

it seems that we are able to call up to 50 subscribe requests on the one websockets connection. So the solution seems to create more BitfinexWebsocketCommunicator and BitfinexWebsocketClient. I would prefer to leave it up to the client to handle that situation and just provide good error message from library.

Usage example:

public async Task<BitfinexWebsocketClient> CreateClient(Action<BitfinexWebsocketClient> subscribeAction)
{
    var communicator = new BitfinexWebsocketCommunicator(url);
    var client = new BitfinexWebsocketClient(communicator);

    client.Streams.InfoStream.Subscribe(info =>
    {
        Log.Information($"Info received, reconnection happened, resubscribing to streams");
        subscribeAction(client);
    });
    await communicator.Start();
}

var client1 = CreateClient(client => {
  client.Send(new TickerSubscribeRequest("BTC/USD")).Wait();
  //... up to 50x
});

var client2 = CreateClient(client => {
  client.Send(new TickerSubscribeRequest("ETH/USD")).Wait();
  //... up to 50x
});

I will prepare some better error message for that new rate limit.