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 committed Dec 23, 2024
1 parent 4291deb commit a7e875f
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
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@v3
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 OKX.Net.UnitTests/OKX.Net.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>

Expand Down
9 changes: 7 additions & 2 deletions OKX.Net/Clients/OKXRestClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CryptoExchange.Net.Clients;
using CryptoExchange.Net.Objects.Options;
using Microsoft.Extensions.Options;
using OKX.Net.Clients.UnifiedApi;
using OKX.Net.Interfaces.Clients;
Expand Down Expand Up @@ -43,7 +44,12 @@ public OKXRestClient(HttpClient? httpClient, ILoggerFactory? loggerFactory, IOpt
}
#endregion

#region Common Methods
/// <inheritdoc />
public void SetOptions(UpdateOptions options)
{
UnifiedApi.SetOptions(options);
}

/// <summary>
/// Sets the default options to use for new clients
/// </summary>
Expand All @@ -61,5 +67,4 @@ public void SetApiCredentials(OKXApiCredentials credentials)
{
UnifiedApi.SetApiCredentials(credentials);
}
#endregion
}
10 changes: 7 additions & 3 deletions OKX.Net/Clients/OKXSocketClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CryptoExchange.Net.Clients;
using CryptoExchange.Net.Objects.Options;
using Microsoft.Extensions.Options;
using OKX.Net.Clients.UnifiedApi;
using OKX.Net.Interfaces.Clients;
Expand Down Expand Up @@ -40,7 +41,12 @@ public OKXSocketClient(IOptions<OKXSocketOptions> options, ILoggerFactory? logge
}
#endregion

#region Common Methods
/// <inheritdoc />
public void SetOptions(UpdateOptions options)
{
UnifiedApi.SetOptions(options);
}

/// <summary>
/// Set default options
/// </summary>
Expand All @@ -55,6 +61,4 @@ public virtual void SetApiCredentials(OKXApiCredentials credentials)
{
UnifiedApi.SetApiCredentials(credentials.Copy());
}

#endregion
}
14 changes: 13 additions & 1 deletion OKX.Net/Clients/UnifiedApi/OKXSocketClientUnifiedApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,19 @@ internal OKXSocketClientUnifiedApi(ILogger logger, OKXSocketOptions options) :

_demoTrading = options.Environment.Name == TradeEnvironmentNames.Testnet;

RegisterPeriodicQuery("Ping", TimeSpan.FromSeconds(20), x => new OKXPingQuery(), null);
RegisterPeriodicQuery(
"Ping",
TimeSpan.FromSeconds(20),
x => new OKXPingQuery(),
(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();
}
});

SetDedicatedConnection(GetUri("/ws/v5/private"), true);
}
Expand Down
1 change: 1 addition & 0 deletions OKX.Net/ExtensionMethods/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ private static IServiceCollection AddOKXCore(
try
{
handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
handler.DefaultProxyCredentials = CredentialCache.DefaultCredentials;
}
catch (PlatformNotSupportedException)
{ }
Expand Down
9 changes: 8 additions & 1 deletion OKX.Net/Interfaces/Clients/IOKXRestClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OKX.Net.Interfaces.Clients.UnifiedApi;
using CryptoExchange.Net.Objects.Options;
using OKX.Net.Interfaces.Clients.UnifiedApi;
using OKX.Net.Objects;

namespace OKX.Net.Interfaces.Clients;
Expand All @@ -13,6 +14,12 @@ public interface IOKXRestClient: IRestClient
/// </summary>
IOKXRestClientUnifiedApi UnifiedApi { 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
9 changes: 8 additions & 1 deletion OKX.Net/Interfaces/Clients/IOKXSocketClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OKX.Net.Interfaces.Clients.UnifiedApi;
using CryptoExchange.Net.Objects.Options;
using OKX.Net.Interfaces.Clients.UnifiedApi;
using OKX.Net.Objects;

namespace OKX.Net.Interfaces.Clients;
Expand All @@ -13,6 +14,12 @@ public interface IOKXSocketClient : ISocketClient
/// </summary>
IOKXSocketClientUnifiedApi UnifiedApi { 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
2 changes: 1 addition & 1 deletion OKX.Net/OKX.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="CryptoExchange.Net" Version="8.4.4" />
<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 OKX.Net/OKX.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 OKX.Net/Objects/Sockets/Queries/OKXPingQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ internal class OKXPingQuery : Query<string>

public OKXPingQuery() : base("ping", false, 0)
{
RequestTimeout = TimeSpan.FromSeconds(5);
}
}

0 comments on commit a7e875f

Please sign in to comment.