Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/update options #83

Merged
merged 3 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading