diff --git a/CryptoExchange.Net/BaseClient.cs b/CryptoExchange.Net/BaseClient.cs
index 3af741d..7460bb5 100644
--- a/CryptoExchange.Net/BaseClient.cs
+++ b/CryptoExchange.Net/BaseClient.cs
@@ -1,16 +1,12 @@
-using CryptoExchange.Net.Attributes;
-using CryptoExchange.Net.Authentication;
+using CryptoExchange.Net.Authentication;
using CryptoExchange.Net.Logging;
using CryptoExchange.Net.Objects;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
-using System.Collections.Generic;
using System.Globalization;
using System.IO;
-using System.Linq;
-using System.Reflection;
using System.Text;
using System.Threading.Tasks;
@@ -152,8 +148,7 @@ namespace CryptoExchange.Net
///
protected CallResult Deserialize(JToken obj, JsonSerializer? serializer = null, int? requestId = null)
{
- if (serializer == null)
- serializer = defaultSerializer;
+ serializer ??= defaultSerializer;
try
{
@@ -191,8 +186,7 @@ namespace CryptoExchange.Net
///
protected async Task> DeserializeAsync(Stream stream, JsonSerializer? serializer = null, int? requestId = null, long? elapsedMilliseconds = null)
{
- if (serializer == null)
- serializer = defaultSerializer;
+ serializer ??= defaultSerializer;
try
{
diff --git a/CryptoExchange.Net/Converters/ArrayConverter.cs b/CryptoExchange.Net/Converters/ArrayConverter.cs
index b196fd0..26a17bd 100644
--- a/CryptoExchange.Net/Converters/ArrayConverter.cs
+++ b/CryptoExchange.Net/Converters/ArrayConverter.cs
@@ -36,7 +36,7 @@ namespace CryptoExchange.Net.Converters
return ParseObject(arr, result, objectType);
}
- private static object? ParseObject(JArray arr, object result, Type objectType)
+ private static object ParseObject(JArray arr, object result, Type objectType)
{
foreach (var property in objectType.GetProperties())
{
@@ -63,8 +63,8 @@ namespace CryptoExchange.Net.Converters
var arrayResult = (IList)Activator.CreateInstance(property.PropertyType, new [] { innerArray.Count });
foreach (var obj in innerArray)
{
- var innerObj = Activator.CreateInstance(objType);
- arrayResult[count] = ParseObject((JArray)obj, innerObj, objType);
+ var innerObj = Activator.CreateInstance(objType!);
+ arrayResult[count] = ParseObject((JArray)obj, innerObj, objType!);
count++;
}
property.SetValue(result, arrayResult);
@@ -72,8 +72,8 @@ namespace CryptoExchange.Net.Converters
else
{
var arrayResult = (IList)Activator.CreateInstance(property.PropertyType, new [] { 1 });
- var innerObj = Activator.CreateInstance(objType);
- arrayResult[0] = ParseObject(innerArray, innerObj, objType);
+ var innerObj = Activator.CreateInstance(objType!);
+ arrayResult[0] = ParseObject(innerArray, innerObj, objType!);
property.SetValue(result, arrayResult);
}
continue;
diff --git a/CryptoExchange.Net/ExtensionMethods.cs b/CryptoExchange.Net/ExtensionMethods.cs
index 2055978..2a19126 100644
--- a/CryptoExchange.Net/ExtensionMethods.cs
+++ b/CryptoExchange.Net/ExtensionMethods.cs
@@ -5,8 +5,6 @@ using System.Linq;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
using CryptoExchange.Net.Logging;
using CryptoExchange.Net.Objects;
using Microsoft.Extensions.Logging;
@@ -333,7 +331,7 @@ namespace CryptoExchange.Net
///
///
///
- public static string ToLogString(this Exception exception)
+ public static string ToLogString(this Exception? exception)
{
var message = new StringBuilder();
var indent = 0;
diff --git a/CryptoExchange.Net/Interfaces/IRateLimiter.cs b/CryptoExchange.Net/Interfaces/IRateLimiter.cs
index f5b3361..5b6f830 100644
--- a/CryptoExchange.Net/Interfaces/IRateLimiter.cs
+++ b/CryptoExchange.Net/Interfaces/IRateLimiter.cs
@@ -1,6 +1,5 @@
using CryptoExchange.Net.Logging;
using CryptoExchange.Net.Objects;
-using System;
using System.Net.Http;
using System.Security;
using System.Threading;
diff --git a/CryptoExchange.Net/Interfaces/IRestClient.cs b/CryptoExchange.Net/Interfaces/IRestClient.cs
index 015c6f5..e235f62 100644
--- a/CryptoExchange.Net/Interfaces/IRestClient.cs
+++ b/CryptoExchange.Net/Interfaces/IRestClient.cs
@@ -1,7 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Threading;
-using System.Threading.Tasks;
using CryptoExchange.Net.Objects;
namespace CryptoExchange.Net.Interfaces
@@ -21,17 +18,6 @@ namespace CryptoExchange.Net.Interfaces
///
int TotalRequestsMade { get; }
- ///
- /// Adds a rate limiter to the client. There are 2 choices, the and the .
- ///
- /// The limiter to add
- void AddRateLimiter(IRateLimiter limiter);
-
- ///
- /// Removes all rate limiters from this client
- ///
- void RemoveRateLimiters();
-
///
/// The options provided for this client
///
diff --git a/CryptoExchange.Net/Objects/AsyncAutoResetEvent.cs b/CryptoExchange.Net/Objects/AsyncAutoResetEvent.cs
index 2daddd7..e6ac1d9 100644
--- a/CryptoExchange.Net/Objects/AsyncAutoResetEvent.cs
+++ b/CryptoExchange.Net/Objects/AsyncAutoResetEvent.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
@@ -12,10 +11,10 @@ namespace CryptoExchange.Net.Objects
///
public class AsyncResetEvent : IDisposable
{
- private readonly static Task _completed = Task.FromResult(true);
+ private static readonly Task _completed = Task.FromResult(true);
private readonly Queue> _waits = new Queue>();
private bool _signaled;
- private bool _reset;
+ private readonly bool _reset;
///
/// New AsyncResetEvent
diff --git a/CryptoExchange.Net/Objects/RateLimiter.cs b/CryptoExchange.Net/Objects/RateLimiter.cs
index 420f413..dc0b4e8 100644
--- a/CryptoExchange.Net/Objects/RateLimiter.cs
+++ b/CryptoExchange.Net/Objects/RateLimiter.cs
@@ -1,6 +1,5 @@
using CryptoExchange.Net.Interfaces;
using CryptoExchange.Net.Logging;
-using CryptoExchange.Net.Objects;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
@@ -106,7 +105,7 @@ namespace CryptoExchange.Net.Objects
{
int totalWaitTime = 0;
- EndpointRateLimiter endpointLimit;
+ EndpointRateLimiter? endpointLimit;
lock (_limiterLock)
endpointLimit = Limiters.OfType().SingleOrDefault(h => h.Endpoints.Contains(endpoint) && (h.Method == null || h.Method == method));
if(endpointLimit != null)
@@ -128,7 +127,7 @@ namespace CryptoExchange.Net.Objects
{
if (partialEndpointLimit.CountPerEndpoint)
{
- SingleTopicRateLimiter thisEndpointLimit;
+ SingleTopicRateLimiter? thisEndpointLimit;
lock (_limiterLock)
{
thisEndpointLimit = Limiters.OfType().SingleOrDefault(h => h.Type == RateLimitType.PartialEndpoint && (string)h.Topic == endpoint);
@@ -158,7 +157,7 @@ namespace CryptoExchange.Net.Objects
if(partialEndpointLimits.Any(p => p.IgnoreOtherRateLimits))
return new CallResult(totalWaitTime, null);
- ApiKeyRateLimiter apiLimit;
+ ApiKeyRateLimiter? apiLimit;
lock (_limiterLock)
apiLimit = Limiters.OfType().SingleOrDefault(h => h.Type == RateLimitType.ApiKey);
if (apiLimit != null)
@@ -176,7 +175,7 @@ namespace CryptoExchange.Net.Objects
}
else if (signed || !apiLimit.OnlyForSignedRequests)
{
- SingleTopicRateLimiter thisApiLimit;
+ SingleTopicRateLimiter? thisApiLimit;
lock (_limiterLock)
{
thisApiLimit = Limiters.OfType().SingleOrDefault(h => h.Type == RateLimitType.ApiKey && ((SecureString)h.Topic).IsEqualTo(apiKey));
@@ -198,7 +197,7 @@ namespace CryptoExchange.Net.Objects
if ((signed || apiLimit?.OnlyForSignedRequests == false) && apiLimit?.IgnoreTotalRateLimit == true)
return new CallResult(totalWaitTime, null);
- TotalRateLimiter totalLimit;
+ TotalRateLimiter? totalLimit;
lock (_limiterLock)
totalLimit = Limiters.OfType().SingleOrDefault();
if (totalLimit != null)
diff --git a/CryptoExchange.Net/OrderBook/SymbolOrderBook.cs b/CryptoExchange.Net/OrderBook/SymbolOrderBook.cs
index a7f1e29..1a10689 100644
--- a/CryptoExchange.Net/OrderBook/SymbolOrderBook.cs
+++ b/CryptoExchange.Net/OrderBook/SymbolOrderBook.cs
@@ -18,22 +18,24 @@ namespace CryptoExchange.Net.OrderBook
///
public abstract class SymbolOrderBook : ISymbolOrderBook, IDisposable
{
- private readonly object bookLock = new object();
+ private readonly object _bookLock = new object();
- private OrderBookStatus status;
- private UpdateSubscription? subscription;
+ private OrderBookStatus _status;
+ private UpdateSubscription? _subscription;
private bool _stopProcessing;
private Task? _processTask;
private readonly AutoResetEvent _queueEvent;
private readonly ConcurrentQueue