From 53254e8d0fcb091a3a3221d627538b3015af3195 Mon Sep 17 00:00:00 2001 From: Jan Korf Date: Tue, 9 Apr 2019 10:08:14 +0200 Subject: [PATCH] Added interfaces to base class so they implement IDisposable --- CryptoExchange.Net/CryptoExchange.Net.csproj | 2 +- CryptoExchange.Net/Interfaces/IRestClient.cs | 63 +++++++++++++++++++ .../Interfaces/ISocketClient.cs | 45 +++++++++++++ CryptoExchange.Net/SocketClient.cs | 2 +- 4 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 CryptoExchange.Net/Interfaces/IRestClient.cs create mode 100644 CryptoExchange.Net/Interfaces/ISocketClient.cs diff --git a/CryptoExchange.Net/CryptoExchange.Net.csproj b/CryptoExchange.Net/CryptoExchange.Net.csproj index 16c2ecb..1ea6196 100644 --- a/CryptoExchange.Net/CryptoExchange.Net.csproj +++ b/CryptoExchange.Net/CryptoExchange.Net.csproj @@ -7,7 +7,7 @@ CryptoExchange.Net JKorf - 2.0.14 + 2.0.15 false https://github.com/JKorf/CryptoExchange.Net https://github.com/JKorf/CryptoExchange.Net/blob/master/LICENSE diff --git a/CryptoExchange.Net/Interfaces/IRestClient.cs b/CryptoExchange.Net/Interfaces/IRestClient.cs new file mode 100644 index 0000000..b3a8c4b --- /dev/null +++ b/CryptoExchange.Net/Interfaces/IRestClient.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using CryptoExchange.Net.Interfaces; +using CryptoExchange.Net.Objects; +using CryptoExchange.Net.RateLimiter; + +namespace CryptoExchange.Net.Interfaces +{ + /// + /// Base class for rest API implementations + /// + public interface IRestClient: IDisposable + { + /// + /// The factory for creating requests. Used for unit testing + /// + IRequestFactory RequestFactory { get; set; } + + /// + /// What should happen when hitting a rate limit + /// + RateLimitingBehaviour RateLimitBehaviour { get; } + + /// + /// List of active rate limiters + /// + IEnumerable RateLimiters { get; } + + /// + /// The total amount of requests made + /// + int TotalRequestsMade { get; } + + /// + /// The base address of the API + /// + string BaseAddress { 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(); + + /// + /// Ping to see if the server is reachable + /// + /// The roundtrip time of the ping request + CallResult Ping(); + + /// + /// Ping to see if the server is reachable + /// + /// The roundtrip time of the ping request + Task> PingAsync(); + } +} \ No newline at end of file diff --git a/CryptoExchange.Net/Interfaces/ISocketClient.cs b/CryptoExchange.Net/Interfaces/ISocketClient.cs new file mode 100644 index 0000000..195b1ce --- /dev/null +++ b/CryptoExchange.Net/Interfaces/ISocketClient.cs @@ -0,0 +1,45 @@ +using System; +using System.Threading.Tasks; +using CryptoExchange.Net.Sockets; + +namespace CryptoExchange.Net.Interfaces +{ + /// + /// Base class for socket API implementations + /// + public interface ISocketClient: IDisposable + { + /// + /// The factory for creating sockets. Used for unit testing + /// + IWebsocketFactory SocketFactory { get; set; } + + /// + /// The time in between reconnect attempts + /// + TimeSpan ReconnectInterval { get; } + + /// + /// Whether the client should try to auto reconnect when losing connection + /// + bool AutoReconnect { get; } + + /// + /// The base address of the API + /// + string BaseAddress { get; } + + /// + /// Unsubscribe from a stream + /// + /// The subscription to unsubscribe + /// + Task Unsubscribe(UpdateSubscription subscription); + + /// + /// Unsubscribe all subscriptions + /// + /// + Task UnsubscribeAll(); + } +} \ No newline at end of file diff --git a/CryptoExchange.Net/SocketClient.cs b/CryptoExchange.Net/SocketClient.cs index d1342b7..7eb1491 100644 --- a/CryptoExchange.Net/SocketClient.cs +++ b/CryptoExchange.Net/SocketClient.cs @@ -14,7 +14,7 @@ using Newtonsoft.Json.Linq; namespace CryptoExchange.Net { - public abstract class SocketClient: BaseClient + public abstract class SocketClient: BaseClient, ISocketClient { #region fields ///