mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-07 16:06:15 +00:00
Small rework in options
This commit is contained in:
parent
e1f8b8b7b7
commit
c792bc25b6
@ -253,11 +253,7 @@ namespace CryptoExchange.Net.UnitTests
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default options for the futures client
|
/// Default options for the futures client
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static TestClientOptions Default { get; set; } = new TestClientOptions()
|
public static TestClientOptions Default { get; set; } = new TestClientOptions();
|
||||||
{
|
|
||||||
Api1Options = new RestApiClientOptions(),
|
|
||||||
Api2Options = new RestApiClientOptions()
|
|
||||||
};
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The default receive window for requests
|
/// The default receive window for requests
|
||||||
@ -268,41 +264,32 @@ namespace CryptoExchange.Net.UnitTests
|
|||||||
public RestApiClientOptions Api1Options
|
public RestApiClientOptions Api1Options
|
||||||
{
|
{
|
||||||
get => _api1Options;
|
get => _api1Options;
|
||||||
set => _api1Options.Copy(_api1Options, value);
|
set => _api1Options = new RestApiClientOptions(_api1Options, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private RestApiClientOptions _api2Options = new RestApiClientOptions("https://api2.test.com/");
|
private RestApiClientOptions _api2Options = new RestApiClientOptions("https://api2.test.com/");
|
||||||
public RestApiClientOptions Api2Options
|
public RestApiClientOptions Api2Options
|
||||||
{
|
{
|
||||||
get => _api2Options;
|
get => _api2Options;
|
||||||
set => _api2Options.Copy(_api2Options, value);
|
set => _api2Options = new RestApiClientOptions(_api2Options, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ctor
|
/// ctor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public TestClientOptions()
|
public TestClientOptions(): this(Default)
|
||||||
{
|
{
|
||||||
if (Default == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Copy(this, Default);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public TestClientOptions(TestClientOptions? baseOn): base(baseOn)
|
||||||
/// Copy the values of the def to the input
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T"></typeparam>
|
|
||||||
/// <param name="input"></param>
|
|
||||||
/// <param name="def"></param>
|
|
||||||
public new void Copy<T>(T input, T def) where T : TestClientOptions
|
|
||||||
{
|
{
|
||||||
base.Copy(input, def);
|
if (baseOn == null)
|
||||||
|
return;
|
||||||
|
|
||||||
input.ReceiveWindow = def.ReceiveWindow;
|
ReceiveWindow = baseOn.ReceiveWindow;
|
||||||
|
|
||||||
input.Api1Options = new RestApiClientOptions(def.Api1Options);
|
Api1Options = new RestApiClientOptions(baseOn.Api1Options, null);
|
||||||
input.Api2Options = new RestApiClientOptions(def.Api2Options);
|
Api2Options = new RestApiClientOptions(baseOn.Api2Options, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,16 +30,24 @@ namespace CryptoExchange.Net.Objects
|
|||||||
public bool OutputOriginalData { get; set; } = false;
|
public bool OutputOriginalData { get; set; } = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Copy the values of the def to the input
|
/// ctor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T"></typeparam>
|
public BaseOptions(): this(null)
|
||||||
/// <param name="input"></param>
|
|
||||||
/// <param name="def"></param>
|
|
||||||
public void Copy<T>(T input, T def) where T : BaseOptions
|
|
||||||
{
|
{
|
||||||
input.LogLevel = def.LogLevel;
|
}
|
||||||
input.LogWriters = def.LogWriters.ToList();
|
|
||||||
input.OutputOriginalData = def.OutputOriginalData;
|
/// <summary>
|
||||||
|
/// ctor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="baseOptions">Copy options from these options to the new options</param>
|
||||||
|
public BaseOptions(BaseOptions? baseOptions)
|
||||||
|
{
|
||||||
|
if (baseOptions == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
LogLevel = baseOptions.LogLevel;
|
||||||
|
LogWriters = baseOptions.LogWriters.ToList();
|
||||||
|
OutputOriginalData = baseOptions.OutputOriginalData;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@ -65,17 +73,23 @@ namespace CryptoExchange.Net.Objects
|
|||||||
public ApiCredentials? ApiCredentials { get; set; }
|
public ApiCredentials? ApiCredentials { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Copy the values of the def to the input
|
/// ctor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T"></typeparam>
|
public BaseClientOptions() : this(null)
|
||||||
/// <param name="input"></param>
|
|
||||||
/// <param name="def"></param>
|
|
||||||
public new void Copy<T>(T input, T def) where T : BaseClientOptions
|
|
||||||
{
|
{
|
||||||
base.Copy(input, def);
|
}
|
||||||
|
|
||||||
input.Proxy = def.Proxy;
|
/// <summary>
|
||||||
input.ApiCredentials = def.ApiCredentials?.Copy();
|
/// ctor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="baseOptions">Copy options from these options to the new options</param>
|
||||||
|
public BaseClientOptions(BaseClientOptions? baseOptions) : base(baseOptions)
|
||||||
|
{
|
||||||
|
if (baseOptions == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Proxy = baseOptions.Proxy;
|
||||||
|
ApiCredentials = baseOptions.ApiCredentials?.Copy();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@ -101,17 +115,23 @@ namespace CryptoExchange.Net.Objects
|
|||||||
public HttpClient? HttpClient { get; set; }
|
public HttpClient? HttpClient { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Copy the values of the def to the input
|
/// ctor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T"></typeparam>
|
public BaseRestClientOptions(): this(null)
|
||||||
/// <param name="input"></param>
|
|
||||||
/// <param name="def"></param>
|
|
||||||
public new void Copy<T>(T input, T def) where T : BaseRestClientOptions
|
|
||||||
{
|
{
|
||||||
base.Copy(input, def);
|
}
|
||||||
|
|
||||||
input.HttpClient = def.HttpClient;
|
/// <summary>
|
||||||
input.RequestTimeout = def.RequestTimeout;
|
/// ctor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="baseOptions">Copy options from these options to the new options</param>
|
||||||
|
public BaseRestClientOptions(BaseRestClientOptions? baseOptions): base(baseOptions)
|
||||||
|
{
|
||||||
|
if (baseOptions == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
HttpClient = baseOptions.HttpClient;
|
||||||
|
RequestTimeout = baseOptions.RequestTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@ -170,23 +190,29 @@ namespace CryptoExchange.Net.Objects
|
|||||||
public int? SocketSubscriptionsCombineTarget { get; set; }
|
public int? SocketSubscriptionsCombineTarget { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Copy the values of the def to the input
|
/// ctor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T"></typeparam>
|
public BaseSocketClientOptions(): this(null)
|
||||||
/// <param name="input"></param>
|
|
||||||
/// <param name="def"></param>
|
|
||||||
public new void Copy<T>(T input, T def) where T : BaseSocketClientOptions
|
|
||||||
{
|
{
|
||||||
base.Copy(input, def);
|
}
|
||||||
|
|
||||||
input.AutoReconnect = def.AutoReconnect;
|
/// <summary>
|
||||||
input.ReconnectInterval = def.ReconnectInterval;
|
/// ctor
|
||||||
input.MaxReconnectTries = def.MaxReconnectTries;
|
/// </summary>
|
||||||
input.MaxResubscribeTries = def.MaxResubscribeTries;
|
/// <param name="baseOptions">Copy options from these options to the new options</param>
|
||||||
input.MaxConcurrentResubscriptionsPerSocket = def.MaxConcurrentResubscriptionsPerSocket;
|
public BaseSocketClientOptions(BaseSocketClientOptions? baseOptions): base(baseOptions)
|
||||||
input.SocketResponseTimeout = def.SocketResponseTimeout;
|
{
|
||||||
input.SocketNoDataTimeout = def.SocketNoDataTimeout;
|
if (baseOptions == null)
|
||||||
input.SocketSubscriptionsCombineTarget = def.SocketSubscriptionsCombineTarget;
|
return;
|
||||||
|
|
||||||
|
AutoReconnect = baseOptions.AutoReconnect;
|
||||||
|
ReconnectInterval = baseOptions.ReconnectInterval;
|
||||||
|
MaxReconnectTries = baseOptions.MaxReconnectTries;
|
||||||
|
MaxResubscribeTries = baseOptions.MaxResubscribeTries;
|
||||||
|
MaxConcurrentResubscriptionsPerSocket = baseOptions.MaxConcurrentResubscriptionsPerSocket;
|
||||||
|
SocketResponseTimeout = baseOptions.SocketResponseTimeout;
|
||||||
|
SocketNoDataTimeout = baseOptions.SocketNoDataTimeout;
|
||||||
|
SocketSubscriptionsCombineTarget = baseOptions.SocketSubscriptionsCombineTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@ -232,27 +258,15 @@ namespace CryptoExchange.Net.Objects
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// ctor
|
/// ctor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="baseOn">Copy values for the provided options</param>
|
/// <param name="baseOptions">Copy values for the provided options</param>
|
||||||
#pragma warning disable 8618 // Will always get filled by the provided options
|
#pragma warning disable 8618 // Will always get filled by the provided options
|
||||||
public ApiClientOptions(ApiClientOptions baseOn)
|
public ApiClientOptions(ApiClientOptions baseOptions, RestApiClientOptions? newValues)
|
||||||
{
|
{
|
||||||
Copy(this, baseOn);
|
BaseAddress = newValues?.BaseAddress ?? baseOptions.BaseAddress;
|
||||||
|
ApiCredentials = newValues?.ApiCredentials?.Copy() ?? baseOptions.ApiCredentials?.Copy();
|
||||||
}
|
}
|
||||||
#pragma warning restore 8618
|
#pragma warning restore 8618
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Copy the values of the def to the input
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T"></typeparam>
|
|
||||||
/// <param name="input"></param>
|
|
||||||
/// <param name="def"></param>
|
|
||||||
public void Copy<T>(T input, T def) where T : ApiClientOptions
|
|
||||||
{
|
|
||||||
if (def.BaseAddress != null)
|
|
||||||
input.BaseAddress = def.BaseAddress;
|
|
||||||
input.ApiCredentials = def.ApiCredentials?.Copy();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
@ -304,26 +318,12 @@ namespace CryptoExchange.Net.Objects
|
|||||||
/// ctor
|
/// ctor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="baseOn">Copy values for the provided options</param>
|
/// <param name="baseOn">Copy values for the provided options</param>
|
||||||
public RestApiClientOptions(RestApiClientOptions baseOn)
|
public RestApiClientOptions(RestApiClientOptions baseOn, RestApiClientOptions newValues): base(baseOn, newValues)
|
||||||
{
|
{
|
||||||
Copy(this, baseOn);
|
RateLimitingBehaviour = newValues?.RateLimitingBehaviour ?? baseOn.RateLimitingBehaviour;
|
||||||
}
|
AutoTimestamp = newValues?.AutoTimestamp ?? baseOn.AutoTimestamp;
|
||||||
|
TimestampRecalculationInterval = newValues?.TimestampRecalculationInterval ?? baseOn.TimestampRecalculationInterval;
|
||||||
/// <summary>
|
RateLimiters = newValues?.RateLimiters.ToList() ?? baseOn?.RateLimiters.ToList() ?? new List<IRateLimiter>();
|
||||||
/// Copy the values of the def to the input
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T"></typeparam>
|
|
||||||
/// <param name="input"></param>
|
|
||||||
/// <param name="def"></param>
|
|
||||||
public new void Copy<T>(T input, T def) where T : RestApiClientOptions
|
|
||||||
{
|
|
||||||
base.Copy(input, def);
|
|
||||||
|
|
||||||
if(def.RateLimiters != null)
|
|
||||||
input.RateLimiters = def.RateLimiters.ToList();
|
|
||||||
input.RateLimitingBehaviour = def.RateLimitingBehaviour;
|
|
||||||
input.AutoTimestamp = def.AutoTimestamp;
|
|
||||||
input.TimestampRecalculationInterval = def.TimestampRecalculationInterval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user