JKorf / Kucoin.Net

A C# .netstandard client library for the Kucoin REST and Websocket Spot and Futures API focusing on clear usage and models
https://jkorf.github.io/Kucoin.Net/
MIT License
113 stars 61 forks source link

Futures socket connection does not ping #195

Closed vgpro54321 closed 1 year ago

vgpro54321 commented 1 year ago

Hello Guys,

I am noticing that futures socket is disconnecting at 1 minute intervals, disconnect look like initiated by server. I see that Kucoin documentation requires 60 seconds pings but pings are only issued by spot socket client, not by futures client.

I noticed that there is a difference in KucoinSocketClientSpotStreams and KucoinSocketClientFuturesStreams constructors: futures class does not hook up pinging infrastructure.


 internal KucoinSocketClientSpotStreams(Log log, KucoinSocketClient baseClient, KucoinSocketClientOptions options)
            : base(log, options, options.SpotStreamsOptions)
        {
            _baseClient = baseClient;
            _options = options;

            **SendPeriodic("Ping", TimeSpan.FromSeconds(30), (connection) => new KucoinPing()
            {
                Id = Math.Round((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds).ToString(CultureInfo.InvariantCulture),
                Type = "ping"
            });

            AddGenericHandler("Ping", (messageEvent) => { });
            AddGenericHandler("Welcome", (messageEvent) => { });**
        }
vgpro54321 commented 1 year ago

Qucik workaround (without library mods) causing unhandled 'pong' messages but does keep connection alive.


 class KucoinPing
        {
            [JsonProperty("id")]
            public string Id { get; set; } = string.Empty;
            [JsonProperty("type")]
            public string Type { get; set; } = string.Empty;
        }

            kucoinSocketClient = new KucoinSocketClient(kucoinOptionsBuilder.GetSocketClientOptions());
            kucoinSocketClient.FuturesStreams.SendPeriodic("Ping", TimeSpan.FromSeconds(30), (connection) => new KucoinPing()
            {
                Id = Math.Round((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds).ToString(CultureInfo.InvariantCulture),
                Type = "ping"
            });
JKorf commented 1 year ago

Has been fixed in the latest version