Skip to content

Commit 342f89f

Browse files
authored
CryptoExchange.Net update (#47)
Updated CryptoExchange.Net to version 10.7.0 Added restClient.SpotApi.Account.SetMarginLeverageAsync endpoint Added additional Http settings to client options Updated Shared REST interfaces pagination logic Updated HttpClient registration, fixing issue of DNS changes not getting processed Fixed UserClientProvider using unconfigured HttpClient
1 parent 46391fa commit 342f89f

9 files changed

Lines changed: 444 additions & 364 deletions

GateIo.Net/Clients/FuturesApi/GateIoRestClientPerpetualFuturesApiAccount.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,6 @@ public async Task<WebCallResult<Dictionary<string, GateIoPerpFee>>> GetTradingFe
9090
}
9191

9292
#endregion
93+
9394
}
9495
}

GateIo.Net/Clients/FuturesApi/GateIoRestClientPerpetualFuturesApiShared.cs

Lines changed: 217 additions & 188 deletions
Large diffs are not rendered by default.

GateIo.Net/Clients/GateIoUserClientProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public GateIoUserClientProvider(
4242
IOptions<GateIoSocketOptions> socketOptions)
4343
{
4444
_httpClient = httpClient ?? new HttpClient();
45+
_httpClient.Timeout = restOptions.Value.RequestTimeout;
4546
_loggerFactory = loggerFactory;
4647
_restOptions = restOptions;
4748
_socketOptions = socketOptions;

GateIo.Net/Clients/SpotApi/GateIoRestClientSpotApiAccount.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,5 +1092,18 @@ public async Task<WebCallResult<GateIoInsuranceFund[]>> GetInsuranceFundHistoryA
10921092
}
10931093

10941094
#endregion
1095+
1096+
#region Set Margin Leverage
1097+
/// <inheritdoc />
1098+
public async Task<WebCallResult> SetMarginLeverageAsync(decimal leverage, string? symbol = null, CancellationToken ct = default)
1099+
{
1100+
var parameters = new ParameterCollection();
1101+
parameters.AddOptional("currency_pair", symbol);
1102+
parameters.AddString("leverage", leverage);
1103+
var request = _definitions.GetOrCreate(HttpMethod.Post, "/api/v4/margin/leverage/user_market_setting", GateIoExchange.RateLimiter.RestPrivate, 1, true);
1104+
var result = await _baseClient.SendAsync(request, parameters, ct).ConfigureAwait(false);
1105+
return result;
1106+
}
1107+
#endregion
10951108
}
10961109
}

GateIo.Net/Clients/SpotApi/GateIoRestClientSpotApiShared.cs

Lines changed: 186 additions & 172 deletions
Large diffs are not rendered by default.

GateIo.Net/ExtensionMethods/ServiceCollectionExtensions.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Microsoft.Extensions.Options;
1414
using Microsoft.Extensions.Configuration;
1515
using CryptoExchange.Net.Interfaces.Clients;
16+
using System.Threading;
1617

1718
namespace Microsoft.Extensions.DependencyInjection
1819
{
@@ -95,8 +96,8 @@ private static IServiceCollection AddGateIoCore(
9596
return new GateIoRestClient(client, serviceProvider.GetRequiredService<ILoggerFactory>(), serviceProvider.GetRequiredService<IOptions<GateIoRestOptions>>());
9697
}).ConfigurePrimaryHttpMessageHandler((serviceProvider) => {
9798
var options = serviceProvider.GetRequiredService<IOptions<GateIoRestOptions>>().Value;
98-
return LibraryHelpers.CreateHttpClientMessageHandler(options.Proxy, options.HttpKeepAliveInterval);
99-
});
99+
return LibraryHelpers.CreateHttpClientMessageHandler(options);
100+
}).SetHandlerLifetime(Timeout.InfiniteTimeSpan);
100101
services.Add(new ServiceDescriptor(typeof(IGateIoSocketClient), x => { return new GateIoSocketClient(x.GetRequiredService<IOptions<GateIoSocketOptions>>(), x.GetRequiredService<ILoggerFactory>()); }, socketClientLifeTime ?? ServiceLifetime.Singleton));
101102

102103
services.AddTransient<ICryptoRestClient, CryptoRestClient>();
@@ -106,7 +107,7 @@ private static IServiceCollection AddGateIoCore(
106107
services.AddTransient<ITrackerFactory, GateIoTrackerFactory>();
107108
services.AddSingleton<IGateIoUserClientProvider, GateIoUserClientProvider>(x =>
108109
new GateIoUserClientProvider(
109-
x.GetRequiredService<HttpClient>(),
110+
x.GetRequiredService<IHttpClientFactory>().CreateClient(typeof(IGateIoRestClient).Name),
110111
x.GetRequiredService<ILoggerFactory>(),
111112
x.GetRequiredService<IOptions<GateIoRestOptions>>(),
112113
x.GetRequiredService<IOptions<GateIoSocketOptions>>()));

GateIo.Net/GateIo.Net.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<PrivateAssets>all</PrivateAssets>
5353
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
5454
</PackageReference>
55-
<PackageReference Include="CryptoExchange.Net" Version="10.6.0" />
55+
<PackageReference Include="CryptoExchange.Net" Version="10.7.0" />
5656
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="10.0.101">
5757
<PrivateAssets>all</PrivateAssets>
5858
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

GateIo.Net/GateIo.Net.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,9 @@
691691
<member name="M:GateIo.Net.Clients.SpotApi.GateIoRestClientSpotApiAccount.GetInsuranceFundHistoryAsync(GateIo.Net.Enums.BusinessType,System.String,System.DateTime,System.DateTime,System.Nullable{System.Int32},System.Nullable{System.Int32},System.Threading.CancellationToken)">
692692
<inheritdoc />
693693
</member>
694+
<member name="M:GateIo.Net.Clients.SpotApi.GateIoRestClientSpotApiAccount.SetMarginLeverageAsync(System.Decimal,System.String,System.Threading.CancellationToken)">
695+
<inheritdoc />
696+
</member>
694697
<member name="T:GateIo.Net.Clients.SpotApi.GateIoRestClientSpotApiExchangeData">
695698
<inheritdoc />
696699
</member>
@@ -6522,6 +6525,15 @@
65226525
<param name="ct">Cancellation token</param>
65236526
<returns></returns>
65246527
</member>
6528+
<member name="M:GateIo.Net.Interfaces.Clients.SpotApi.IGateIoRestClientSpotApiAccount.SetMarginLeverageAsync(System.Decimal,System.String,System.Threading.CancellationToken)">
6529+
<summary>
6530+
Set margin leverage
6531+
<para><a href="https://www.gate.com/docs/developers/apiv4/en/#set-user-market-leverage-multiplier" /></para>
6532+
</summary>
6533+
<param name="leverage">Leverage to set</param>
6534+
<param name="symbol">Symbol</param>
6535+
<param name="ct">Cancellation token</param>
6536+
</member>
65256537
<member name="T:GateIo.Net.Interfaces.Clients.SpotApi.IGateIoRestClientSpotApiExchangeData">
65266538
<summary>
65276539
GateIo Spot exchange data endpoints. Exchange data includes market data (tickers, order books, etc) and system status.

GateIo.Net/Interfaces/Clients/SpotApi/IGateIoRestClientSpotApiAccount.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,5 +815,14 @@ Task<WebCallResult<GateIoInsuranceFund[]>> GetInsuranceFundHistoryAsync(
815815
int? page = null,
816816
int? pageSize = null,
817817
CancellationToken ct = default);
818+
819+
/// <summary>
820+
/// Set margin leverage
821+
/// <para><a href="https://www.gate.com/docs/developers/apiv4/en/#set-user-market-leverage-multiplier" /></para>
822+
/// </summary>
823+
/// <param name="leverage">Leverage to set</param>
824+
/// <param name="symbol">Symbol</param>
825+
/// <param name="ct">Cancellation token</param>
826+
Task<WebCallResult> SetMarginLeverageAsync(decimal leverage, string? symbol = null, CancellationToken ct = default);
818827
}
819828
}

0 commit comments

Comments
 (0)