Skip to content

Commit

Permalink
Update CryptoExchange.Net version to 8.5.0, added SetOptions on clien…
Browse files Browse the repository at this point in the history
…ts, added setting of DefaultProxyCredentials to CredentialCache.DefaultCredentials on the DI http client, improved websocket disconnect detection, updated dotnet versions to 9.0
  • Loading branch information
JKorf authored Dec 23, 2024
1 parent a803049 commit 0bcdc3c
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion CoinEx.Net.UnitTests/CoinEx.Net.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ApplicationIcon />
<StartupObject />
</PropertyGroup>
Expand Down
9 changes: 9 additions & 0 deletions CoinEx.Net/Clients/CoinExRestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -51,6 +52,14 @@ public CoinExRestClient(HttpClient? httpClient, ILoggerFactory? loggerFactory, I
#endregion

#region methods
/// <inheritdoc />
public void SetOptions(UpdateOptions options)
{
FuturesApi.SetOptions(options);
SpotApi.SetOptions(options);
SpotApiV2.SetOptions(options);
}

/// <summary>
/// Set the default options to be used when creating new clients
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions CoinEx.Net/Clients/CoinExSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -59,6 +60,14 @@ public static void SetDefaultOptions(Action<CoinExSocketOptions> optionsDelegate
CoinExSocketOptions.Default = ApplyOptionsDelegate(optionsDelegate);
}

/// <inheritdoc />
public void SetOptions(UpdateOptions options)
{
FuturesApi.SetOptions(options);
SpotApi.SetOptions(options);
SpotApiV2.SetOptions(options);
}

/// <inheritdoc />
public void SetApiCredentials(ApiCredentials credentials)
{
Expand Down
14 changes: 13 additions & 1 deletion CoinEx.Net/Clients/FuturesApi/CoinExSocketClientFuturesApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, object>())), null);
RegisterPeriodicQuery(
"Ping",
TimeSpan.FromSeconds(30),
q => new CoinExQuery("server.ping", new Dictionary<string, object>()) { 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

Expand Down
14 changes: 13 additions & 1 deletion CoinEx.Net/Clients/SpotApiV2/CoinExSocketClientSpotApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, object>())), null);
RegisterPeriodicQuery(
"Ping",
TimeSpan.FromSeconds(30),
q => new CoinExQuery("server.ping", new Dictionary<string, object>()) { 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

Expand Down
2 changes: 1 addition & 1 deletion CoinEx.Net/CoinEx.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="CryptoExchange.Net" Version="8.4.4" />
<PackageReference Include="Crc32.NET" Version="1.2.0" />
<PackageReference Include="CryptoExchange.Net" Version="8.5.0" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
18 changes: 18 additions & 0 deletions CoinEx.Net/CoinEx.Net.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions CoinEx.Net/ExtensionMethods/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ private static IServiceCollection AddCoinExCore(
try
{
handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
handler.DefaultProxyCredentials = CredentialCache.DefaultCredentials;
}
catch (PlatformNotSupportedException)
{ }
Expand Down
7 changes: 7 additions & 0 deletions CoinEx.Net/Interfaces/Clients/ICoinExRestClient.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -22,6 +23,12 @@ public interface ICoinExRestClient : IRestClient
/// </summary>
ICoinExRestClientFuturesApi FuturesApi { get; }

/// <summary>
/// Update specific options
/// </summary>
/// <param name="options">Options to update. Only specific options are changable after the client has been created</param>
void SetOptions(UpdateOptions options);

/// <summary>
/// Set the API credentials for this client. All Api clients in this client will use the new credentials, regardless of earlier set options.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions CoinEx.Net/Interfaces/Clients/ICoinExSocketClient.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -22,6 +23,12 @@ public interface ICoinExSocketClient : ISocketClient
/// </summary>
public SpotApiV1.ICoinExSocketClientSpotApi SpotApi { get; }

/// <summary>
/// Update specific options
/// </summary>
/// <param name="options">Options to update. Only specific options are changable after the client has been created</param>
void SetOptions(UpdateOptions options);

/// <summary>
/// Set the API credentials for this client. All Api clients in this client will use the new credentials, regardless of earlier set options.
/// </summary>
Expand Down

0 comments on commit 0bcdc3c

Please sign in to comment.