From 0441c53bad026805c226a0a243d3713ac2d9fedb Mon Sep 17 00:00:00 2001 From: Jkorf Date: Thu, 5 Dec 2024 16:20:12 +0100 Subject: [PATCH 1/2] wip --- CoinEx.Net/Clients/CoinExRestClient.cs | 9 +++++++++ CoinEx.Net/Clients/CoinExSocketClient.cs | 9 +++++++++ CoinEx.Net/CoinEx.Net.csproj | 4 +++- CoinEx.Net/CoinEx.Net.xml | 18 ++++++++++++++++++ .../Interfaces/Clients/ICoinExRestClient.cs | 7 +++++++ .../Interfaces/Clients/ICoinExSocketClient.cs | 7 +++++++ 6 files changed, 53 insertions(+), 1 deletion(-) diff --git a/CoinEx.Net/Clients/CoinExRestClient.cs b/CoinEx.Net/Clients/CoinExRestClient.cs index 06cf80b..f605c6d 100644 --- a/CoinEx.Net/Clients/CoinExRestClient.cs +++ b/CoinEx.Net/Clients/CoinExRestClient.cs @@ -8,6 +8,7 @@ using CoinEx.Net.Interfaces.Clients.FuturesApi; using CoinEx.Net.Clients.FuturesApi; using Microsoft.Extensions.Options; +using CryptoExchange.Net.Objects.Options; namespace CoinEx.Net.Clients { @@ -51,6 +52,14 @@ public CoinExRestClient(HttpClient? httpClient, ILoggerFactory? loggerFactory, I #endregion #region methods + /// + public void SetOptions(UpdateOptions options) + { + FuturesApi.SetOptions(options); + SpotApi.SetOptions(options); + SpotApiV2.SetOptions(options); + } + /// /// Set the default options to be used when creating new clients /// diff --git a/CoinEx.Net/Clients/CoinExSocketClient.cs b/CoinEx.Net/Clients/CoinExSocketClient.cs index 2c80004..5c76cb2 100644 --- a/CoinEx.Net/Clients/CoinExSocketClient.cs +++ b/CoinEx.Net/Clients/CoinExSocketClient.cs @@ -7,6 +7,7 @@ using CoinEx.Net.Interfaces.Clients.FuturesApi; using CoinEx.Net.Clients.FuturesApi; using Microsoft.Extensions.Options; +using CryptoExchange.Net.Objects.Options; namespace CoinEx.Net.Clients { @@ -59,6 +60,14 @@ public static void SetDefaultOptions(Action optionsDelegate CoinExSocketOptions.Default = ApplyOptionsDelegate(optionsDelegate); } + /// + public void SetOptions(UpdateOptions options) + { + FuturesApi.SetOptions(options); + SpotApi.SetOptions(options); + SpotApiV2.SetOptions(options); + } + /// public void SetApiCredentials(ApiCredentials credentials) { diff --git a/CoinEx.Net/CoinEx.Net.csproj b/CoinEx.Net/CoinEx.Net.csproj index ee0ce4e..d9ed21b 100644 --- a/CoinEx.Net/CoinEx.Net.csproj +++ b/CoinEx.Net/CoinEx.Net.csproj @@ -48,11 +48,13 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - all runtime; build; native; contentfiles; analyzers; buildtransitive + + + \ No newline at end of file diff --git a/CoinEx.Net/CoinEx.Net.xml b/CoinEx.Net/CoinEx.Net.xml index b7b879a..6a2733b 100644 --- a/CoinEx.Net/CoinEx.Net.xml +++ b/CoinEx.Net/CoinEx.Net.xml @@ -30,6 +30,9 @@ The logger factory Http client for this client + + + Set the default options to be used when creating new clients @@ -70,6 +73,9 @@ Option configuration delegate + + + @@ -2444,6 +2450,12 @@ Futures V2 API endpoints + + + Update specific options + + + Set the API credentials for this client. All Api clients in this client will use the new credentials, regardless of earlier set options. @@ -2470,6 +2482,12 @@ DEPRECATED FROM 2024/09/25, USE SpotApiV2 INSTEAD + + + Update specific options + + + Set the API credentials for this client. All Api clients in this client will use the new credentials, regardless of earlier set options. diff --git a/CoinEx.Net/Interfaces/Clients/ICoinExRestClient.cs b/CoinEx.Net/Interfaces/Clients/ICoinExRestClient.cs index 3a872d1..e96143f 100644 --- a/CoinEx.Net/Interfaces/Clients/ICoinExRestClient.cs +++ b/CoinEx.Net/Interfaces/Clients/ICoinExRestClient.cs @@ -1,6 +1,7 @@ using CoinEx.Net.Interfaces.Clients.FuturesApi; using CryptoExchange.Net.Authentication; using CryptoExchange.Net.Interfaces; +using CryptoExchange.Net.Objects.Options; namespace CoinEx.Net.Interfaces.Clients { @@ -22,6 +23,12 @@ public interface ICoinExRestClient : IRestClient /// ICoinExRestClientFuturesApi FuturesApi { get; } + /// + /// Update specific options + /// + /// + void SetOptions(UpdateOptions options); + /// /// Set the API credentials for this client. All Api clients in this client will use the new credentials, regardless of earlier set options. /// diff --git a/CoinEx.Net/Interfaces/Clients/ICoinExSocketClient.cs b/CoinEx.Net/Interfaces/Clients/ICoinExSocketClient.cs index e7de576..283edfd 100644 --- a/CoinEx.Net/Interfaces/Clients/ICoinExSocketClient.cs +++ b/CoinEx.Net/Interfaces/Clients/ICoinExSocketClient.cs @@ -1,6 +1,7 @@ using CoinEx.Net.Interfaces.Clients.FuturesApi; using CryptoExchange.Net.Authentication; using CryptoExchange.Net.Interfaces; +using CryptoExchange.Net.Objects.Options; namespace CoinEx.Net.Interfaces.Clients { @@ -22,6 +23,12 @@ public interface ICoinExSocketClient : ISocketClient /// public SpotApiV1.ICoinExSocketClientSpotApi SpotApi { get; } + /// + /// Update specific options + /// + /// + void SetOptions(UpdateOptions options); + /// /// Set the API credentials for this client. All Api clients in this client will use the new credentials, regardless of earlier set options. /// From 8a83a9fbe55a5b9e0f295e1ac7004ba9222f4b2e Mon Sep 17 00:00:00 2001 From: Jkorf Date: Mon, 23 Dec 2024 15:01:12 +0100 Subject: [PATCH 2/2] Update CryptoExchange.Net version to 8.5.0, added setting of DefaultProxyCredentials to CredentialCache.DefaultCredentials on the DI http client, updated dotnet versions to 9.0 --- .github/workflows/dotnet.yml | 2 +- .github/workflows/tests.yml | 2 +- CoinEx.Net.UnitTests/CoinEx.Net.UnitTests.csproj | 2 +- .../FuturesApi/CoinExSocketClientFuturesApi.cs | 14 +++++++++++++- .../Clients/SpotApiV2/CoinExSocketClientSpotApi.cs | 14 +++++++++++++- CoinEx.Net/CoinEx.Net.csproj | 4 +--- CoinEx.Net/CoinEx.Net.xml | 4 ++-- .../ServiceCollectionExtensions.cs | 1 + CoinEx.Net/Interfaces/Clients/ICoinExRestClient.cs | 2 +- .../Interfaces/Clients/ICoinExSocketClient.cs | 2 +- 10 files changed, 35 insertions(+), 12 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index cafaa72..e156742 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -16,7 +16,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v1 with: - dotnet-version: 8.0.x + dotnet-version: 9.0.x - name: Set GitHub package source run: dotnet nuget add source --username JKorf --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/JKorf/index.json" - name: Restore dependencies diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3801845..d751ddb 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,7 +14,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v1 with: - dotnet-version: 8.0.x + dotnet-version: 9.0.x - name: Set GitHub package source run: dotnet nuget add source --username JKorf --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/JKorf/index.json" - name: Restore dependencies diff --git a/CoinEx.Net.UnitTests/CoinEx.Net.UnitTests.csproj b/CoinEx.Net.UnitTests/CoinEx.Net.UnitTests.csproj index 168fe89..3aa0630 100644 --- a/CoinEx.Net.UnitTests/CoinEx.Net.UnitTests.csproj +++ b/CoinEx.Net.UnitTests/CoinEx.Net.UnitTests.csproj @@ -2,7 +2,7 @@ Library - net8.0 + net9.0 diff --git a/CoinEx.Net/Clients/FuturesApi/CoinExSocketClientFuturesApi.cs b/CoinEx.Net/Clients/FuturesApi/CoinExSocketClientFuturesApi.cs index 086d8eb..05de106 100644 --- a/CoinEx.Net/Clients/FuturesApi/CoinExSocketClientFuturesApi.cs +++ b/CoinEx.Net/Clients/FuturesApi/CoinExSocketClientFuturesApi.cs @@ -43,7 +43,19 @@ internal partial class CoinExSocketClientFuturesApi : SocketApiClient, ICoinExSo internal CoinExSocketClientFuturesApi(ILogger logger, CoinExSocketOptions options) : base(logger, options.Environment.SocketBaseAddress, options, options.FuturesOptions) { - RegisterPeriodicQuery("Ping", TimeSpan.FromMinutes(1), q => (new CoinExQuery("server.ping", new Dictionary())), null); + RegisterPeriodicQuery( + "Ping", + TimeSpan.FromSeconds(30), + q => new CoinExQuery("server.ping", new Dictionary()) { RequestTimeout = TimeSpan.FromSeconds(5) }, + (connection, result) => + { + if (result.Error?.Message.Equals("Query timeout") == true) + { + // Ping timeout, reconnect + _logger.LogWarning("[Sckt {SocketId}] Ping response timeout, reconnecting", connection.SocketId); + _ = connection.TriggerReconnectAsync(); + } + }); } #endregion diff --git a/CoinEx.Net/Clients/SpotApiV2/CoinExSocketClientSpotApi.cs b/CoinEx.Net/Clients/SpotApiV2/CoinExSocketClientSpotApi.cs index 90296b1..dc30489 100644 --- a/CoinEx.Net/Clients/SpotApiV2/CoinExSocketClientSpotApi.cs +++ b/CoinEx.Net/Clients/SpotApiV2/CoinExSocketClientSpotApi.cs @@ -43,7 +43,19 @@ internal partial class CoinExSocketClientSpotApi : SocketApiClient, ICoinExSocke internal CoinExSocketClientSpotApi(ILogger logger, CoinExSocketOptions options) : base(logger, options.Environment.SocketBaseAddress, options, options.SpotOptions) { - RegisterPeriodicQuery("Ping", TimeSpan.FromMinutes(1), q => (new CoinExQuery("server.ping", new Dictionary())), null); + RegisterPeriodicQuery( + "Ping", + TimeSpan.FromSeconds(30), + q => new CoinExQuery("server.ping", new Dictionary()) { RequestTimeout = TimeSpan.FromSeconds(5) }, + (connection, result) => + { + if (result.Error?.Message.Equals("Query timeout") == true) + { + // Ping timeout, reconnect + _logger.LogWarning("[Sckt {SocketId}] Ping response timeout, reconnecting", connection.SocketId); + _ = connection.TriggerReconnectAsync(); + } + }); } #endregion diff --git a/CoinEx.Net/CoinEx.Net.csproj b/CoinEx.Net/CoinEx.Net.csproj index 6eff1a1..12c7d50 100644 --- a/CoinEx.Net/CoinEx.Net.csproj +++ b/CoinEx.Net/CoinEx.Net.csproj @@ -49,12 +49,10 @@ runtime; build; native; contentfiles; analyzers; buildtransitive + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - \ No newline at end of file diff --git a/CoinEx.Net/CoinEx.Net.xml b/CoinEx.Net/CoinEx.Net.xml index 6a2733b..b595bd8 100644 --- a/CoinEx.Net/CoinEx.Net.xml +++ b/CoinEx.Net/CoinEx.Net.xml @@ -2454,7 +2454,7 @@ Update specific options - + Options to update. Only specific options are changable after the client has been created @@ -2486,7 +2486,7 @@ Update specific options - + Options to update. Only specific options are changable after the client has been created diff --git a/CoinEx.Net/ExtensionMethods/ServiceCollectionExtensions.cs b/CoinEx.Net/ExtensionMethods/ServiceCollectionExtensions.cs index 903e267..309b542 100644 --- a/CoinEx.Net/ExtensionMethods/ServiceCollectionExtensions.cs +++ b/CoinEx.Net/ExtensionMethods/ServiceCollectionExtensions.cs @@ -113,6 +113,7 @@ private static IServiceCollection AddCoinExCore( try { handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; + handler.DefaultProxyCredentials = CredentialCache.DefaultCredentials; } catch (PlatformNotSupportedException) { } diff --git a/CoinEx.Net/Interfaces/Clients/ICoinExRestClient.cs b/CoinEx.Net/Interfaces/Clients/ICoinExRestClient.cs index e96143f..4cfc490 100644 --- a/CoinEx.Net/Interfaces/Clients/ICoinExRestClient.cs +++ b/CoinEx.Net/Interfaces/Clients/ICoinExRestClient.cs @@ -26,7 +26,7 @@ public interface ICoinExRestClient : IRestClient /// /// Update specific options /// - /// + /// Options to update. Only specific options are changable after the client has been created void SetOptions(UpdateOptions options); /// diff --git a/CoinEx.Net/Interfaces/Clients/ICoinExSocketClient.cs b/CoinEx.Net/Interfaces/Clients/ICoinExSocketClient.cs index 283edfd..e1b81e3 100644 --- a/CoinEx.Net/Interfaces/Clients/ICoinExSocketClient.cs +++ b/CoinEx.Net/Interfaces/Clients/ICoinExSocketClient.cs @@ -26,7 +26,7 @@ public interface ICoinExSocketClient : ISocketClient /// /// Update specific options /// - /// + /// Options to update. Only specific options are changable after the client has been created void SetOptions(UpdateOptions options); ///