diff --git a/CryptoExchange.Net/Interfaces/IWebsocket.cs b/CryptoExchange.Net/Interfaces/IWebsocket.cs index a208d66..7686d6d 100644 --- a/CryptoExchange.Net/Interfaces/IWebsocket.cs +++ b/CryptoExchange.Net/Interfaces/IWebsocket.cs @@ -13,6 +13,7 @@ namespace CryptoExchange.Net.Interfaces event Action OnOpen; int Id { get; } + string Origin { get; set; } bool ShouldReconnect { get; set; } bool Reconnecting { get; set; } Func DataInterpreter { get; set; } diff --git a/CryptoExchange.Net/Interfaces/IWebsocketFactory.cs b/CryptoExchange.Net/Interfaces/IWebsocketFactory.cs index bc265f0..e3a45c7 100644 --- a/CryptoExchange.Net/Interfaces/IWebsocketFactory.cs +++ b/CryptoExchange.Net/Interfaces/IWebsocketFactory.cs @@ -1,9 +1,11 @@ -using CryptoExchange.Net.Logging; +using System.Collections.Generic; +using CryptoExchange.Net.Logging; namespace CryptoExchange.Net.Interfaces { public interface IWebsocketFactory { IWebsocket CreateWebsocket(Log log, string url); + IWebsocket CreateWebsocket(Log log, string url, IDictionary cookies, IDictionary headers); } } diff --git a/CryptoExchange.Net/RestClient.cs b/CryptoExchange.Net/RestClient.cs index f32ca2d..943a2d1 100644 --- a/CryptoExchange.Net/RestClient.cs +++ b/CryptoExchange.Net/RestClient.cs @@ -33,6 +33,7 @@ namespace CryptoExchange.Net protected TimeSpan RequestTimeout { get; private set; } public RateLimitingBehaviour RateLimitBehaviour { get; private set; } public IEnumerable RateLimiters { get; private set; } + public int TotalRequestsMade { get; private set; } protected RestClient(ClientOptions exchangeOptions, AuthenticationProvider authenticationProvider): base(exchangeOptions, authenticationProvider) { @@ -270,6 +271,7 @@ namespace CryptoExchange.Net try { request.Timeout = RequestTimeout; + TotalRequestsMade++; var response = await request.GetResponse().ConfigureAwait(false); using (var reader = new StreamReader(response.GetResponseStream())) { diff --git a/CryptoExchange.Net/Sockets/BaseSocket.cs b/CryptoExchange.Net/Sockets/BaseSocket.cs index f3da7d0..9f408c5 100644 --- a/CryptoExchange.Net/Sockets/BaseSocket.cs +++ b/CryptoExchange.Net/Sockets/BaseSocket.cs @@ -35,6 +35,7 @@ namespace CryptoExchange.Net.Sockets public bool ShouldReconnect { get; set; } public bool Reconnecting { get; set; } + public string Origin { get; set; } public string Url { get; } public bool IsClosed => socket.State == WebSocketState.Closed; @@ -173,6 +174,7 @@ namespace CryptoExchange.Net.Sockets { lock (socketLock) { + log.Write(LogVerbosity.Debug, $"Socket {Id} resetting"); socket?.Dispose(); socket = null; } @@ -187,7 +189,7 @@ namespace CryptoExchange.Net.Sockets { if (socket == null) { - socket = new WebSocket(Url, cookies: cookies.ToList(), customHeaderItems: headers.ToList()) + socket = new WebSocket(Url, cookies: cookies.ToList(), customHeaderItems: headers.ToList(), origin: Origin ?? "") { EnableAutoSendPing = true, AutoSendPingInterval = 10 @@ -243,7 +245,7 @@ namespace CryptoExchange.Net.Sockets } if (socket.State == WebSocketState.Connecting) - Close().Wait(); + socket.Close(); return connected; }).ConfigureAwait(false); diff --git a/CryptoExchange.Net/Sockets/WebsocketFactory.cs b/CryptoExchange.Net/Sockets/WebsocketFactory.cs index 3b27532..02b0a36 100644 --- a/CryptoExchange.Net/Sockets/WebsocketFactory.cs +++ b/CryptoExchange.Net/Sockets/WebsocketFactory.cs @@ -1,4 +1,5 @@ -using CryptoExchange.Net.Interfaces; +using System.Collections.Generic; +using CryptoExchange.Net.Interfaces; using CryptoExchange.Net.Logging; namespace CryptoExchange.Net.Sockets @@ -9,5 +10,10 @@ namespace CryptoExchange.Net.Sockets { return new BaseSocket(log, url); } + + public IWebsocket CreateWebsocket(Log log, string url, IDictionary cookies, IDictionary headers) + { + return new BaseSocket(log, url, cookies, headers); + } } }