Skip to content

Commit

Permalink
CryptoExchange update
Browse files Browse the repository at this point in the history
  • Loading branch information
JKorf committed Nov 28, 2024
1 parent 0432086 commit 260bc2b
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 82 deletions.
8 changes: 4 additions & 4 deletions CoinEx.Net.UnitTests/CoinEx.Net.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
</ItemGroup>

<ItemGroup>
Expand Down
42 changes: 26 additions & 16 deletions CoinEx.Net/Clients/FuturesApi/CoinExRestClientFuturesApiShared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ async Task<ExchangeWebResult<IEnumerable<SharedFuturesOrder>>> IFuturesOrderRest
}).ToArray());
}

PaginatedEndpointOptions<GetClosedOrdersRequest> IFuturesOrderRestClient.GetClosedFuturesOrdersOptions { get; } = new PaginatedEndpointOptions<GetClosedOrdersRequest>(SharedPaginationSupport.Descending, true);
PaginatedEndpointOptions<GetClosedOrdersRequest> IFuturesOrderRestClient.GetClosedFuturesOrdersOptions { get; } = new PaginatedEndpointOptions<GetClosedOrdersRequest>(SharedPaginationSupport.Descending, true, 50, true);
async Task<ExchangeWebResult<IEnumerable<SharedFuturesOrder>>> IFuturesOrderRestClient.GetClosedFuturesOrdersAsync(GetClosedOrdersRequest request, INextPageToken? pageToken, CancellationToken ct)
{
var validationError = ((IFuturesOrderRestClient)this).GetClosedFuturesOrdersOptions.ValidateRequest(Exchange, request, request.Symbol.TradingMode, SupportedTradingModes);
Expand Down Expand Up @@ -320,7 +320,7 @@ async Task<ExchangeWebResult<IEnumerable<SharedUserTrade>>> IFuturesOrderRestCli
}).ToArray());
}

PaginatedEndpointOptions<GetUserTradesRequest> IFuturesOrderRestClient.GetFuturesUserTradesOptions { get; } = new PaginatedEndpointOptions<GetUserTradesRequest>(SharedPaginationSupport.Descending, true);
PaginatedEndpointOptions<GetUserTradesRequest> IFuturesOrderRestClient.GetFuturesUserTradesOptions { get; } = new PaginatedEndpointOptions<GetUserTradesRequest>(SharedPaginationSupport.Descending, true, 50, true);
async Task<ExchangeWebResult<IEnumerable<SharedUserTrade>>> IFuturesOrderRestClient.GetFuturesUserTradesAsync(GetUserTradesRequest request, INextPageToken? pageToken, CancellationToken ct)
{
var validationError = ((IFuturesOrderRestClient)this).GetFuturesUserTradesOptions.ValidateRequest(Exchange, request, request.Symbol.TradingMode, SupportedTradingModes);
Expand Down Expand Up @@ -475,10 +475,7 @@ private SharedOrderType ParseOrderType(OrderTypeV2 type)

#region Klines client

GetKlinesOptions IKlineRestClient.GetKlinesOptions { get; } = new GetKlinesOptions(SharedPaginationSupport.Descending, false)
{
MaxTotalDataPoints = 1000
};
GetKlinesOptions IKlineRestClient.GetKlinesOptions { get; } = new GetKlinesOptions(SharedPaginationSupport.Descending, true, 1000, false);

async Task<ExchangeWebResult<IEnumerable<SharedKline>>> IKlineRestClient.GetKlinesAsync(GetKlinesRequest request, INextPageToken? pageToken, CancellationToken ct)
{
Expand Down Expand Up @@ -506,10 +503,7 @@ async Task<ExchangeWebResult<IEnumerable<SharedKline>>> IKlineRestClient.GetKlin

#region Mark Price Klines client

GetKlinesOptions IMarkPriceKlineRestClient.GetMarkPriceKlinesOptions { get; } = new GetKlinesOptions(SharedPaginationSupport.Descending, false)
{
MaxTotalDataPoints = 1000
};
GetKlinesOptions IMarkPriceKlineRestClient.GetMarkPriceKlinesOptions { get; } = new GetKlinesOptions(SharedPaginationSupport.Descending, true, 1000, false);

async Task<ExchangeWebResult<IEnumerable<SharedFuturesKline>>> IMarkPriceKlineRestClient.GetMarkPriceKlinesAsync(GetKlinesRequest request, INextPageToken? pageToken, CancellationToken ct)
{
Expand Down Expand Up @@ -538,10 +532,7 @@ async Task<ExchangeWebResult<IEnumerable<SharedFuturesKline>>> IMarkPriceKlineRe

#region Index Price Klines client

GetKlinesOptions IIndexPriceKlineRestClient.GetIndexPriceKlinesOptions { get; } = new GetKlinesOptions(SharedPaginationSupport.Descending, false)
{
MaxTotalDataPoints = 1000
};
GetKlinesOptions IIndexPriceKlineRestClient.GetIndexPriceKlinesOptions { get; } = new GetKlinesOptions(SharedPaginationSupport.Descending, true, 1000, false);

async Task<ExchangeWebResult<IEnumerable<SharedFuturesKline>>> IIndexPriceKlineRestClient.GetIndexPriceKlinesAsync(GetKlinesRequest request, INextPageToken? pageToken, CancellationToken ct)
{
Expand Down Expand Up @@ -684,7 +675,7 @@ async Task<ExchangeWebResult<SharedOpenInterest>> IOpenInterestRestClient.GetOpe
#endregion

#region Funding Rate client
GetFundingRateHistoryOptions IFundingRateRestClient.GetFundingRateHistoryOptions { get; } = new GetFundingRateHistoryOptions(SharedPaginationSupport.Descending,false);
GetFundingRateHistoryOptions IFundingRateRestClient.GetFundingRateHistoryOptions { get; } = new GetFundingRateHistoryOptions(SharedPaginationSupport.Descending, true, 100, false);

async Task<ExchangeWebResult<IEnumerable<SharedFundingRate>>> IFundingRateRestClient.GetFundingRateHistoryAsync(GetFundingRateHistoryRequest request, INextPageToken? pageToken, CancellationToken ct)
{
Expand Down Expand Up @@ -722,7 +713,7 @@ async Task<ExchangeWebResult<IEnumerable<SharedFundingRate>>> IFundingRateRestCl

#region Position History client

GetPositionHistoryOptions IPositionHistoryRestClient.GetPositionHistoryOptions { get; } = new GetPositionHistoryOptions(SharedPaginationSupport.Descending);
GetPositionHistoryOptions IPositionHistoryRestClient.GetPositionHistoryOptions { get; } = new GetPositionHistoryOptions(SharedPaginationSupport.Descending, true, 100);
async Task<ExchangeWebResult<IEnumerable<SharedPositionHistory>>> IPositionHistoryRestClient.GetPositionHistoryAsync(GetPositionHistoryRequest request, INextPageToken? pageToken, CancellationToken ct)
{
var validationError = ((IPositionHistoryRestClient)this).GetPositionHistoryOptions.ValidateRequest(Exchange, request, request.Symbol?.TradingMode ?? request.TradingMode, SupportedTradingModes);
Expand Down Expand Up @@ -768,5 +759,24 @@ async Task<ExchangeWebResult<IEnumerable<SharedPositionHistory>>> IPositionHisto
}).ToArray(), nextToken);
}
#endregion

#region Fee Client
EndpointOptions<GetFeeRequest> IFeeRestClient.GetFeeOptions { get; } = new EndpointOptions<GetFeeRequest>(true);

async Task<ExchangeWebResult<SharedFee>> IFeeRestClient.GetFeesAsync(GetFeeRequest request, CancellationToken ct)
{
var validationError = ((IFeeRestClient)this).GetFeeOptions.ValidateRequest(Exchange, request, request.Symbol.TradingMode, SupportedTradingModes);
if (validationError != null)
return new ExchangeWebResult<SharedFee>(Exchange, validationError);

// Get data
var result = await Account.GetTradingFeesAsync(request.Symbol.GetSymbol(FormatSymbol), ct: ct).ConfigureAwait(false);
if (!result)
return result.AsExchangeResult<SharedFee>(Exchange, null, default);

// Return
return result.AsExchangeResult(Exchange, TradingMode.Spot, new SharedFee(result.Data.MakerFeeRate * 100, result.Data.TakerFeeRate * 100));
}
#endregion
}
}
34 changes: 26 additions & 8 deletions CoinEx.Net/Clients/SpotApiV2/CoinExRestClientSpotApiShared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ internal partial class CoinExRestClientSpotApi : ICoinExRestClientSpotApiShared

#region Kline client

GetKlinesOptions IKlineRestClient.GetKlinesOptions { get; } = new GetKlinesOptions(SharedPaginationSupport.Descending, false)
GetKlinesOptions IKlineRestClient.GetKlinesOptions { get; } = new GetKlinesOptions(SharedPaginationSupport.Descending, true, 1000, false)
{
MaxRequestDataPoints = 1000,
MaxTotalDataPoints = 1000
};

Expand Down Expand Up @@ -290,7 +289,7 @@ async Task<ExchangeWebResult<IEnumerable<SharedSpotOrder>>> ISpotOrderRestClient
}).ToArray());
}

PaginatedEndpointOptions<GetClosedOrdersRequest> ISpotOrderRestClient.GetClosedSpotOrdersOptions { get; } = new PaginatedEndpointOptions<GetClosedOrdersRequest>(SharedPaginationSupport.Descending, true);
PaginatedEndpointOptions<GetClosedOrdersRequest> ISpotOrderRestClient.GetClosedSpotOrdersOptions { get; } = new PaginatedEndpointOptions<GetClosedOrdersRequest>(SharedPaginationSupport.Descending, true, 500, true);
async Task<ExchangeWebResult<IEnumerable<SharedSpotOrder>>> ISpotOrderRestClient.GetClosedSpotOrdersAsync(GetClosedOrdersRequest request, INextPageToken? pageToken, CancellationToken ct)
{
var validationError = ((ISpotOrderRestClient)this).GetClosedSpotOrdersOptions.ValidateRequest(Exchange, request, request.Symbol.TradingMode, SupportedTradingModes);
Expand Down Expand Up @@ -371,7 +370,7 @@ async Task<ExchangeWebResult<IEnumerable<SharedUserTrade>>> ISpotOrderRestClient
}).ToArray());
}

PaginatedEndpointOptions<GetUserTradesRequest> ISpotOrderRestClient.GetSpotUserTradesOptions { get; } = new PaginatedEndpointOptions<GetUserTradesRequest>(SharedPaginationSupport.Descending, true);
PaginatedEndpointOptions<GetUserTradesRequest> ISpotOrderRestClient.GetSpotUserTradesOptions { get; } = new PaginatedEndpointOptions<GetUserTradesRequest>(SharedPaginationSupport.Descending, true, 500, true);
async Task<ExchangeWebResult<IEnumerable<SharedUserTrade>>> ISpotOrderRestClient.GetSpotUserTradesAsync(GetUserTradesRequest request, INextPageToken? pageToken, CancellationToken ct)
{
var validationError = ((ISpotOrderRestClient)this).GetSpotUserTradesOptions.ValidateRequest(Exchange, request, request.Symbol.TradingMode, SupportedTradingModes);
Expand Down Expand Up @@ -546,7 +545,7 @@ async Task<ExchangeWebResult<IEnumerable<SharedDepositAddress>>> IDepositRestCli
});
}

GetDepositsOptions IDepositRestClient.GetDepositsOptions { get; } = new GetDepositsOptions(SharedPaginationSupport.Descending, false)
GetDepositsOptions IDepositRestClient.GetDepositsOptions { get; } = new GetDepositsOptions(SharedPaginationSupport.Descending, false, 100)
{
RequiredOptionalParameters = new List<ParameterDescription>
{
Expand All @@ -561,7 +560,7 @@ async Task<ExchangeWebResult<IEnumerable<SharedDeposit>>> IDepositRestClient.Get

// Determine page token
int page = 1;
int pageSize = request.Limit ?? 500;
int pageSize = request.Limit ?? 100;
if (pageToken is PageToken token)
{
page = token.Page;
Expand Down Expand Up @@ -614,7 +613,7 @@ async Task<ExchangeWebResult<SharedOrderBook>> IOrderBookRestClient.GetOrderBook

#region Withdrawal client

GetWithdrawalsOptions IWithdrawalRestClient.GetWithdrawalsOptions { get; } = new GetWithdrawalsOptions(SharedPaginationSupport.Descending, false);
GetWithdrawalsOptions IWithdrawalRestClient.GetWithdrawalsOptions { get; } = new GetWithdrawalsOptions(SharedPaginationSupport.Descending, false, 100);
async Task<ExchangeWebResult<IEnumerable<SharedWithdrawal>>> IWithdrawalRestClient.GetWithdrawalsAsync(GetWithdrawalsRequest request, INextPageToken? pageToken, CancellationToken ct)
{
var validationError = ((IWithdrawalRestClient)this).GetWithdrawalsOptions.ValidateRequest(Exchange, request, TradingMode.Spot, SupportedTradingModes);
Expand All @@ -623,7 +622,7 @@ async Task<ExchangeWebResult<IEnumerable<SharedWithdrawal>>> IWithdrawalRestClie

// Determine page token
int page = 1;
int pageSize = request.Limit ?? 500;
int pageSize = request.Limit ?? 100;
if (pageToken is PageToken token)
{
page = token.Page;
Expand Down Expand Up @@ -683,5 +682,24 @@ async Task<ExchangeWebResult<SharedId>> IWithdrawRestClient.WithdrawAsync(Withdr
}

#endregion

#region Fee Client
EndpointOptions<GetFeeRequest> IFeeRestClient.GetFeeOptions { get; } = new EndpointOptions<GetFeeRequest>(true);

async Task<ExchangeWebResult<SharedFee>> IFeeRestClient.GetFeesAsync(GetFeeRequest request, CancellationToken ct)
{
var validationError = ((IFeeRestClient)this).GetFeeOptions.ValidateRequest(Exchange, request, request.Symbol.TradingMode, SupportedTradingModes);
if (validationError != null)
return new ExchangeWebResult<SharedFee>(Exchange, validationError);

// Get data
var result = await Account.GetTradingFeesAsync(request.Symbol.GetSymbol(FormatSymbol), AccountType.Spot, ct: ct).ConfigureAwait(false);
if (!result)
return result.AsExchangeResult<SharedFee>(Exchange, null, default);

// Return
return result.AsExchangeResult(Exchange, TradingMode.Spot, new SharedFee(result.Data.MakerFeeRate * 100, result.Data.TakerFeeRate * 100));
}
#endregion
}
}
4 changes: 2 additions & 2 deletions CoinEx.Net/CoinEx.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="CryptoExchange.Net" Version="8.3.0" />
<PackageReference Include="CryptoExchange.Net" Version="8.4.0" />
<PackageReference Include="Crc32.NET" Version="1.2.0" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
25 changes: 0 additions & 25 deletions CoinEx.Net/CoinEx.Net.xml

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

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public interface ICoinExRestClientFuturesApiShared :
IOrderBookRestClient,
IOpenInterestRestClient,
IFundingRateRestClient,
IPositionHistoryRestClient
IPositionHistoryRestClient,
IFeeRestClient
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public interface ICoinExRestClientSpotApiShared :
ISpotTickerRestClient,
//ITradeHistoryRestClient,
IWithdrawalRestClient,
IWithdrawRestClient
IWithdrawRestClient,
IFeeRestClient
{
}
}
27 changes: 2 additions & 25 deletions CoinEx.Net/Objects/Options/CoinExOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CryptoExchange.Net.Authentication;
using CryptoExchange.Net.Objects.Options;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
Expand All @@ -9,31 +10,7 @@ namespace CoinEx.Net.Objects.Options
/// <summary>
/// CoinEx options
/// </summary>
public class CoinExOptions
public class CoinExOptions : LibraryOptions<CoinExRestOptions, CoinExSocketOptions, ApiCredentials, CoinExEnvironment>
{
/// <summary>
/// Rest client options
/// </summary>
public CoinExRestOptions Rest { get; set; } = new CoinExRestOptions();

/// <summary>
/// Socket client options
/// </summary>
public CoinExSocketOptions Socket { get; set; } = new CoinExSocketOptions();

/// <summary>
/// Trade environment. Contains info about URL's to use to connect to the API. Use `CoinExEnvironment` to swap environment, for example `Environment = CoinExEnvironment.Live`
/// </summary>
public CoinExEnvironment? Environment { get; set; }

/// <summary>
/// The api credentials used for signing requests.
/// </summary>
public ApiCredentials? ApiCredentials { get; set; }

/// <summary>
/// The DI service lifetime for the ICoinExSocketClient
/// </summary>
public ServiceLifetime? SocketClientLifeTime { get; set; }
}
}

0 comments on commit 260bc2b

Please sign in to comment.