diff --git a/CryptoExchange.Net/Clients/BaseSocketClient.cs b/CryptoExchange.Net/Clients/BaseSocketClient.cs index eeda53a..7979935 100644 --- a/CryptoExchange.Net/Clients/BaseSocketClient.cs +++ b/CryptoExchange.Net/Clients/BaseSocketClient.cs @@ -40,6 +40,10 @@ namespace CryptoExchange.Net /// protected int MaxSocketConnections { get; set; } = 9999; /// + /// Keep alive interval for websocket connection + /// + protected TimeSpan KeepAliveInterval { get; set; } = TimeSpan.FromSeconds(10); + /// /// Delegate used for processing byte data received from socket connections before it is processed by handlers /// protected Func? dataInterpreterBytes; @@ -574,6 +578,7 @@ namespace CryptoExchange.Net if (ClientOptions.Proxy != null) socket.SetProxy(ClientOptions.Proxy); + socket.KeepAliveInterval = KeepAliveInterval; socket.Timeout = ClientOptions.SocketNoDataTimeout; socket.DataInterpreterBytes = dataInterpreterBytes; socket.DataInterpreterString = dataInterpreterString; diff --git a/CryptoExchange.Net/Interfaces/IWebsocket.cs b/CryptoExchange.Net/Interfaces/IWebsocket.cs index 153d476..9d40d86 100644 --- a/CryptoExchange.Net/Interfaces/IWebsocket.cs +++ b/CryptoExchange.Net/Interfaces/IWebsocket.cs @@ -77,6 +77,10 @@ namespace CryptoExchange.Net.Interfaces /// TimeSpan Timeout { get; set; } /// + /// The interval at which to send a ping frame to the server + /// + TimeSpan KeepAliveInterval { get; set; } + /// /// Set a proxy to use when connecting /// /// diff --git a/CryptoExchange.Net/Sockets/CryptoExchangeWebSocketClient.cs b/CryptoExchange.Net/Sockets/CryptoExchangeWebSocketClient.cs index 6d5fc97..ad9b85e 100644 --- a/CryptoExchange.Net/Sockets/CryptoExchangeWebSocketClient.cs +++ b/CryptoExchange.Net/Sockets/CryptoExchangeWebSocketClient.cs @@ -122,6 +122,9 @@ namespace CryptoExchange.Net.Sockets /// public TimeSpan Timeout { get; set; } + /// + public TimeSpan KeepAliveInterval { get; set; } + /// public double IncomingKbps { @@ -332,7 +335,7 @@ namespace CryptoExchange.Net.Sockets socket.Options.Cookies = cookieContainer; foreach (var header in headers) socket.Options.SetRequestHeader(header.Key, header.Value); - socket.Options.KeepAliveInterval = TimeSpan.FromSeconds(10); + socket.Options.KeepAliveInterval = KeepAliveInterval; socket.Options.SetBuffer(65536, 65536); // Setting it to anything bigger than 65536 throws an exception in .net framework return socket; }