mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-08-31 12:42:00 +00:00
.
This commit is contained in:
parent
9ba29035b2
commit
73764970b0
@ -1,132 +0,0 @@
|
|||||||
//using System;
|
|
||||||
//using System.IO;
|
|
||||||
//using System.Net.WebSockets;
|
|
||||||
//using System.Security.Authentication;
|
|
||||||
//using System.Text;
|
|
||||||
//using System.Threading.Tasks;
|
|
||||||
//using CryptoExchange.Net.Interfaces;
|
|
||||||
//using CryptoExchange.Net.Objects;
|
|
||||||
|
|
||||||
//namespace CryptoExchange.Net.UnitTests.TestImplementations
|
|
||||||
//{
|
|
||||||
// public class TestSocket: IWebsocket
|
|
||||||
// {
|
|
||||||
// public bool CanConnect { get; set; }
|
|
||||||
// public bool Connected { get; set; }
|
|
||||||
|
|
||||||
// public event Func<Task> OnClose;
|
|
||||||
//#pragma warning disable 0067
|
|
||||||
// public event Func<Task> OnReconnected;
|
|
||||||
// public event Func<Task> OnReconnecting;
|
|
||||||
// public event Func<int, Task> OnRequestRateLimited;
|
|
||||||
//#pragma warning restore 0067
|
|
||||||
// public event Func<int, Task> OnRequestSent;
|
|
||||||
// public event Func<WebSocketMessageType, ReadOnlyMemory<byte>, Task> OnStreamMessage;
|
|
||||||
// public event Func<Exception, Task> OnError;
|
|
||||||
// public event Func<Task> OnOpen;
|
|
||||||
// public Func<Task<Uri>> GetReconnectionUrl { get; set; }
|
|
||||||
|
|
||||||
// public int Id { get; }
|
|
||||||
// public bool ShouldReconnect { get; set; }
|
|
||||||
// public TimeSpan Timeout { get; set; }
|
|
||||||
// public Func<string, string> DataInterpreterString { get; set; }
|
|
||||||
// public Func<byte[], string> DataInterpreterBytes { get; set; }
|
|
||||||
// public DateTime? DisconnectTime { get; set; }
|
|
||||||
// public string Url { get; }
|
|
||||||
// public bool IsClosed => !Connected;
|
|
||||||
// public bool IsOpen => Connected;
|
|
||||||
// public bool PingConnection { get; set; }
|
|
||||||
// public TimeSpan PingInterval { get; set; }
|
|
||||||
// public SslProtocols SSLProtocols { get; set; }
|
|
||||||
// public Encoding Encoding { get; set; }
|
|
||||||
|
|
||||||
// public int ConnectCalls { get; private set; }
|
|
||||||
// public bool Reconnecting { get; set; }
|
|
||||||
// public string Origin { get; set; }
|
|
||||||
// public int? RatelimitPerSecond { get; set; }
|
|
||||||
|
|
||||||
// public double IncomingKbps => throw new NotImplementedException();
|
|
||||||
|
|
||||||
// public Uri Uri => new Uri("");
|
|
||||||
|
|
||||||
// public TimeSpan KeepAliveInterval { get; set; }
|
|
||||||
|
|
||||||
// public static int lastId = 0;
|
|
||||||
// public static object lastIdLock = new object();
|
|
||||||
|
|
||||||
// public TestSocket()
|
|
||||||
// {
|
|
||||||
// lock (lastIdLock)
|
|
||||||
// {
|
|
||||||
// Id = lastId + 1;
|
|
||||||
// lastId++;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public Task<CallResult> ConnectAsync()
|
|
||||||
// {
|
|
||||||
// Connected = CanConnect;
|
|
||||||
// ConnectCalls++;
|
|
||||||
// if (CanConnect)
|
|
||||||
// InvokeOpen();
|
|
||||||
// return Task.FromResult(CanConnect ? new CallResult(null) : new CallResult(new CantConnectError()));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public bool Send(int requestId, string data, int weight)
|
|
||||||
// {
|
|
||||||
// if(!Connected)
|
|
||||||
// throw new Exception("Socket not connected");
|
|
||||||
// OnRequestSent?.Invoke(requestId);
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public void Reset()
|
|
||||||
// {
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public Task CloseAsync()
|
|
||||||
// {
|
|
||||||
// Connected = false;
|
|
||||||
// DisconnectTime = DateTime.UtcNow;
|
|
||||||
// OnClose?.Invoke();
|
|
||||||
// return Task.FromResult(0);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public void SetProxy(string host, int port)
|
|
||||||
// {
|
|
||||||
// throw new NotImplementedException();
|
|
||||||
// }
|
|
||||||
// public void Dispose()
|
|
||||||
// {
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public void InvokeClose()
|
|
||||||
// {
|
|
||||||
// Connected = false;
|
|
||||||
// DisconnectTime = DateTime.UtcNow;
|
|
||||||
// Reconnecting = true;
|
|
||||||
// OnClose?.Invoke();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public void InvokeOpen()
|
|
||||||
// {
|
|
||||||
// OnOpen?.Invoke();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public void InvokeMessage(string data)
|
|
||||||
// {
|
|
||||||
// OnStreamMessage?.Invoke(WebSocketMessageType.Text, new ReadOnlyMemory<byte>(Encoding.UTF8.GetBytes(data))).Wait();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public void SetProxy(ApiProxy proxy)
|
|
||||||
// {
|
|
||||||
// throw new NotImplementedException();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public void InvokeError(Exception error)
|
|
||||||
// {
|
|
||||||
// OnError?.Invoke(error);
|
|
||||||
// }
|
|
||||||
// public Task ReconnectAsync() => Task.CompletedTask;
|
|
||||||
// }
|
|
||||||
//}
|
|
@ -7,6 +7,7 @@ indent_style = space
|
|||||||
indent_size = 4
|
indent_size = 4
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
charset = utf-8
|
charset = utf-8
|
||||||
|
max_line_length = 140
|
||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
|
|
||||||
# ReSharper code style properties
|
# ReSharper code style properties
|
||||||
|
@ -465,7 +465,11 @@ public abstract class AuthenticationProvider
|
|||||||
public abstract class AuthenticationProvider<TApiCredentials> : AuthenticationProvider where TApiCredentials : ApiCredentials
|
public abstract class AuthenticationProvider<TApiCredentials> : AuthenticationProvider where TApiCredentials : ApiCredentials
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
#pragma warning disable IDE1006 // Naming Styles
|
||||||
|
#pragma warning disable CA1707 // Naming Styles
|
||||||
protected new TApiCredentials _credentials => (TApiCredentials)base._credentials;
|
protected new TApiCredentials _credentials => (TApiCredentials)base._credentials;
|
||||||
|
#pragma warning restore IDE1006 // Naming Styles
|
||||||
|
#pragma warning restore CA1707 // Naming Styles
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ctor
|
/// ctor
|
||||||
|
@ -124,7 +124,16 @@ public abstract class BaseApiClient : IDisposable, IBaseApiClient
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Dispose
|
/// Dispose
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void Dispose()
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Dispose
|
||||||
|
/// </summary>
|
||||||
|
public virtual void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
_disposing = true;
|
_disposing = true;
|
||||||
}
|
}
|
||||||
|
@ -119,10 +119,24 @@ public abstract class BaseClient : IDisposable
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Dispose
|
/// Dispose
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_logger.Log(LogLevel.Debug, "Disposing client");
|
Dispose(true);
|
||||||
foreach (var client in ApiClients)
|
GC.SuppressFinalize(this);
|
||||||
client.Dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Dispose
|
||||||
|
/// </summary>
|
||||||
|
public virtual void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
_logger.Log(LogLevel.Debug, "Disposing client");
|
||||||
|
foreach (var client in ApiClients)
|
||||||
|
client.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -56,11 +56,23 @@ public class CryptoBaseClient : IDisposable
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Dispose
|
||||||
|
/// </summary>
|
||||||
|
public void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
_serviceCache.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Dispose
|
/// Dispose
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_serviceCache.Clear();
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -839,8 +839,11 @@ public abstract class SocketApiClient : BaseApiClient, ISocketApiClient
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Dispose the client
|
/// Dispose the client
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public override void Dispose()
|
public override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
|
if (disposing)
|
||||||
|
return;
|
||||||
|
|
||||||
_disposing = true;
|
_disposing = true;
|
||||||
var tasks = new List<Task>();
|
var tasks = new List<Task>();
|
||||||
{
|
{
|
||||||
@ -855,7 +858,7 @@ public abstract class SocketApiClient : BaseApiClient, ISocketApiClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
semaphoreSlim?.Dispose();
|
semaphoreSlim?.Dispose();
|
||||||
base.Dispose();
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -118,6 +118,18 @@ public class AsyncResetEvent : IDisposable
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_waits.Clear();
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Dispose
|
||||||
|
/// </summary>
|
||||||
|
public void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
_waits.Clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,95 +1,94 @@
|
|||||||
using CryptoExchange.Net.RateLimiting.Interfaces;
|
using CryptoExchange.Net.RateLimiting.Interfaces;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
|
||||||
namespace CryptoExchange.Net.Objects
|
namespace CryptoExchange.Net.Objects;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The definition of a rest request
|
||||||
|
/// </summary>
|
||||||
|
public class RequestDefinition
|
||||||
{
|
{
|
||||||
|
private string? _stringRep;
|
||||||
|
|
||||||
|
// Basics
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The definition of a rest request
|
/// Path of the request
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class RequestDefinition
|
public string Path { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Http method of the request
|
||||||
|
/// </summary>
|
||||||
|
public HttpMethod Method { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Is the request authenticated
|
||||||
|
/// </summary>
|
||||||
|
public bool Authenticated { get; set; }
|
||||||
|
|
||||||
|
// Formatting
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The body format for this request
|
||||||
|
/// </summary>
|
||||||
|
public RequestBodyFormat? RequestBodyFormat { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// The position of parameters for this request
|
||||||
|
/// </summary>
|
||||||
|
public HttpMethodParameterPosition? ParameterPosition { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// The array serialization type for this request
|
||||||
|
/// </summary>
|
||||||
|
public ArrayParametersSerialization? ArraySerialization { get; set; }
|
||||||
|
|
||||||
|
// Rate limiting
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Request weight
|
||||||
|
/// </summary>
|
||||||
|
public int Weight { get; set; } = 1;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Rate limit gate to use
|
||||||
|
/// </summary>
|
||||||
|
public IRateLimitGate? RateLimitGate { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Individual endpoint rate limit guard to use
|
||||||
|
/// </summary>
|
||||||
|
public IRateLimitGuard? LimitGuard { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether this request should never be cached
|
||||||
|
/// </summary>
|
||||||
|
public bool PreventCaching { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether the response to this requests should attempted to be parsed even when the status indicates failure
|
||||||
|
/// </summary>
|
||||||
|
public bool TryParseOnNonSuccess { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Connection id
|
||||||
|
/// </summary>
|
||||||
|
public int? ConnectionId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ctor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path"></param>
|
||||||
|
/// <param name="method"></param>
|
||||||
|
public RequestDefinition(string path, HttpMethod method)
|
||||||
{
|
{
|
||||||
private string? _stringRep;
|
Path = path;
|
||||||
|
Method = method;
|
||||||
|
|
||||||
// Basics
|
if (!Path.StartsWith("/"))
|
||||||
|
Path = $"/{Path}";
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc />
|
||||||
/// Path of the request
|
public override string ToString()
|
||||||
/// </summary>
|
{
|
||||||
public string Path { get; set; }
|
return _stringRep ??= $"{Method} {Path}{(Authenticated ? " authenticated" : "")}";
|
||||||
/// <summary>
|
|
||||||
/// Http method of the request
|
|
||||||
/// </summary>
|
|
||||||
public HttpMethod Method { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Is the request authenticated
|
|
||||||
/// </summary>
|
|
||||||
public bool Authenticated { get; set; }
|
|
||||||
|
|
||||||
// Formatting
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The body format for this request
|
|
||||||
/// </summary>
|
|
||||||
public RequestBodyFormat? RequestBodyFormat { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// The position of parameters for this request
|
|
||||||
/// </summary>
|
|
||||||
public HttpMethodParameterPosition? ParameterPosition { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// The array serialization type for this request
|
|
||||||
/// </summary>
|
|
||||||
public ArrayParametersSerialization? ArraySerialization { get; set; }
|
|
||||||
|
|
||||||
// Rate limiting
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Request weight
|
|
||||||
/// </summary>
|
|
||||||
public int Weight { get; set; } = 1;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Rate limit gate to use
|
|
||||||
/// </summary>
|
|
||||||
public IRateLimitGate? RateLimitGate { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Individual endpoint rate limit guard to use
|
|
||||||
/// </summary>
|
|
||||||
public IRateLimitGuard? LimitGuard { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether this request should never be cached
|
|
||||||
/// </summary>
|
|
||||||
public bool PreventCaching { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether the response to this requests should attempted to be parsed even when the status indicates failure
|
|
||||||
/// </summary>
|
|
||||||
public bool TryParseOnNonSuccess { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Connection id
|
|
||||||
/// </summary>
|
|
||||||
public int? ConnectionId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// ctor
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="path"></param>
|
|
||||||
/// <param name="method"></param>
|
|
||||||
public RequestDefinition(string path, HttpMethod method)
|
|
||||||
{
|
|
||||||
Path = path;
|
|
||||||
Method = method;
|
|
||||||
|
|
||||||
if (!Path.StartsWith("/"))
|
|
||||||
Path = $"/{Path}";
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return _stringRep ??= $"{Method} {Path}{(Authenticated ? " authenticated" : "")}";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,116 +1,115 @@
|
|||||||
using CryptoExchange.Net.RateLimiting.Interfaces;
|
using CryptoExchange.Net.RateLimiting.Interfaces;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
|
||||||
namespace CryptoExchange.Net.Objects
|
namespace CryptoExchange.Net.Objects;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Request definitions cache
|
||||||
|
/// </summary>
|
||||||
|
public class RequestDefinitionCache
|
||||||
{
|
{
|
||||||
|
private readonly ConcurrentDictionary<string, RequestDefinition> _definitions = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Request definitions cache
|
/// Get a definition if it is already in the cache or create a new definition and add it to the cache
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class RequestDefinitionCache
|
/// <param name="method">The HttpMethod</param>
|
||||||
|
/// <param name="path">Endpoint path</param>
|
||||||
|
/// <param name="authenticated">Endpoint is authenticated</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public RequestDefinition GetOrCreate(HttpMethod method, string path, bool authenticated = false)
|
||||||
|
=> GetOrCreate(method, path, null, 0, authenticated, null, null, null, null, null);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get a definition if it is already in the cache or create a new definition and add it to the cache
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="method">The HttpMethod</param>
|
||||||
|
/// <param name="path">Endpoint path</param>
|
||||||
|
/// <param name="rateLimitGate">The rate limit gate</param>
|
||||||
|
/// <param name="weight">Request weight</param>
|
||||||
|
/// <param name="authenticated">Endpoint is authenticated</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public RequestDefinition GetOrCreate(HttpMethod method, string path, IRateLimitGate rateLimitGate, int weight = 1, bool authenticated = false)
|
||||||
|
=> GetOrCreate(method, path, rateLimitGate, weight, authenticated, null, null, null, null, null);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get a definition if it is already in the cache or create a new definition and add it to the cache
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="method">The HttpMethod</param>
|
||||||
|
/// <param name="path">Endpoint path</param>
|
||||||
|
/// <param name="rateLimitGate">The rate limit gate</param>
|
||||||
|
/// <param name="limitGuard">The rate limit guard for this specific endpoint</param>
|
||||||
|
/// <param name="weight">Request weight</param>
|
||||||
|
/// <param name="authenticated">Endpoint is authenticated</param>
|
||||||
|
/// <param name="requestBodyFormat">Request body format</param>
|
||||||
|
/// <param name="parameterPosition">Parameter position</param>
|
||||||
|
/// <param name="arraySerialization">Array serialization type</param>
|
||||||
|
/// <param name="preventCaching">Prevent request caching</param>
|
||||||
|
/// <param name="tryParseOnNonSuccess">Try parse the response even when status is not success</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public RequestDefinition GetOrCreate(
|
||||||
|
HttpMethod method,
|
||||||
|
string path,
|
||||||
|
IRateLimitGate? rateLimitGate,
|
||||||
|
int weight,
|
||||||
|
bool authenticated,
|
||||||
|
IRateLimitGuard? limitGuard = null,
|
||||||
|
RequestBodyFormat? requestBodyFormat = null,
|
||||||
|
HttpMethodParameterPosition? parameterPosition = null,
|
||||||
|
ArrayParametersSerialization? arraySerialization = null,
|
||||||
|
bool? preventCaching = null,
|
||||||
|
bool? tryParseOnNonSuccess = null)
|
||||||
|
=> GetOrCreate(method + path, method, path, rateLimitGate, weight, authenticated, limitGuard, requestBodyFormat, parameterPosition, arraySerialization, preventCaching, tryParseOnNonSuccess);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get a definition if it is already in the cache or create a new definition and add it to the cache
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="identifier">Request identifier</param>
|
||||||
|
/// <param name="method">The HttpMethod</param>
|
||||||
|
/// <param name="path">Endpoint path</param>
|
||||||
|
/// <param name="rateLimitGate">The rate limit gate</param>
|
||||||
|
/// <param name="limitGuard">The rate limit guard for this specific endpoint</param>
|
||||||
|
/// <param name="weight">Request weight</param>
|
||||||
|
/// <param name="authenticated">Endpoint is authenticated</param>
|
||||||
|
/// <param name="requestBodyFormat">Request body format</param>
|
||||||
|
/// <param name="parameterPosition">Parameter position</param>
|
||||||
|
/// <param name="arraySerialization">Array serialization type</param>
|
||||||
|
/// <param name="preventCaching">Prevent request caching</param>
|
||||||
|
/// <param name="tryParseOnNonSuccess">Try parse the response even when status is not success</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public RequestDefinition GetOrCreate(
|
||||||
|
string identifier,
|
||||||
|
HttpMethod method,
|
||||||
|
string path,
|
||||||
|
IRateLimitGate? rateLimitGate,
|
||||||
|
int weight,
|
||||||
|
bool authenticated,
|
||||||
|
IRateLimitGuard? limitGuard = null,
|
||||||
|
RequestBodyFormat? requestBodyFormat = null,
|
||||||
|
HttpMethodParameterPosition? parameterPosition = null,
|
||||||
|
ArrayParametersSerialization? arraySerialization = null,
|
||||||
|
bool? preventCaching = null,
|
||||||
|
bool? tryParseOnNonSuccess = null)
|
||||||
{
|
{
|
||||||
private readonly ConcurrentDictionary<string, RequestDefinition> _definitions = new();
|
|
||||||
|
|
||||||
/// <summary>
|
if (!_definitions.TryGetValue(identifier, out var def))
|
||||||
/// Get a definition if it is already in the cache or create a new definition and add it to the cache
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="method">The HttpMethod</param>
|
|
||||||
/// <param name="path">Endpoint path</param>
|
|
||||||
/// <param name="authenticated">Endpoint is authenticated</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public RequestDefinition GetOrCreate(HttpMethod method, string path, bool authenticated = false)
|
|
||||||
=> GetOrCreate(method, path, null, 0, authenticated, null, null, null, null, null);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get a definition if it is already in the cache or create a new definition and add it to the cache
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="method">The HttpMethod</param>
|
|
||||||
/// <param name="path">Endpoint path</param>
|
|
||||||
/// <param name="rateLimitGate">The rate limit gate</param>
|
|
||||||
/// <param name="weight">Request weight</param>
|
|
||||||
/// <param name="authenticated">Endpoint is authenticated</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public RequestDefinition GetOrCreate(HttpMethod method, string path, IRateLimitGate rateLimitGate, int weight = 1, bool authenticated = false)
|
|
||||||
=> GetOrCreate(method, path, rateLimitGate, weight, authenticated, null, null, null, null, null);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get a definition if it is already in the cache or create a new definition and add it to the cache
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="method">The HttpMethod</param>
|
|
||||||
/// <param name="path">Endpoint path</param>
|
|
||||||
/// <param name="rateLimitGate">The rate limit gate</param>
|
|
||||||
/// <param name="limitGuard">The rate limit guard for this specific endpoint</param>
|
|
||||||
/// <param name="weight">Request weight</param>
|
|
||||||
/// <param name="authenticated">Endpoint is authenticated</param>
|
|
||||||
/// <param name="requestBodyFormat">Request body format</param>
|
|
||||||
/// <param name="parameterPosition">Parameter position</param>
|
|
||||||
/// <param name="arraySerialization">Array serialization type</param>
|
|
||||||
/// <param name="preventCaching">Prevent request caching</param>
|
|
||||||
/// <param name="tryParseOnNonSuccess">Try parse the response even when status is not success</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public RequestDefinition GetOrCreate(
|
|
||||||
HttpMethod method,
|
|
||||||
string path,
|
|
||||||
IRateLimitGate? rateLimitGate,
|
|
||||||
int weight,
|
|
||||||
bool authenticated,
|
|
||||||
IRateLimitGuard? limitGuard = null,
|
|
||||||
RequestBodyFormat? requestBodyFormat = null,
|
|
||||||
HttpMethodParameterPosition? parameterPosition = null,
|
|
||||||
ArrayParametersSerialization? arraySerialization = null,
|
|
||||||
bool? preventCaching = null,
|
|
||||||
bool? tryParseOnNonSuccess = null)
|
|
||||||
=> GetOrCreate(method + path, method, path, rateLimitGate, weight, authenticated, limitGuard, requestBodyFormat, parameterPosition, arraySerialization, preventCaching, tryParseOnNonSuccess);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get a definition if it is already in the cache or create a new definition and add it to the cache
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="identifier">Request identifier</param>
|
|
||||||
/// <param name="method">The HttpMethod</param>
|
|
||||||
/// <param name="path">Endpoint path</param>
|
|
||||||
/// <param name="rateLimitGate">The rate limit gate</param>
|
|
||||||
/// <param name="limitGuard">The rate limit guard for this specific endpoint</param>
|
|
||||||
/// <param name="weight">Request weight</param>
|
|
||||||
/// <param name="authenticated">Endpoint is authenticated</param>
|
|
||||||
/// <param name="requestBodyFormat">Request body format</param>
|
|
||||||
/// <param name="parameterPosition">Parameter position</param>
|
|
||||||
/// <param name="arraySerialization">Array serialization type</param>
|
|
||||||
/// <param name="preventCaching">Prevent request caching</param>
|
|
||||||
/// <param name="tryParseOnNonSuccess">Try parse the response even when status is not success</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public RequestDefinition GetOrCreate(
|
|
||||||
string identifier,
|
|
||||||
HttpMethod method,
|
|
||||||
string path,
|
|
||||||
IRateLimitGate? rateLimitGate,
|
|
||||||
int weight,
|
|
||||||
bool authenticated,
|
|
||||||
IRateLimitGuard? limitGuard = null,
|
|
||||||
RequestBodyFormat? requestBodyFormat = null,
|
|
||||||
HttpMethodParameterPosition? parameterPosition = null,
|
|
||||||
ArrayParametersSerialization? arraySerialization = null,
|
|
||||||
bool? preventCaching = null,
|
|
||||||
bool? tryParseOnNonSuccess = null)
|
|
||||||
{
|
{
|
||||||
|
def = new RequestDefinition(path, method)
|
||||||
if (!_definitions.TryGetValue(identifier, out var def))
|
|
||||||
{
|
{
|
||||||
def = new RequestDefinition(path, method)
|
Authenticated = authenticated,
|
||||||
{
|
LimitGuard = limitGuard,
|
||||||
Authenticated = authenticated,
|
RateLimitGate = rateLimitGate,
|
||||||
LimitGuard = limitGuard,
|
Weight = weight,
|
||||||
RateLimitGate = rateLimitGate,
|
ArraySerialization = arraySerialization,
|
||||||
Weight = weight,
|
RequestBodyFormat = requestBodyFormat,
|
||||||
ArraySerialization = arraySerialization,
|
ParameterPosition = parameterPosition,
|
||||||
RequestBodyFormat = requestBodyFormat,
|
PreventCaching = preventCaching ?? false,
|
||||||
ParameterPosition = parameterPosition,
|
TryParseOnNonSuccess = tryParseOnNonSuccess ?? false
|
||||||
PreventCaching = preventCaching ?? false,
|
};
|
||||||
TryParseOnNonSuccess = tryParseOnNonSuccess ?? false
|
_definitions.TryAdd(identifier, def);
|
||||||
};
|
|
||||||
_definitions.TryAdd(identifier, def);
|
|
||||||
}
|
|
||||||
|
|
||||||
return def;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return def;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,22 @@ public class TraceLoggerProvider : ILoggerProvider
|
|||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public ILogger CreateLogger(string categoryName) => new TraceLogger(categoryName, _logLevel);
|
public ILogger CreateLogger(string categoryName) => new TraceLogger(categoryName, _logLevel);
|
||||||
/// <inheritdoc />
|
|
||||||
public void Dispose() { }
|
/// <summary>
|
||||||
|
/// Dispose
|
||||||
|
/// </summary>
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Dispose
|
||||||
|
/// </summary>
|
||||||
|
public static void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -578,21 +578,24 @@ public abstract class SymbolOrderBook : ISymbolOrderBook, IDisposable
|
|||||||
/// <param name="disposing"></param>
|
/// <param name="disposing"></param>
|
||||||
protected virtual void Dispose(bool disposing)
|
protected virtual void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
Status = OrderBookStatus.Disposing;
|
if (disposing)
|
||||||
|
{
|
||||||
|
Status = OrderBookStatus.Disposing;
|
||||||
|
|
||||||
_cts?.Cancel();
|
_cts?.Cancel();
|
||||||
_queueEvent.Set();
|
_queueEvent.Set();
|
||||||
|
|
||||||
// Clear queue
|
// Clear queue
|
||||||
while (_processQueue.TryDequeue(out _)) { }
|
while (_processQueue.TryDequeue(out _)) { }
|
||||||
|
|
||||||
_processBuffer.Clear();
|
_processBuffer.Clear();
|
||||||
_asks.Clear();
|
_asks.Clear();
|
||||||
_bids.Clear();
|
_bids.Clear();
|
||||||
AskCount = 0;
|
AskCount = 0;
|
||||||
BidCount = 0;
|
BidCount = 0;
|
||||||
|
|
||||||
Status = OrderBookStatus.Disposed;
|
Status = OrderBookStatus.Disposed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -488,9 +488,18 @@ public class CryptoExchangeWebSocketClient : IWebsocket
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Dispose the socket
|
/// Dispose
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Dispose the socket
|
||||||
|
/// </summary>
|
||||||
|
public void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (_disposed)
|
if (_disposed)
|
||||||
return;
|
return;
|
||||||
|
@ -169,7 +169,6 @@ public abstract class Query : IMessageProcessor, IDisposable
|
|||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
// TODO: dispose managed state (managed objects)
|
|
||||||
_cts?.Dispose();
|
_cts?.Dispose();
|
||||||
_event.Dispose();
|
_event.Dispose();
|
||||||
}
|
}
|
||||||
|
@ -709,14 +709,29 @@ public class SocketConnection : IDisposable
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Dispose the connection
|
/// Dispose
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (Status != SocketStatus.Disposed)
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
Status = SocketStatus.Disposed;
|
||||||
|
periodicEvent?.Set();
|
||||||
|
periodicEvent?.Dispose();
|
||||||
|
_socket.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Dispose
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
Status = SocketStatus.Disposed;
|
Dispose(disposing: true);
|
||||||
periodicEvent?.Set();
|
GC.SuppressFinalize(this);
|
||||||
periodicEvent?.Dispose();
|
|
||||||
_socket.Dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -23,6 +23,8 @@ public class RestRequestValidator<TClient> where TClient : BaseRestClient
|
|||||||
private readonly string _baseAddress;
|
private readonly string _baseAddress;
|
||||||
private readonly string? _nestedPropertyForCompare;
|
private readonly string? _nestedPropertyForCompare;
|
||||||
|
|
||||||
|
private static readonly char[] _paramSeparator = new char[] { '?' };
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ctor
|
/// ctor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -117,8 +119,8 @@ public class RestRequestValidator<TClient> where TClient : BaseRestClient
|
|||||||
throw new Exception(name + $" authentication not matched. Expected: {expectedAuth}, Actual: {_isAuthenticated(result.AsDataless())}");
|
throw new Exception(name + $" authentication not matched. Expected: {expectedAuth}, Actual: {_isAuthenticated(result.AsDataless())}");
|
||||||
if (result.RequestMethod != new HttpMethod(expectedMethod!))
|
if (result.RequestMethod != new HttpMethod(expectedMethod!))
|
||||||
throw new Exception(name + $" http method not matched. Expected {expectedMethod}, Actual: {result.RequestMethod}");
|
throw new Exception(name + $" http method not matched. Expected {expectedMethod}, Actual: {result.RequestMethod}");
|
||||||
if (expectedPath != result.RequestUrl!.Replace(_baseAddress, "").Split(new char[] { '?' })[0])
|
if (expectedPath != result.RequestUrl!.Replace(_baseAddress, "").Split(_paramSeparator)[0])
|
||||||
throw new Exception(name + $" path not matched. Expected: {expectedPath}, Actual: {result.RequestUrl!.Replace(_baseAddress, "").Split(new char[] { '?' })[0]}");
|
throw new Exception(name + $" path not matched. Expected: {expectedPath}, Actual: {result.RequestUrl!.Replace(_baseAddress, "").Split(_paramSeparator)[0]}");
|
||||||
|
|
||||||
if (!skipResponseValidation)
|
if (!skipResponseValidation)
|
||||||
{
|
{
|
||||||
@ -176,8 +178,8 @@ public class RestRequestValidator<TClient> where TClient : BaseRestClient
|
|||||||
throw new Exception(name + $" authentication not matched. Expected: {expectedAuth}, Actual: {_isAuthenticated(result)}");
|
throw new Exception(name + $" authentication not matched. Expected: {expectedAuth}, Actual: {_isAuthenticated(result)}");
|
||||||
if (result.RequestMethod != new HttpMethod(expectedMethod!))
|
if (result.RequestMethod != new HttpMethod(expectedMethod!))
|
||||||
throw new Exception(name + $" http method not matched. Expected {expectedMethod}, Actual: {result.RequestMethod}");
|
throw new Exception(name + $" http method not matched. Expected {expectedMethod}, Actual: {result.RequestMethod}");
|
||||||
if (expectedPath != result.RequestUrl!.Replace(_baseAddress, "").Split(new char[] { '?' })[0])
|
if (expectedPath != result.RequestUrl!.Replace(_baseAddress, "").Split(_paramSeparator)[0])
|
||||||
throw new Exception(name + $" path not matched. Expected: {expectedPath}, Actual: {result.RequestUrl!.Replace(_baseAddress, "").Split(new char[] { '?' })[0]}");
|
throw new Exception(name + $" path not matched. Expected: {expectedPath}, Actual: {result.RequestUrl!.Replace(_baseAddress, "").Split(_paramSeparator)[0]}");
|
||||||
|
|
||||||
Trace.Listeners.Remove(listener);
|
Trace.Listeners.Remove(listener);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user