diff --git a/GateIo.Net.UnitTests/GateIoRestClientTests.cs b/GateIo.Net.UnitTests/GateIoRestClientTests.cs index e578c0e..3ed63b2 100644 --- a/GateIo.Net.UnitTests/GateIoRestClientTests.cs +++ b/GateIo.Net.UnitTests/GateIoRestClientTests.cs @@ -6,6 +6,10 @@ using System.Net.Http; using GateIo.Net.Clients; using GateIo.Net; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using GateIo.Net.Interfaces.Clients; +using CryptoExchange.Net.Objects; namespace Gate.io.Net.UnitTests { @@ -43,5 +47,103 @@ public void CheckInterfaces() CryptoExchange.Net.Testing.TestHelpers.CheckForMissingRestInterfaces(); CryptoExchange.Net.Testing.TestHelpers.CheckForMissingSocketInterfaces(); } + + [Test] + [TestCase(TradeEnvironmentNames.Live, "https://api.gateio.ws")] + [TestCase("", "https://api.gateio.ws")] + public void TestConstructorEnvironments(string environmentName, string expected) + { + var configuration = new ConfigurationBuilder() + .AddInMemoryCollection(new Dictionary + { + { "GateIo:Environment:Name", environmentName }, + }).Build(); + + var collection = new ServiceCollection(); + collection.AddGateIo(configuration.GetSection("GateIo")); + var provider = collection.BuildServiceProvider(); + + var client = provider.GetRequiredService(); + + var address = client.SpotApi.BaseAddress; + + Assert.That(address, Is.EqualTo(expected)); + } + + [Test] + public void TestConstructorNullEnvironment() + { + var configuration = new ConfigurationBuilder() + .AddInMemoryCollection(new Dictionary + { + { "GateIo", null }, + }).Build(); + + var collection = new ServiceCollection(); + collection.AddGateIo(configuration.GetSection("GateIo")); + var provider = collection.BuildServiceProvider(); + + var client = provider.GetRequiredService(); + + var address = client.SpotApi.BaseAddress; + + Assert.That(address, Is.EqualTo("https://api.gateio.ws")); + } + + [Test] + public void TestConstructorApiOverwriteEnvironment() + { + var configuration = new ConfigurationBuilder() + .AddInMemoryCollection(new Dictionary + { + { "GateIo:Environment:Name", "test" }, + { "GateIo:Rest:Environment:Name", "live" }, + }).Build(); + + var collection = new ServiceCollection(); + collection.AddGateIo(configuration.GetSection("GateIo")); + var provider = collection.BuildServiceProvider(); + + var client = provider.GetRequiredService(); + + var address = client.SpotApi.BaseAddress; + + Assert.That(address, Is.EqualTo("https://api.gateio.ws")); + } + + [Test] + public void TestConstructorConfiguration() + { + var configuration = new ConfigurationBuilder() + .AddInMemoryCollection(new Dictionary + { + { "ApiCredentials:Key", "123" }, + { "ApiCredentials:Secret", "456" }, + { "Socket:ApiCredentials:Key", "456" }, + { "Socket:ApiCredentials:Secret", "789" }, + { "Rest:OutputOriginalData", "true" }, + { "Socket:OutputOriginalData", "false" }, + { "Rest:Proxy:Host", "host" }, + { "Rest:Proxy:Port", "80" }, + { "Socket:Proxy:Host", "host2" }, + { "Socket:Proxy:Port", "81" }, + }).Build(); + + var collection = new ServiceCollection(); + collection.AddGateIo(configuration); + var provider = collection.BuildServiceProvider(); + + var restClient = provider.GetRequiredService(); + var socketClient = provider.GetRequiredService(); + + Assert.That(((BaseApiClient)restClient.SpotApi).OutputOriginalData, Is.True); + Assert.That(((BaseApiClient)socketClient.SpotApi).OutputOriginalData, Is.False); + Assert.That(((BaseApiClient)restClient.SpotApi).AuthenticationProvider.ApiKey, Is.EqualTo("123")); + Assert.That(((BaseApiClient)socketClient.SpotApi).AuthenticationProvider.ApiKey, Is.EqualTo("456")); + Assert.That(((BaseApiClient)restClient.SpotApi).ClientOptions.Proxy.Host, Is.EqualTo("host")); + Assert.That(((BaseApiClient)restClient.SpotApi).ClientOptions.Proxy.Port, Is.EqualTo(80)); + Assert.That(((BaseApiClient)socketClient.SpotApi).ClientOptions.Proxy.Host, Is.EqualTo("host2")); + Assert.That(((BaseApiClient)socketClient.SpotApi).ClientOptions.Proxy.Port, Is.EqualTo(81)); + } } } diff --git a/GateIo.Net.UnitTests/GateIoRestIntegrationTests.cs b/GateIo.Net.UnitTests/GateIoRestIntegrationTests.cs index 9712e82..2b3a0aa 100644 --- a/GateIo.Net.UnitTests/GateIoRestIntegrationTests.cs +++ b/GateIo.Net.UnitTests/GateIoRestIntegrationTests.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using Microsoft.Extensions.Options; namespace GateIo.Net.UnitTests { @@ -27,11 +28,11 @@ public override GateIoRestClient GetClient(ILoggerFactory loggerFactory) var sec = Environment.GetEnvironmentVariable("APISECRET"); Authenticated = key != null && sec != null; - return new GateIoRestClient(null, loggerFactory, opts => + return new GateIoRestClient(null, loggerFactory, Options.Create(new Objects.Options.GateIoRestOptions { - opts.OutputOriginalData = true; - opts.ApiCredentials = Authenticated ? new ApiCredentials(key, sec) : null; - }); + OutputOriginalData = true, + ApiCredentials = Authenticated ? new ApiCredentials(key, sec) : null + })); } [Test] diff --git a/GateIo.Net/Clients/GateIoRestClient.cs b/GateIo.Net/Clients/GateIoRestClient.cs index cf90d1e..0c12d6f 100644 --- a/GateIo.Net/Clients/GateIoRestClient.cs +++ b/GateIo.Net/Clients/GateIoRestClient.cs @@ -9,6 +9,7 @@ using GateIo.Net.Clients.FuturesApi; using CryptoExchange.Net.Clients; using GateIo.Net.Interfaces.Clients.PerpetualFuturesApi; +using Microsoft.Extensions.Options; namespace GateIo.Net.Clients { @@ -30,25 +31,23 @@ public class GateIoRestClient : BaseRestClient, IGateIoRestClient /// Create a new instance of the GateIoRestClient using provided options /// /// Option configuration delegate - public GateIoRestClient(Action? optionsDelegate = null) : this(null, null, optionsDelegate) + public GateIoRestClient(Action? optionsDelegate = null) + : this(null, null, Options.Create(ApplyOptionsDelegate(optionsDelegate))) { } /// /// Create a new instance of the GateIoRestClient using provided options /// - /// Option configuration delegate + /// Option configuration delegate /// The logger factory /// Http client for this client - public GateIoRestClient(HttpClient? httpClient, ILoggerFactory? loggerFactory, Action? optionsDelegate = null) : base(loggerFactory, "GateIo") + public GateIoRestClient(HttpClient? httpClient, ILoggerFactory? loggerFactory, IOptions options) : base(loggerFactory, "GateIo") { - var options = GateIoRestOptions.Default.Copy(); - if (optionsDelegate != null) - optionsDelegate(options); - Initialize(options); + Initialize(options.Value); - SpotApi = AddApiClient(new GateIoRestClientSpotApi(_logger, httpClient, options)); - PerpetualFuturesApi = AddApiClient(new GateIoRestClientPerpetualFuturesApi(_logger, httpClient, options)); + SpotApi = AddApiClient(new GateIoRestClientSpotApi(_logger, httpClient, options.Value)); + PerpetualFuturesApi = AddApiClient(new GateIoRestClientPerpetualFuturesApi(_logger, httpClient, options.Value)); } #endregion @@ -59,9 +58,7 @@ public GateIoRestClient(HttpClient? httpClient, ILoggerFactory? loggerFactory, A /// Option configuration delegate public static void SetDefaultOptions(Action optionsDelegate) { - var options = GateIoRestOptions.Default.Copy(); - optionsDelegate(options); - GateIoRestOptions.Default = options; + GateIoRestOptions.Default = ApplyOptionsDelegate(optionsDelegate); } /// diff --git a/GateIo.Net/Clients/GateIoSocketClient.cs b/GateIo.Net/Clients/GateIoSocketClient.cs index 103b50d..63cef3a 100644 --- a/GateIo.Net/Clients/GateIoSocketClient.cs +++ b/GateIo.Net/Clients/GateIoSocketClient.cs @@ -8,6 +8,7 @@ using GateIo.Net.Interfaces.Clients.SpotApi; using GateIo.Net.Objects.Options; using GateIo.Net.Interfaces.Clients.PerpetualFuturesApi; +using Microsoft.Extensions.Options; namespace GateIo.Net.Clients { @@ -28,19 +29,13 @@ public class GateIoSocketClient : BaseSocketClient, IGateIoSocketClient #endregion #region constructor/destructor - /// - /// Create a new instance of GateIoSocketClient - /// - /// The logger factory - public GateIoSocketClient(ILoggerFactory? loggerFactory = null) : this((x) => { }, loggerFactory) - { - } /// /// Create a new instance of GateIoSocketClient /// /// Option configuration delegate - public GateIoSocketClient(Action optionsDelegate) : this(optionsDelegate, null) + public GateIoSocketClient(Action? optionsDelegate = null) + : this(Options.Create(ApplyOptionsDelegate(optionsDelegate)), null) { } @@ -48,15 +43,13 @@ public GateIoSocketClient(Action optionsDelegate) : this(op /// Create a new instance of GateIoSocketClient /// /// The logger factory - /// Option configuration delegate - public GateIoSocketClient(Action? optionsDelegate, ILoggerFactory? loggerFactory = null) : base(loggerFactory, "GateIo") + /// Option configuration delegate + public GateIoSocketClient(IOptions options, ILoggerFactory? loggerFactory = null) : base(loggerFactory, "GateIo") { - var options = GateIoSocketOptions.Default.Copy(); - optionsDelegate?.Invoke(options); - Initialize(options); + Initialize(options.Value); - SpotApi = AddApiClient(new GateIoSocketClientSpotApi(_logger, options)); - PerpetualFuturesApi = AddApiClient(new GateIoSocketClientPerpetualFuturesApi(_logger, options)); + SpotApi = AddApiClient(new GateIoSocketClientSpotApi(_logger, options.Value)); + PerpetualFuturesApi = AddApiClient(new GateIoSocketClientPerpetualFuturesApi(_logger, options.Value)); } #endregion @@ -66,9 +59,7 @@ public GateIoSocketClient(Action? optionsDelegate, ILoggerF /// Option configuration delegate public static void SetDefaultOptions(Action optionsDelegate) { - var options = GateIoSocketOptions.Default.Copy(); - optionsDelegate(options); - GateIoSocketOptions.Default = options; + GateIoSocketOptions.Default = ApplyOptionsDelegate(optionsDelegate); } /// diff --git a/GateIo.Net/ExtensionMethods/ServiceCollectionExtensions.cs b/GateIo.Net/ExtensionMethods/ServiceCollectionExtensions.cs index d99053c..bf2ba60 100644 --- a/GateIo.Net/ExtensionMethods/ServiceCollectionExtensions.cs +++ b/GateIo.Net/ExtensionMethods/ServiceCollectionExtensions.cs @@ -10,6 +10,9 @@ using GateIo.Net.SymbolOrderBooks; using CryptoExchange.Net; using GateIo.Net; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Microsoft.Extensions.Configuration; namespace Microsoft.Extensions.DependencyInjection { @@ -18,47 +21,114 @@ namespace Microsoft.Extensions.DependencyInjection /// public static class ServiceCollectionExtensions { + /// - /// Add the IGateIoClient and IGateIoSocketClient to the sevice collection so they can be injected + /// Add services such as the IGateIoRestClient and IGateIoSocketClient. Configures the services based on the provided configuration. /// /// The service collection - /// Set default options for the rest client - /// Set default options for the socket client - /// The lifetime of the IGateIoSocketClient for the service collection. Defaults to Singleton. + /// The configuration(section) containing the options /// public static IServiceCollection AddGateIo( this IServiceCollection services, - Action? defaultRestOptionsDelegate = null, - Action? defaultSocketOptionsDelegate = null, - ServiceLifetime? socketClientLifeTime = null) + IConfiguration configuration) { - var restOptions = GateIoRestOptions.Default.Copy(); + var options = new GateIoOptions(); + // Reset environment so we know if theyre overriden + options.Rest.Environment = null!; + options.Socket.Environment = null!; + configuration.Bind(options); - if (defaultRestOptionsDelegate != null) - { - defaultRestOptionsDelegate(restOptions); - GateIoRestClient.SetDefaultOptions(defaultRestOptionsDelegate); - } + if (options.Rest == null || options.Socket == null) + throw new ArgumentException("Options null"); - if (defaultSocketOptionsDelegate != null) - GateIoSocketClient.SetDefaultOptions(defaultSocketOptionsDelegate); + var restEnvName = options.Rest.Environment?.Name ?? options.Environment?.Name ?? GateIoEnvironment.Live.Name; + var socketEnvName = options.Socket.Environment?.Name ?? options.Environment?.Name ?? GateIoEnvironment.Live.Name; + options.Rest.Environment = GateIoEnvironment.GetEnvironmentByName(restEnvName) ?? options.Rest.Environment!; + options.Rest.ApiCredentials = options.Rest.ApiCredentials ?? options.ApiCredentials; + options.Socket.Environment = GateIoEnvironment.GetEnvironmentByName(socketEnvName) ?? options.Socket.Environment!; + options.Socket.ApiCredentials = options.Socket.ApiCredentials ?? options.ApiCredentials; - services.AddHttpClient(options => - { - options.Timeout = restOptions.RequestTimeout; - }).ConfigurePrimaryHttpMessageHandler(() => + + services.AddSingleton(x => Options.Options.Create(options.Rest)); + services.AddSingleton(x => Options.Options.Create(options.Socket)); + + return AddGateIoCore(services, options.SocketClientLifeTime); + } + + /// + /// Add services such as the IGateIoRestClient and IGateIoSocketClient. Services will be configured based on the provided options. + /// + /// The service collection + /// Set options for the GateIo services + /// + public static IServiceCollection AddGateIo( + this IServiceCollection services, + Action? optionsDelegate = null) + { + var options = new GateIoOptions(); + // Reset environment so we know if theyre overriden + options.Rest.Environment = null!; + options.Socket.Environment = null!; + optionsDelegate?.Invoke(options); + if (options.Rest == null || options.Socket == null) + throw new ArgumentException("Options null"); + + options.Rest.Environment = options.Rest.Environment ?? options.Environment ?? GateIoEnvironment.Live; + options.Rest.ApiCredentials = options.Rest.ApiCredentials ?? options.ApiCredentials; + options.Socket.Environment = options.Socket.Environment ?? options.Environment ?? GateIoEnvironment.Live; + options.Socket.ApiCredentials = options.Socket.ApiCredentials ?? options.ApiCredentials; + + services.AddSingleton(x => Options.Options.Create(options.Rest)); + services.AddSingleton(x => Options.Options.Create(options.Socket)); + + return AddGateIoCore(services, options.SocketClientLifeTime); + } + + /// + /// DEPRECATED; use instead + /// + public static IServiceCollection AddGateIo( + this IServiceCollection services, + Action restDelegate, + Action? socketDelegate = null, + ServiceLifetime? socketClientLifeTime = null) + { + services.Configure((x) => { restDelegate?.Invoke(x); }); + services.Configure((x) => { socketDelegate?.Invoke(x); }); + + return AddGateIoCore(services, socketClientLifeTime); + } + + private static IServiceCollection AddGateIoCore( + this IServiceCollection services, + ServiceLifetime? socketClientLifeTime = null) + { + services.AddHttpClient((client, serviceProvider) => { + var options = serviceProvider.GetRequiredService>().Value; + client.Timeout = options.RequestTimeout; + return new GateIoRestClient(client, serviceProvider.GetRequiredService(), serviceProvider.GetRequiredService>()); + }).ConfigurePrimaryHttpMessageHandler((serviceProvider) => { var handler = new HttpClientHandler(); - if (restOptions.Proxy != null) + try + { + handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; + } + catch (PlatformNotSupportedException) + { } + + var options = serviceProvider.GetRequiredService>().Value; + if (options.Proxy != null) { handler.Proxy = new WebProxy { - Address = new Uri($"{restOptions.Proxy.Host}:{restOptions.Proxy.Port}"), - Credentials = restOptions.Proxy.Password == null ? null : new NetworkCredential(restOptions.Proxy.Login, restOptions.Proxy.Password) + Address = new Uri($"{options.Proxy.Host}:{options.Proxy.Port}"), + Credentials = options.Proxy.Password == null ? null : new NetworkCredential(options.Proxy.Login, options.Proxy.Password) }; } return handler; }); + services.Add(new ServiceDescriptor(typeof(IGateIoSocketClient), x => { return new GateIoSocketClient(x.GetRequiredService>(), x.GetRequiredService()); }, socketClientLifeTime ?? ServiceLifetime.Singleton)); services.AddTransient(); services.AddSingleton(); @@ -71,10 +141,6 @@ public static IServiceCollection AddGateIo( services.RegisterSharedRestInterfaces(x => x.GetRequiredService().PerpetualFuturesApi.SharedClient); services.RegisterSharedSocketInterfaces(x => x.GetRequiredService().PerpetualFuturesApi.SharedClient); - if (socketClientLifeTime == null) - services.AddSingleton(); - else - services.Add(new ServiceDescriptor(typeof(IGateIoSocketClient), typeof(GateIoSocketClient), socketClientLifeTime.Value)); return services; } } diff --git a/GateIo.Net/GateIo.Net.csproj b/GateIo.Net/GateIo.Net.csproj index c7bf332..5f28143 100644 --- a/GateIo.Net/GateIo.Net.csproj +++ b/GateIo.Net/GateIo.Net.csproj @@ -48,10 +48,12 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - all runtime; build; native; contentfiles; analyzers; buildtransitive + + + \ No newline at end of file diff --git a/GateIo.Net/GateIo.Net.xml b/GateIo.Net/GateIo.Net.xml index 010b3f0..1626d14 100644 --- a/GateIo.Net/GateIo.Net.xml +++ b/GateIo.Net/GateIo.Net.xml @@ -305,11 +305,11 @@ Option configuration delegate - + Create a new instance of the GateIoRestClient using provided options - Option configuration delegate + Option configuration delegate The logger factory Http client for this client @@ -331,24 +331,18 @@ - - - Create a new instance of GateIoSocketClient - - The logger factory - Create a new instance of GateIoSocketClient Option configuration delegate - + Create a new instance of GateIoSocketClient The logger factory - Option configuration delegate + Option configuration delegate @@ -1735,6 +1729,16 @@ Socket API futures address + + + ctor for DI, use for creating a custom environment + + + + + Get the GateIo environment by name + + Live environment @@ -9889,6 +9893,36 @@ Percentage withdrawal fee on multiple networks + + + GateIo options + + + + + Rest client options + + + + + Socket client options + + + + + Trade environment. Contains info about URL's to use to connect to the API. Use `GateIoEnvironment` to swap environment, for example `Environment = GateIoEnvironment.Live` + + + + + The api credentials used for signing requests. + + + + + The DI service lifetime for the IGateIoSocketClient + + Options for the GateIo SymbolOrderBook @@ -9924,6 +9958,11 @@ Default options for new clients + + + ctor + + Broker id @@ -9949,6 +9988,11 @@ Default options for new clients + + + ctor + + Broker id @@ -10092,15 +10136,26 @@ Extensions for DI - + + + Add services such as the IGateIoRestClient and IGateIoSocketClient. Configures the services based on the provided configuration. + + The service collection + The configuration(section) containing the options + + + - Add the IGateIoClient and IGateIoSocketClient to the sevice collection so they can be injected + Add services such as the IGateIoRestClient and IGateIoSocketClient. Services will be configured based on the provided options. The service collection - Set default options for the rest client - Set default options for the socket client - The lifetime of the IGateIoSocketClient for the service collection. Defaults to Singleton. + Set options for the GateIo services + + + DEPRECATED; use instead + + diff --git a/GateIo.Net/GateIoEnvironment.cs b/GateIo.Net/GateIoEnvironment.cs index 921c95c..d72e902 100644 --- a/GateIo.Net/GateIoEnvironment.cs +++ b/GateIo.Net/GateIoEnvironment.cs @@ -35,6 +35,26 @@ internal GateIoEnvironment( FuturesSocketClientAddress = futuresWebsocketAddress; } + /// + /// ctor for DI, use for creating a custom environment + /// +#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. + public GateIoEnvironment() : base(TradeEnvironmentNames.Live) +#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. + { } + + /// + /// Get the GateIo environment by name + /// + public static GateIoEnvironment? GetEnvironmentByName(string? name) + => name switch + { + TradeEnvironmentNames.Live => Live, + "" => Live, + null => Live, + _ => default + }; + /// /// Live environment /// diff --git a/GateIo.Net/Objects/Options/GateIoOptions.cs b/GateIo.Net/Objects/Options/GateIoOptions.cs new file mode 100644 index 0000000..776ffdb --- /dev/null +++ b/GateIo.Net/Objects/Options/GateIoOptions.cs @@ -0,0 +1,39 @@ +using CryptoExchange.Net.Authentication; +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Generic; +using System.Text; + +namespace GateIo.Net.Objects.Options +{ + /// + /// GateIo options + /// + public class GateIoOptions + { + /// + /// Rest client options + /// + public GateIoRestOptions Rest { get; set; } = new GateIoRestOptions(); + + /// + /// Socket client options + /// + public GateIoSocketOptions Socket { get; set; } = new GateIoSocketOptions(); + + /// + /// Trade environment. Contains info about URL's to use to connect to the API. Use `GateIoEnvironment` to swap environment, for example `Environment = GateIoEnvironment.Live` + /// + public GateIoEnvironment? Environment { get; set; } + + /// + /// The api credentials used for signing requests. + /// + public ApiCredentials? ApiCredentials { get; set; } + + /// + /// The DI service lifetime for the IGateIoSocketClient + /// + public ServiceLifetime? SocketClientLifeTime { get; set; } + } +} diff --git a/GateIo.Net/Objects/Options/GateIoRestOptions.cs b/GateIo.Net/Objects/Options/GateIoRestOptions.cs index 1313547..1f2e53d 100644 --- a/GateIo.Net/Objects/Options/GateIoRestOptions.cs +++ b/GateIo.Net/Objects/Options/GateIoRestOptions.cs @@ -10,12 +10,20 @@ public class GateIoRestOptions : RestExchangeOptions /// /// Default options for new clients /// - public static GateIoRestOptions Default { get; set; } = new GateIoRestOptions() + internal static GateIoRestOptions Default { get; set; } = new GateIoRestOptions() { Environment = GateIoEnvironment.Live, AutoTimestamp = true }; + /// + /// ctor + /// + public GateIoRestOptions() + { + Default?.Set(this); + } + /// /// Broker id /// @@ -33,13 +41,13 @@ public class GateIoRestOptions : RestExchangeOptions /// public RestApiOptions PerpetualFuturesOptions { get; private set; } = new RestApiOptions(); - internal GateIoRestOptions Copy() + internal GateIoRestOptions Set(GateIoRestOptions targetOptions) { - var options = Copy(); - options.BrokerId = BrokerId; - options.SpotOptions = SpotOptions.Copy(); - options.PerpetualFuturesOptions = PerpetualFuturesOptions.Copy(); - return options; + targetOptions = base.Set(targetOptions); + targetOptions.BrokerId = BrokerId; + targetOptions.SpotOptions = SpotOptions.Set(targetOptions.SpotOptions); + targetOptions.PerpetualFuturesOptions = PerpetualFuturesOptions.Set(targetOptions.PerpetualFuturesOptions); + return targetOptions; } } } diff --git a/GateIo.Net/Objects/Options/GateIoSocketOptions.cs b/GateIo.Net/Objects/Options/GateIoSocketOptions.cs index 69bd799..9bc0849 100644 --- a/GateIo.Net/Objects/Options/GateIoSocketOptions.cs +++ b/GateIo.Net/Objects/Options/GateIoSocketOptions.cs @@ -10,13 +10,21 @@ public class GateIoSocketOptions : SocketExchangeOptions /// /// Default options for new clients /// - public static GateIoSocketOptions Default { get; set; } = new GateIoSocketOptions() + internal static GateIoSocketOptions Default { get; set; } = new GateIoSocketOptions() { Environment = GateIoEnvironment.Live, SocketSubscriptionsCombineTarget = 10, MaxSocketConnections = 300 }; + /// + /// ctor + /// + public GateIoSocketOptions() + { + Default?.Set(this); + } + /// /// Broker id /// @@ -34,13 +42,13 @@ public class GateIoSocketOptions : SocketExchangeOptions /// public SocketApiOptions PerpetualFuturesOptions { get; private set; } = new SocketApiOptions(); - internal GateIoSocketOptions Copy() + internal GateIoSocketOptions Set(GateIoSocketOptions targetOptions) { - var options = Copy(); - options.BrokerId = BrokerId; - options.SpotOptions = SpotOptions.Copy(); - options.PerpetualFuturesOptions = PerpetualFuturesOptions.Copy(); - return options; + targetOptions = base.Set(targetOptions); + targetOptions.BrokerId = BrokerId; + targetOptions.SpotOptions = SpotOptions.Set(targetOptions.SpotOptions); + targetOptions.PerpetualFuturesOptions = PerpetualFuturesOptions.Set(targetOptions.PerpetualFuturesOptions); + return targetOptions; } } }