mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-08 00:16:27 +00:00
Small basesocket changes, added total request prop to rest client
This commit is contained in:
parent
2b1c77577c
commit
b5a80a3095
@ -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<byte[], string> DataInterpreter { get; set; }
|
||||
|
@ -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<string, string> cookies, IDictionary<string, string> headers);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ namespace CryptoExchange.Net
|
||||
protected TimeSpan RequestTimeout { get; private set; }
|
||||
public RateLimitingBehaviour RateLimitBehaviour { get; private set; }
|
||||
public IEnumerable<IRateLimiter> 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()))
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -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<string, string> cookies, IDictionary<string, string> headers)
|
||||
{
|
||||
return new BaseSocket(log, url, cookies, headers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user