diff --git a/CryptoExchange.Net.UnitTests/TestImplementations/TestBaseClient.cs b/CryptoExchange.Net.UnitTests/TestImplementations/TestBaseClient.cs index c696169c..3fac0e9c 100644 --- a/CryptoExchange.Net.UnitTests/TestImplementations/TestBaseClient.cs +++ b/CryptoExchange.Net.UnitTests/TestImplementations/TestBaseClient.cs @@ -54,6 +54,8 @@ public CallResult Deserialize(string data) return deserializeResult; } + /// + public override string FormatSymbol(string baseAsset, string quoteAsset) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}"; public override TimeSpan? GetTimeOffset() => null; public override TimeSyncInfo GetTimeSyncInfo() => null; protected override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials) => throw new NotImplementedException(); diff --git a/CryptoExchange.Net.UnitTests/TestImplementations/TestRestClient.cs b/CryptoExchange.Net.UnitTests/TestImplementations/TestRestClient.cs index 1326abfc..1ad9c9f3 100644 --- a/CryptoExchange.Net.UnitTests/TestImplementations/TestRestClient.cs +++ b/CryptoExchange.Net.UnitTests/TestImplementations/TestRestClient.cs @@ -137,6 +137,9 @@ public TestRestApi1Client(TestClientOptions options) : base(new TraceLogger(), n RequestFactory = new Mock().Object; } + /// + public override string FormatSymbol(string baseAsset, string quoteAsset) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}"; + public async Task> Request(CancellationToken ct = default) where T : class { return await SendRequestAsync(new Uri("http://www.test.com"), HttpMethod.Get, ct, requestWeight: 0); @@ -178,6 +181,9 @@ public TestRestApi2Client(TestClientOptions options) : base(new TraceLogger(), n RequestFactory = new Mock().Object; } + /// + public override string FormatSymbol(string baseAsset, string quoteAsset) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}"; + public async Task> Request(CancellationToken ct = default) where T : class { return await SendRequestAsync(new Uri("http://www.test.com"), HttpMethod.Get, ct, requestWeight: 0); diff --git a/CryptoExchange.Net.UnitTests/TestImplementations/TestSocketClient.cs b/CryptoExchange.Net.UnitTests/TestImplementations/TestSocketClient.cs index 1ab342ce..1df46353 100644 --- a/CryptoExchange.Net.UnitTests/TestImplementations/TestSocketClient.cs +++ b/CryptoExchange.Net.UnitTests/TestImplementations/TestSocketClient.cs @@ -84,6 +84,9 @@ public TestSubSocketClient(TestSocketOptions options, SocketApiOptions apiOption } + /// + public override string FormatSymbol(string baseAsset, string quoteAsset) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}"; + internal IWebsocket CreateSocketInternal(string address) { return CreateSocket(address); diff --git a/CryptoExchange.Net/Clients/BaseApiClient.cs b/CryptoExchange.Net/Clients/BaseApiClient.cs index 5f7113da..a377fbdf 100644 --- a/CryptoExchange.Net/Clients/BaseApiClient.cs +++ b/CryptoExchange.Net/Clients/BaseApiClient.cs @@ -78,6 +78,9 @@ protected BaseApiClient(ILogger logger, bool outputOriginalData, ApiCredentials? /// protected abstract AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials); + /// + public abstract string FormatSymbol(string baseAsset, string quoteAsset); + /// public void SetApiCredentials(T credentials) where T : ApiCredentials { diff --git a/CryptoExchange.Net/Interfaces/IBaseApiClient.cs b/CryptoExchange.Net/Interfaces/IBaseApiClient.cs index fea84d57..88bbd73a 100644 --- a/CryptoExchange.Net/Interfaces/IBaseApiClient.cs +++ b/CryptoExchange.Net/Interfaces/IBaseApiClient.cs @@ -12,6 +12,14 @@ public interface IBaseApiClient /// string BaseAddress { get; } + /// + /// Format a base and quote asset to an exchange accepted symbol + /// + /// The base asset + /// The quote asset + /// + string FormatSymbol(string baseAsset, string quoteAsset); + /// /// Set the API credentials for this API client /// diff --git a/CryptoExchange.Net/Interfaces/IOrderBookFactory.cs b/CryptoExchange.Net/Interfaces/IOrderBookFactory.cs new file mode 100644 index 00000000..2ffc9e30 --- /dev/null +++ b/CryptoExchange.Net/Interfaces/IOrderBookFactory.cs @@ -0,0 +1,27 @@ +using CryptoExchange.Net.Objects.Options; +using System; + +namespace CryptoExchange.Net.Interfaces +{ + /// + /// Factory for ISymbolOrderBook instances + /// + public interface IOrderBookFactory where TOptions : OrderBookOptions + { + /// + /// Create a new order book by symbol name + /// + /// Symbol name + /// Options for the order book + /// + public ISymbolOrderBook Create(string symbol, Action? options = null); + /// + /// Create a new order book by base and quote asset names + /// + /// Base asset name + /// Quote asset name + /// Options for the order book + /// + public ISymbolOrderBook Create(string baseAsset, string quoteAsset, Action? options = null); + } +} diff --git a/CryptoExchange.Net/Objects/Options/OrderBookOptions.cs b/CryptoExchange.Net/Objects/Options/OrderBookOptions.cs index 1e6b0625..9bcc39d2 100644 --- a/CryptoExchange.Net/Objects/Options/OrderBookOptions.cs +++ b/CryptoExchange.Net/Objects/Options/OrderBookOptions.cs @@ -3,7 +3,7 @@ /// /// Base for order book options /// - public class OrderBookOptions : ExchangeOptions + public class OrderBookOptions { /// /// Whether or not checksum validation is enabled. Default is true, disabling will ignore checksum messages. @@ -19,11 +19,7 @@ public class OrderBookOptions : ExchangeOptions { return new T { - ApiCredentials = ApiCredentials?.Copy(), - OutputOriginalData = OutputOriginalData, ChecksumValidationEnabled = ChecksumValidationEnabled, - Proxy = Proxy, - RequestTimeout = RequestTimeout }; } } diff --git a/CryptoExchange.Net/OrderBook/OrderBookFactory.cs b/CryptoExchange.Net/OrderBook/OrderBookFactory.cs new file mode 100644 index 00000000..279dddb2 --- /dev/null +++ b/CryptoExchange.Net/OrderBook/OrderBookFactory.cs @@ -0,0 +1,30 @@ +using CryptoExchange.Net.Interfaces; +using CryptoExchange.Net.Objects.Options; +using System; + +namespace CryptoExchange.Net.OrderBook +{ + /// + public class OrderBookFactory : IOrderBookFactory where TOptions: OrderBookOptions + { + private readonly Func?, ISymbolOrderBook> _symbolCtor; + private readonly Func?, ISymbolOrderBook> _assetsCtor; + + /// + /// ctor + /// + /// + /// + public OrderBookFactory(Func?, ISymbolOrderBook> symbolCtor, Func?, ISymbolOrderBook> assetsCtor) + { + _symbolCtor = symbolCtor; + _assetsCtor = assetsCtor; + } + + /// + public ISymbolOrderBook Create(string symbol, Action? options = null) => _symbolCtor(symbol, options); + + /// + public ISymbolOrderBook Create(string baseAsset, string quoteAsset, Action? options = null) => _assetsCtor(baseAsset, quoteAsset, options); + } +} diff --git a/CryptoExchange.Net/Sockets/CryptoExchangeWebSocketClient.cs b/CryptoExchange.Net/Sockets/CryptoExchangeWebSocketClient.cs index 40c4f8d0..6162317f 100644 --- a/CryptoExchange.Net/Sockets/CryptoExchangeWebSocketClient.cs +++ b/CryptoExchange.Net/Sockets/CryptoExchangeWebSocketClient.cs @@ -729,7 +729,7 @@ public struct SendItem public int Id { get; set; } /// - /// The request id + /// The request weight /// public int Weight { get; set; }