1
0
mirror of https://github.com/JKorf/CryptoExchange.Net synced 2026-04-12 16:13:12 +00:00
This commit is contained in:
Jkorf 2026-03-20 16:34:01 +01:00
parent 46d3ffcf66
commit ee30618566
5 changed files with 42 additions and 17 deletions

View File

@ -474,7 +474,7 @@ namespace CryptoExchange.Net.Authentication
/// <inheritdoc />
public abstract class AuthenticationProvider<TApiCredentials, TCredentialType> : AuthenticationProvider<TApiCredentials>
where TApiCredentials : ApiCredentials
where TCredentialType : CredentialPair
where TCredentialType : CredentialSet
{
/// <summary>
/// The specific credential type used for signing requests.

View File

@ -7,9 +7,9 @@ using System.Text;
namespace CryptoExchange.Net.Authentication
{
/// <summary>
/// Credential pair base class
/// Base class for a set of credentials
/// </summary>
public abstract class CredentialPair : ApiCredentials
public abstract class CredentialSet : ApiCredentials
{
/// <summary>
/// The (public) key/identifier for this credential pair
@ -19,12 +19,12 @@ namespace CryptoExchange.Net.Authentication
/// <summary>
/// ctor
/// </summary>
public CredentialPair() { }
public CredentialSet() { }
/// <summary>
/// ctor
/// </summary>
public CredentialPair(string key)
public CredentialSet(string key)
{
Key = key;
}
@ -42,7 +42,7 @@ namespace CryptoExchange.Net.Authentication
/// <summary>
/// Api key credentials
/// </summary>
public class ApiKeyCredential : CredentialPair
public class ApiKeyCredential : CredentialSet
{
/// <summary>
/// ctor
@ -60,7 +60,7 @@ namespace CryptoExchange.Net.Authentication
/// <summary>
/// HMAC credentials
/// </summary>
public class HMACCredential : CredentialPair
public class HMACCredential : CredentialSet
{
private byte[]? _sBytes;
@ -151,7 +151,7 @@ namespace CryptoExchange.Net.Authentication
/// <summary>
/// RSA credentials
/// </summary>
public abstract class RSACredential : CredentialPair
public abstract class RSACredential : CredentialSet
{
/// <summary>
/// Private key
@ -399,7 +399,7 @@ namespace CryptoExchange.Net.Authentication
/// <summary>
/// Credentials in Ed25519 format
/// </summary>
public class Ed25519Credential : CredentialPair
public class Ed25519Credential : CredentialSet
{
private NSec.Cryptography.Key? _signKey;
@ -499,7 +499,7 @@ namespace CryptoExchange.Net.Authentication
/// <summary>
/// Credentials in ECDsa format
/// </summary>
public class ECDsaCredential : CredentialPair
public class ECDsaCredential : CredentialSet
{
/// <summary>
/// Private key

View File

@ -27,6 +27,11 @@ namespace CryptoExchange.Net.Clients
/// </summary>
protected bool _disposing;
/// <summary>
/// Whether a proxy is configured
/// </summary>
protected bool _proxyConfigured;
/// <summary>
/// Name of the client
/// </summary>
@ -88,6 +93,8 @@ namespace CryptoExchange.Net.Clients
ApiOptions = apiOptions;
OutputOriginalData = outputOriginalData;
BaseAddress = baseAddress;
_proxyConfigured = ClientOptions.Proxy != null;
}
/// <inheritdoc />

View File

@ -890,6 +890,7 @@ namespace CryptoExchange.Net.Clients
/// <inheritdoc />
public virtual void SetOptions(UpdateOptions<TApiCredentials> options)
{
_proxyConfigured = options.Proxy != null;
ClientOptions.Proxy = options.Proxy;
ClientOptions.RequestTimeout = options.RequestTimeout ?? ClientOptions.RequestTimeout;
@ -958,15 +959,23 @@ namespace CryptoExchange.Net.Clients
public override void SetApiCredentials(TApiCredentials credentials)
{
base.SetApiCredentials(credentials);
AuthenticationProvider = CreateAuthenticationProvider(credentials);
AuthenticationProvider = null;
_authProviderInitialized = false;
ApiCredentials = credentials;
}
/// <inheritdoc />
public override void SetOptions(UpdateOptions<TApiCredentials> options)
{
base.SetOptions(options);
if (ApiCredentials != null)
AuthenticationProvider = CreateAuthenticationProvider(ApiCredentials);
if (options.ApiCredentials != null)
{
AuthenticationProvider = null;
_authProviderInitialized = false;
ApiCredentials = options.ApiCredentials;
}
}
}
}

View File

@ -1102,13 +1102,14 @@ namespace CryptoExchange.Net.Clients
/// <inheritdoc />
public virtual void SetOptions(UpdateOptions<TApiCredentials> options)
{
var previousProxyIsSet = ClientOptions.Proxy != null;
var previousProxyIsSet = _proxyConfigured;
ClientOptions.Proxy = options.Proxy;
ClientOptions.RequestTimeout = options.RequestTimeout ?? ClientOptions.RequestTimeout;
ApiCredentials = (TApiCredentials?)options.ApiCredentials?.Copy() ?? ApiCredentials;
_proxyConfigured = options.Proxy != null;
if ((!previousProxyIsSet && options.Proxy == null)
|| _socketConnections.IsEmpty)
{
@ -1180,15 +1181,23 @@ namespace CryptoExchange.Net.Clients
/// <inheritdoc />
public override void SetApiCredentials(TApiCredentials credentials)
{
AuthenticationProvider = CreateAuthenticationProvider(credentials);
AuthenticationProvider = null;
_authProviderInitialized = false;
ApiCredentials = credentials;
base.SetApiCredentials(credentials);
}
/// <inheritdoc />
public override void SetOptions(UpdateOptions<TApiCredentials> options)
{
if (ApiCredentials != null)
AuthenticationProvider = CreateAuthenticationProvider(ApiCredentials);
if (options.ApiCredentials != null)
{
AuthenticationProvider = null;
_authProviderInitialized = false;
ApiCredentials = options.ApiCredentials;
}
base.SetOptions(options);
}
}