Marfusios / bitfinex-client-websocket

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

Reconnect not working #12

Closed andrzej-suwala closed 6 years ago

andrzej-suwala commented 6 years ago

Hi,

Thanks for all your good work. I've compiled your console sample, and reconnecting is not working. Please take a look at screenshot https://ibb.co/gYDdUc

I've run the app, disconnected internet cable, waited 30 sec. and reconnected the cable. Internet is working, but the app didn't reconnect.

Marfusios commented 6 years ago

Hello,

it seems to me, that you are not resubscribing to channels, hence you don't get any new messages and it invokes a new reconnecting.

You should handle info message and authentication message and then resubscribe, example:

client.Streams.InfoStream.Subscribe(info =>
{
    Log.Information($"Reconnection happened, Message: {info.Msg}, Version: {info.Version}");
    client.Authenticate(API_KEY, API_SECRET);
});

client.Streams.AuthenticationStream.Subscribe(auth =>
{                    
    Log.Information($"Authenticated: {auth.IsAuthenticated}");

    client.Send(new TradesSubscribeRequest("BTC/USD"));
    client.Send(new CandlesSubscribeRequest("BTC/USD", BitfinexTimeFrame.OneMinute));
    client.Send(new BookSubscribeRequest("BTC/USD", BitfinexPrecision.P0, BitfinexFrequency.TwoSecDelay));
});

communicator.Start().Wait();
andrzej-suwala commented 6 years ago

Thank you, I'll try it.