diff --git a/CryptoExchange.Net.UnitTests/OptionsTests.cs b/CryptoExchange.Net.UnitTests/OptionsTests.cs index 6330d2f..d2e1245 100644 --- a/CryptoExchange.Net.UnitTests/OptionsTests.cs +++ b/CryptoExchange.Net.UnitTests/OptionsTests.cs @@ -29,7 +29,7 @@ namespace CryptoExchange.Net.UnitTests // act // assert Assert.Throws(typeof(ArgumentException), - () => new RestExchangeOptions() { ApiCredentials = new TestCredentials(key, secret) }); + () => new RestExchangeOptions() { ApiCredentials = new HMACCredential(key, secret) }); } [Test] @@ -38,94 +38,19 @@ namespace CryptoExchange.Net.UnitTests // arrange, act var options = new TestClientOptions { - ApiCredentials = new TestCredentials("123", "456"), + ApiCredentials = new HMACCredential("123", "456"), ReceiveWindow = TimeSpan.FromSeconds(10) }; // assert Assert.That(options.ReceiveWindow == TimeSpan.FromSeconds(10)); - Assert.That(options.ApiCredentials.GetCredential().Key == "123"); - Assert.That(options.ApiCredentials.GetCredential().Secret == "456"); + Assert.That(options.ApiCredentials.Key == "123"); + Assert.That(options.ApiCredentials.Secret == "456"); } - [Test] - public void TestApiOptionsAreSet() - { - // arrange, act - var options = new TestClientOptions(); - options.Api1Options.ApiCredentials = new TestCredentials("123", "456"); - options.Api2Options.ApiCredentials = new TestCredentials("789", "101"); - - // assert - Assert.That(options.Api1Options.ApiCredentials.GetCredential().Key == "123"); - Assert.That(options.Api1Options.ApiCredentials.GetCredential().Secret == "456"); - Assert.That(options.Api2Options.ApiCredentials.GetCredential().Key == "789"); - Assert.That(options.Api2Options.ApiCredentials.GetCredential().Secret == "101"); - } - - [Test] - public void TestClientUsesCorrectOptions() - { - var client = new TestRestClient(options => { - options.Api1Options.ApiCredentials = new TestCredentials("111", "222"); - options.ApiCredentials = new TestCredentials("333", "444"); - }); - - var authProvider1 = (TestAuthProvider)client.Api1.AuthenticationProvider; - var authProvider2 = (TestAuthProvider)client.Api2.AuthenticationProvider; - Assert.That(authProvider1.GetKey() == "111"); - Assert.That(authProvider1.GetSecret() == "222"); - Assert.That(authProvider2.GetKey() == "333"); - Assert.That(authProvider2.GetSecret() == "444"); - } - - [Test] - public void TestClientUsesCorrectOptionsWithDefault() - { - TestClientOptions.Default.ApiCredentials = new TestCredentials("123", "456"); - TestClientOptions.Default.Api1Options.ApiCredentials = new TestCredentials("111", "222"); - - var client = new TestRestClient(); - - var authProvider1 = (TestAuthProvider)client.Api1.AuthenticationProvider; - var authProvider2 = (TestAuthProvider)client.Api2.AuthenticationProvider; - Assert.That(authProvider1.GetKey() == "111"); - Assert.That(authProvider1.GetSecret() == "222"); - Assert.That(authProvider2.GetKey() == "123"); - Assert.That(authProvider2.GetSecret() == "456"); - - // Cleanup static values - TestClientOptions.Default.ApiCredentials = null; - TestClientOptions.Default.Api1Options.ApiCredentials = null; - } - - [Test] - public void TestClientUsesCorrectOptionsWithOverridingDefault() - { - TestClientOptions.Default.ApiCredentials = new TestCredentials("123", "456"); - TestClientOptions.Default.Api1Options.ApiCredentials = new TestCredentials("111", "222"); - - var client = new TestRestClient(options => - { - options.Api1Options.ApiCredentials = new TestCredentials("333", "444"); - options.Environment = new TestEnvironment("Test", "https://test.test"); - }); - - var authProvider1 = client.Api1.AuthenticationProvider; - var authProvider2 = client.Api2.AuthenticationProvider; - Assert.That(authProvider1.GetKey() == "333"); - Assert.That(authProvider1.GetSecret() == "444"); - Assert.That(authProvider2.GetKey() == "123"); - Assert.That(authProvider2.GetSecret() == "456"); - Assert.That(client.Api2.BaseAddress == "https://localhost:123"); - - // Cleanup static values - TestClientOptions.Default.ApiCredentials = null; - TestClientOptions.Default.Api1Options.ApiCredentials = null; - } } - public class TestClientOptions: RestExchangeOptions + public class TestClientOptions: RestExchangeOptions { /// /// Default options for the futures client @@ -148,9 +73,9 @@ namespace CryptoExchange.Net.UnitTests /// public TimeSpan ReceiveWindow { get; set; } = TimeSpan.FromSeconds(5); - public RestApiOptions Api1Options { get; private set; } = new RestApiOptions(); + public RestApiOptions Api1Options { get; private set; } = new RestApiOptions(); - public RestApiOptions Api2Options { get; set; } = new RestApiOptions(); + public RestApiOptions Api2Options { get; set; } = new RestApiOptions(); internal TestClientOptions Set(TestClientOptions targetOptions) { diff --git a/CryptoExchange.Net.UnitTests/TestImplementations/TestBaseClient.cs b/CryptoExchange.Net.UnitTests/TestImplementations/TestBaseClient.cs index d43ccf8..e7a6496 100644 --- a/CryptoExchange.Net.UnitTests/TestImplementations/TestBaseClient.cs +++ b/CryptoExchange.Net.UnitTests/TestImplementations/TestBaseClient.cs @@ -26,14 +26,14 @@ namespace CryptoExchange.Net.UnitTests var options = new TestClientOptions(); _logger = NullLogger.Instance; Initialize(options); - SubClient = AddApiClient(new TestSubClient(options, new RestApiOptions())); + SubClient = AddApiClient(new TestSubClient(options, new RestApiOptions())); } public TestBaseClient(TestClientOptions exchangeOptions) : base(null, "Test") { _logger = NullLogger.Instance; Initialize(exchangeOptions); - SubClient = AddApiClient(new TestSubClient(exchangeOptions, new RestApiOptions())); + SubClient = AddApiClient(new TestSubClient(exchangeOptions, new RestApiOptions())); } public void Log(LogLevel verbosity, string data) @@ -42,11 +42,11 @@ namespace CryptoExchange.Net.UnitTests } } - public class TestSubClient : RestApiClient + public class TestSubClient : RestApiClient { protected override IRestMessageHandler MessageHandler => throw new NotImplementedException(); - public TestSubClient(RestExchangeOptions options, RestApiOptions apiOptions) : base(new TraceLogger(), null, "https://localhost:123", options, apiOptions) + public TestSubClient(RestExchangeOptions options, RestApiOptions apiOptions) : base(new TraceLogger(), null, "https://localhost:123", options, apiOptions) { } @@ -58,15 +58,13 @@ namespace CryptoExchange.Net.UnitTests /// public override string FormatSymbol(string baseAsset, string quoteAsset, TradingMode futuresType, DateTime? deliverDate = null) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}"; protected override IMessageSerializer CreateSerializer() => new SystemTextJsonMessageSerializer(new System.Text.Json.JsonSerializerOptions()); - protected override TestAuthProvider CreateAuthenticationProvider(TestCredentials credentials) => throw new NotImplementedException(); + protected override TestAuthProvider CreateAuthenticationProvider(HMACCredential credentials) => throw new NotImplementedException(); protected override Task> GetServerTimestampAsync() => throw new NotImplementedException(); } - public class TestAuthProvider : AuthenticationProvider + public class TestAuthProvider : AuthenticationProvider { - public override ApiCredentialsType[] SupportedCredentialTypes => [ApiCredentialsType.HMAC]; - - public TestAuthProvider(TestCredentials credentials) : base(credentials) + public TestAuthProvider(HMACCredential credentials) : base(credentials, credentials) { } @@ -87,14 +85,4 @@ namespace CryptoExchange.Net.UnitTests TestAddress = url; } } - - public class TestCredentials : ApiCredentials - { - public TestCredentials(string apiKey, string secret) : this(new HMACCredential(apiKey, secret)) { } - - public TestCredentials(HMACCredential credential) : base(credential) { } - - /// - public override ApiCredentials Copy() => new TestCredentials(HMAC!); - } } diff --git a/CryptoExchange.Net.UnitTests/TestImplementations/TestRestClient.cs b/CryptoExchange.Net.UnitTests/TestImplementations/TestRestClient.cs index efcca5b..5e90269 100644 --- a/CryptoExchange.Net.UnitTests/TestImplementations/TestRestClient.cs +++ b/CryptoExchange.Net.UnitTests/TestImplementations/TestRestClient.cs @@ -130,7 +130,7 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations } } - public class TestRestApi1Client : RestApiClient + public class TestRestApi1Client : RestApiClient { protected override IRestMessageHandler MessageHandler { get; } = new TestRestMessageHandler(); @@ -159,7 +159,7 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations ParameterPositions[method] = position; } - protected override TestAuthProvider CreateAuthenticationProvider(TestCredentials credentials) + protected override TestAuthProvider CreateAuthenticationProvider(HMACCredential credentials) => new TestAuthProvider(credentials); protected override Task> GetServerTimestampAsync() @@ -168,7 +168,7 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations } } - public class TestRestApi2Client : RestApiClient + public class TestRestApi2Client : RestApiClient { protected override IRestMessageHandler MessageHandler { get; } = new TestRestMessageHandler(); @@ -187,7 +187,7 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations return await SendAsync("http://www.test.com", new RequestDefinition("/", HttpMethod.Get) { Weight = 0 }, null, ct); } - protected override TestAuthProvider CreateAuthenticationProvider(TestCredentials credentials) + protected override TestAuthProvider CreateAuthenticationProvider(HMACCredential credentials) => new TestAuthProvider(credentials); protected override Task> GetServerTimestampAsync() diff --git a/CryptoExchange.Net/Authentication/ApiCredentials.cs b/CryptoExchange.Net/Authentication/ApiCredentials.cs index ae2f506..416b57f 100644 --- a/CryptoExchange.Net/Authentication/ApiCredentials.cs +++ b/CryptoExchange.Net/Authentication/ApiCredentials.cs @@ -1,143 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -namespace CryptoExchange.Net.Authentication +namespace CryptoExchange.Net.Authentication { /// /// Api credentials, used to sign requests accessing private endpoints /// public abstract class ApiCredentials { - /// - /// The credential pairs contained in these API credentials. This can contain multiple credential pairs when the API requires different credentials for different endpoints. - /// - public CredentialPair[] CredentialPairs { get; protected set; } = Array.Empty(); - - /// - /// The public key/identifier for the provided credentials - /// - public string Key => CredentialPairs.First().Key; - - /// - /// HMAC credentials - /// - public HMACCredential? HMAC - { - get => (HMACCredential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.HMAC); - set => AddOrRemoveCredential(ApiCredentialsType.HMAC, value); - } - - /// - /// RSA credentials - /// - public RSACredential? RSA - { - get => (RSACredential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.RSA); - set => AddOrRemoveCredential(ApiCredentialsType.RSA, value); - } - - /// - /// RSA credentials in XML format - /// - public RSAXmlCredential? RSAXml - { - get => (RSAXmlCredential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.RSA); - set => AddOrRemoveCredential(ApiCredentialsType.RSA, value); - } - -#if NETSTANDARD2_1_OR_GREATER || NET7_0_OR_GREATER - /// - /// RSA credentials in PEM/Base64 format - /// - public RSAPemCredential? RSAPem - { - get => (RSAPemCredential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.RSA); - set => AddOrRemoveCredential(ApiCredentialsType.RSA, value); - } -#endif - -#if NET8_0_OR_GREATER - /// - /// Ed25519 credentials - /// - public Ed25519Credential? Ed25519 - { - get => (Ed25519Credential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.Ed25519); - set => AddOrRemoveCredential(ApiCredentialsType.Ed25519, value); - } -#endif - /// - /// ECDsa credentials - /// - public ECDsaCredential? ECDsa - { - get => (ECDsaCredential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.ECDsa); - set => AddOrRemoveCredential(ApiCredentialsType.ECDsa, value); - } - - /// - /// API key credentials - /// - public ApiKeyCredential? ApiKey - { - get => (ApiKeyCredential?)CredentialPairs.SingleOrDefault(x => x.CredentialType == ApiCredentialsType.ApiKey); - set => AddOrRemoveCredential(ApiCredentialsType.ApiKey, value); - } - - /// - /// If credential is null attempt to remove the credential of the type, else add it - /// - protected void AddOrRemoveCredential(ApiCredentialsType type, CredentialPair? credential) - { - if (credential is null) - { - var cred = CredentialPairs.SingleOrDefault(x => x.CredentialType == type); - if (cred != null) - { - var newList = CredentialPairs.ToList(); - newList.Remove(cred); - CredentialPairs = newList.ToArray(); - } - } - else - { - var newList = CredentialPairs.ToList(); - newList.Add(credential); - CredentialPairs = newList.ToArray(); - } - } - - /// - /// DI constructor - /// - [Obsolete("Parameterless constructor is only for deserialization purposes and should not be used directly.")] - public ApiCredentials() { } - - /// - /// Create API credentials using the provided credential pair - /// - public ApiCredentials(CredentialPair credential) - { - CredentialPairs = [credential]; - } - - /// - /// Create API credentials using the provided credential pairs - /// - public ApiCredentials(params IEnumerable credentials) - { - CredentialPairs = credentials.Where(x => x != null).ToArray()!; - } - - /// - /// Get credentials of a specific type - /// - public T? GetCredential() where T : CredentialPair - { - return CredentialPairs.OfType().SingleOrDefault(); - } - /// /// Copy the credentials /// diff --git a/CryptoExchange.Net/Authentication/ApiCredentialsType.cs b/CryptoExchange.Net/Authentication/ApiCredentialsType.cs deleted file mode 100644 index d4367a8..0000000 --- a/CryptoExchange.Net/Authentication/ApiCredentialsType.cs +++ /dev/null @@ -1,33 +0,0 @@ -namespace CryptoExchange.Net.Authentication -{ - /// - /// Credentials type - /// - public enum ApiCredentialsType - { - /// - /// HMAC credentials - /// - HMAC, - /// - /// RSA credentials - /// - RSA, - /// - /// Ed25519 credentials - /// - Ed25519, - /// - /// ECDsa credentials - /// - ECDsa, - /// - /// API key credentials - /// - ApiKey, - /// - /// Custom / exchange specific - /// - Custom - } -} diff --git a/CryptoExchange.Net/Authentication/AuthenticationProvider.cs b/CryptoExchange.Net/Authentication/AuthenticationProvider.cs index 35cccd8..0d26a47 100644 --- a/CryptoExchange.Net/Authentication/AuthenticationProvider.cs +++ b/CryptoExchange.Net/Authentication/AuthenticationProvider.cs @@ -29,11 +29,6 @@ namespace CryptoExchange.Net.Authentication /// public abstract string Key { get; } - /// - /// The supported credential types - /// - public abstract ApiCredentialsType[] SupportedCredentialTypes { get; } - /// /// Authenticate a REST request /// @@ -458,13 +453,14 @@ namespace CryptoExchange.Net.Authentication /// public abstract class AuthenticationProvider : AuthenticationProvider - where TApiCredentials : ApiCredentials { /// /// API credentials used for signing requests /// public TApiCredentials ApiCredentials { get; set; } + public CredentialPair? Credential { get; set; } + /// /// ctor /// @@ -472,17 +468,28 @@ namespace CryptoExchange.Net.Authentication { ApiCredentials = credentials; } + + /// + /// ctor + /// + protected AuthenticationProvider(TApiCredentials credentials, CredentialPair? credentialPair) + { + if (credentialPair == null) + throw new ArgumentNullException(nameof(credentialPair), $"Credential pair needed but not provided"); + + ApiCredentials = credentials; + Credential = credentialPair; + } } /// public abstract class AuthenticationProvider : AuthenticationProvider - where TApiCredentials : ApiCredentials where TCredentialType : CredentialPair { /// /// The specific credential type used for signing requests. /// - public TCredentialType Credential { get; set; } + public new TCredentialType Credential => (TCredentialType)base.Credential!; /// public override string Key => Credential.Key; @@ -490,10 +497,8 @@ namespace CryptoExchange.Net.Authentication /// /// ctor /// - protected AuthenticationProvider(TApiCredentials credentials) : base(credentials) + protected AuthenticationProvider(TApiCredentials credentials, TCredentialType? credential) : base(credentials, credential) { - Credential = credentials.GetCredential() - ?? throw new Exception($"Credential type {typeof(TCredentialType).Name} needed but not provided"); } /// @@ -513,10 +518,10 @@ namespace CryptoExchange.Net.Authentication /// protected string SignHMACSHA256(byte[] data, SignOutputType? outputType = null) { - if (Credential.CredentialType != ApiCredentialsType.HMAC) + if (Credential is not HMACCredential hmacCredential) throw new InvalidOperationException($"Invalid HMAC signing without HMAC credentials provided"); - return SignHMACSHA256((Credential as HMACCredential)!, data, outputType); + return SignHMACSHA256(hmacCredential, data, outputType); } /// @@ -536,10 +541,10 @@ namespace CryptoExchange.Net.Authentication /// protected string SignHMACSHA384(byte[] data, SignOutputType? outputType = null) { - if (Credential.CredentialType != ApiCredentialsType.HMAC) + if (Credential is not HMACCredential hmacCredential) throw new InvalidOperationException($"Invalid HMAC signing without HMAC credentials provided"); - return SignHMACSHA384((Credential as HMACCredential)!, data, outputType); + return SignHMACSHA384(hmacCredential, data, outputType); } /// @@ -559,10 +564,10 @@ namespace CryptoExchange.Net.Authentication /// protected string SignHMACSHA512(byte[] data, SignOutputType? outputType = null) { - if (Credential.CredentialType != ApiCredentialsType.HMAC) + if (Credential is not HMACCredential hmacCredential) throw new InvalidOperationException($"Invalid HMAC signing without HMAC credentials provided"); - return SignHMACSHA512((Credential as HMACCredential)!, data, outputType); + return SignHMACSHA512(hmacCredential, data, outputType); } /// @@ -573,10 +578,10 @@ namespace CryptoExchange.Net.Authentication /// protected string SignRSASHA256(byte[] data, SignOutputType? outputType = null) { - if (Credential.CredentialType != ApiCredentialsType.RSA) + if (Credential is not RSACredential rsaCredential) throw new InvalidOperationException($"Invalid RSA signing without RSA credentials provided"); - return SignRSASHA256((Credential as RSACredential)!, data, outputType); + return SignRSASHA256(rsaCredential, data, outputType); } /// @@ -587,10 +592,10 @@ namespace CryptoExchange.Net.Authentication /// protected string SignRSASHA384(byte[] data, SignOutputType? outputType = null) { - if (Credential.CredentialType != ApiCredentialsType.RSA) + if (Credential is not RSACredential rsaCredential) throw new InvalidOperationException($"Invalid RSA signing without RSA credentials provided"); - return SignRSASHA384((Credential as RSACredential)!, data, outputType); + return SignRSASHA384(rsaCredential, data, outputType); } /// @@ -601,10 +606,10 @@ namespace CryptoExchange.Net.Authentication /// protected string SignRSASHA512(byte[] data, SignOutputType? outputType = null) { - if (Credential.CredentialType != ApiCredentialsType.RSA) + if (Credential is not RSACredential rsaCredential) throw new InvalidOperationException($"Invalid RSA signing without RSA credentials provided"); - return SignRSASHA512((Credential as RSACredential)!, data, outputType); + return SignRSASHA512(rsaCredential, data, outputType); } #if NET8_0_OR_GREATER @@ -619,10 +624,10 @@ namespace CryptoExchange.Net.Authentication /// public string SignEd25519(byte[] data, SignOutputType? outputType = null) { - if (Credential.CredentialType != ApiCredentialsType.Ed25519) + if (Credential is not Ed25519Credential ed25519Credential) throw new InvalidOperationException($"Invalid Ed25519 signing without Ed25519 credentials provided"); - return SignEd25519((Credential as Ed25519Credential)!, data, outputType); + return SignEd25519(ed25519Credential, data, outputType); } #endif } diff --git a/CryptoExchange.Net/Authentication/CredentialPair.cs b/CryptoExchange.Net/Authentication/CredentialPair.cs index 231dc2a..26f6228 100644 --- a/CryptoExchange.Net/Authentication/CredentialPair.cs +++ b/CryptoExchange.Net/Authentication/CredentialPair.cs @@ -7,16 +7,12 @@ namespace CryptoExchange.Net.Authentication /// /// Credential pair base class /// - public abstract class CredentialPair + public abstract class CredentialPair : ApiCredentials { /// /// The (public) key/identifier for this credential pair /// public string Key { get; set; } - /// - /// Type of credentials - /// - public abstract ApiCredentialsType CredentialType { get; } /// /// ctor @@ -32,9 +28,6 @@ namespace CryptoExchange.Net.Authentication /// public class ApiKeyCredential : CredentialPair { - /// - public override ApiCredentialsType CredentialType => ApiCredentialsType.ApiKey; - /// /// ctor /// @@ -44,6 +37,9 @@ namespace CryptoExchange.Net.Authentication if (string.IsNullOrEmpty(key)) throw new ArgumentException("Key can't be null/empty"); } + + /// + public override ApiCredentials Copy() => new ApiKeyCredential(Key); } /// @@ -62,9 +58,6 @@ namespace CryptoExchange.Net.Authentication /// public string? Pass { get; set; } - /// - public override ApiCredentialsType CredentialType => ApiCredentialsType.HMAC; - /// /// ctor /// @@ -88,6 +81,9 @@ namespace CryptoExchange.Net.Authentication { return _sBytes ??= Encoding.UTF8.GetBytes(Secret); } + + /// + public override ApiCredentials Copy() => new HMACCredential(Key, Secret, Pass); } /// @@ -104,9 +100,6 @@ namespace CryptoExchange.Net.Authentication /// public string? Pass { get; set; } - /// - public override ApiCredentialsType CredentialType => ApiCredentialsType.RSA; - /// /// ctor /// @@ -161,6 +154,9 @@ namespace CryptoExchange.Net.Authentication return rsa; } + + /// + public override ApiCredentials Copy() => new RSAPemCredential(Key, PrivateKey, Pass); } #endif @@ -188,6 +184,9 @@ namespace CryptoExchange.Net.Authentication rsa.FromXmlString(PrivateKey); return rsa; } + + /// + public override ApiCredentials Copy() => new RSAXmlCredential(Key, PrivateKey, Pass); } #if NET8_0_OR_GREATER @@ -207,9 +206,6 @@ namespace CryptoExchange.Net.Authentication /// public string? Pass { get; set; } - /// - public override ApiCredentialsType CredentialType => ApiCredentialsType.Ed25519; - /// /// ctor /// @@ -239,6 +235,9 @@ namespace CryptoExchange.Net.Authentication _signKey = NSec.Cryptography.Key.Import(NSec.Cryptography.SignatureAlgorithm.Ed25519, keyBytes, NSec.Cryptography.KeyBlobFormat.PkixPrivateKey); return _signKey; } + + /// + public override ApiCredentials Copy() => new Ed25519Credential(Key, PrivateKey, Pass); } #endif @@ -256,9 +255,6 @@ namespace CryptoExchange.Net.Authentication /// public string? Pass { get; set; } - /// - public override ApiCredentialsType CredentialType => ApiCredentialsType.ECDsa; - /// /// ctor /// @@ -270,5 +266,8 @@ namespace CryptoExchange.Net.Authentication PrivateKey = privateKey; Pass = pass; } + + /// + public override ApiCredentials Copy() => new ECDsaCredential(Key, PrivateKey, Pass); } } diff --git a/CryptoExchange.Net/Clients/RestApiClient.cs b/CryptoExchange.Net/Clients/RestApiClient.cs index 67e41c6..09f004f 100644 --- a/CryptoExchange.Net/Clients/RestApiClient.cs +++ b/CryptoExchange.Net/Clients/RestApiClient.cs @@ -852,9 +852,6 @@ namespace CryptoExchange.Net.Clients /// public new RestExchangeOptions ClientOptions => (RestExchangeOptions)base.ClientOptions; - /// - public new RestApiOptions ApiOptions => (RestApiOptions)base.ApiOptions; - /// /// ctor /// @@ -863,14 +860,14 @@ namespace CryptoExchange.Net.Clients HttpClient? httpClient, string baseAddress, RestExchangeOptions options, - RestApiOptions apiOptions) : base( + RestApiOptions apiOptions) : base( logger, httpClient, baseAddress, options, apiOptions) { - ApiCredentials = apiOptions.ApiCredentials ?? options.ApiCredentials; + ApiCredentials = options.ApiCredentials; } /// @@ -930,7 +927,7 @@ namespace CryptoExchange.Net.Clients HttpClient? httpClient, string baseAddress, RestExchangeOptions options, - RestApiOptions apiOptions) : base( + RestApiOptions apiOptions) : base( logger, httpClient, baseAddress, diff --git a/CryptoExchange.Net/Clients/SocketApiClient.cs b/CryptoExchange.Net/Clients/SocketApiClient.cs index b2a7216..bba72d3 100644 --- a/CryptoExchange.Net/Clients/SocketApiClient.cs +++ b/CryptoExchange.Net/Clients/SocketApiClient.cs @@ -1066,9 +1066,6 @@ namespace CryptoExchange.Net.Clients /// public new SocketExchangeOptions ClientOptions => (SocketExchangeOptions)base.ClientOptions; - /// - public new SocketApiOptions ApiOptions => (SocketApiOptions)base.ApiOptions; - /// /// ctor /// @@ -1076,13 +1073,13 @@ namespace CryptoExchange.Net.Clients ILogger logger, string baseAddress, SocketExchangeOptions options, - SocketApiOptions apiOptions) : base( + SocketApiOptions apiOptions) : base( logger, baseAddress, options, apiOptions) { - ApiCredentials = apiOptions.ApiCredentials ?? options.ApiCredentials; + ApiCredentials = options.ApiCredentials; } /// @@ -1154,7 +1151,7 @@ namespace CryptoExchange.Net.Clients ILogger logger, string baseAddress, SocketExchangeOptions options, - SocketApiOptions apiOptions) : base( + SocketApiOptions apiOptions) : base( logger, baseAddress, options, diff --git a/CryptoExchange.Net/LibraryHelpers.cs b/CryptoExchange.Net/LibraryHelpers.cs index 4125651..92a4e65 100644 --- a/CryptoExchange.Net/LibraryHelpers.cs +++ b/CryptoExchange.Net/LibraryHelpers.cs @@ -167,8 +167,8 @@ namespace CryptoExchange.Net /// public static void ValidateCredentials(ApiCredentials? credentials) { - if (credentials != null && credentials.CredentialPairs.Length == 0) - throw new ArgumentException("ApiCredentials configuration invalid"); + //if (credentials != null && credentials.CredentialPairs.Length == 0) + // throw new ArgumentException("ApiCredentials configuration invalid"); } } } diff --git a/CryptoExchange.Net/Objects/Options/RestApiOptions.cs b/CryptoExchange.Net/Objects/Options/RestApiOptions.cs index 0540c38..7913097 100644 --- a/CryptoExchange.Net/Objects/Options/RestApiOptions.cs +++ b/CryptoExchange.Net/Objects/Options/RestApiOptions.cs @@ -24,23 +24,4 @@ namespace CryptoExchange.Net.Objects.Options return item; } } - - /// - public class RestApiOptions : RestApiOptions where TApiCredentials : ApiCredentials - { - /// - /// The api credentials used for signing requests to this API. Overrides API credentials provided in the client options - /// - public TApiCredentials? ApiCredentials { get; set; } - - /// - /// Set the values of this options on the target options - /// - public new T Set(T item) where T : RestApiOptions, new() - { - base.Set(item); - item.ApiCredentials = (TApiCredentials?)ApiCredentials?.Copy(); - return item; - } - } } diff --git a/CryptoExchange.Net/Objects/Options/SocketApiOptions.cs b/CryptoExchange.Net/Objects/Options/SocketApiOptions.cs index 39f6941..88af5ed 100644 --- a/CryptoExchange.Net/Objects/Options/SocketApiOptions.cs +++ b/CryptoExchange.Net/Objects/Options/SocketApiOptions.cs @@ -31,23 +31,4 @@ namespace CryptoExchange.Net.Objects.Options return item; } } - - /// - public class SocketApiOptions : SocketApiOptions where TApiCredentials : ApiCredentials - { - /// - /// The api credentials used for signing requests to this API. Overrides API credentials provided in the client options - /// - public TApiCredentials? ApiCredentials { get; set; } - - /// - /// Set the values of this options on the target options - /// - public new T Set(T item) where T : SocketApiOptions, new() - { - base.Set(item); - item.ApiCredentials = (TApiCredentials?)ApiCredentials?.Copy(); - return item; - } - } }