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 99db40d commit 3745252
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 101 deletions.
8 changes: 4 additions & 4 deletions Binance.Net.UnitTests/Binance.Net.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
</PropertyGroup>

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

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Binance.Net/Binance.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.3.0" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
<PackageReference Include="CryptoExchange.Net" Version="8.4.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 Binance.Net/Binance.Net.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29332,31 +29332,6 @@
Binance options
</summary>
</member>
<member name="P:Binance.Net.Objects.Options.BinanceOptions.Rest">
<summary>
Rest client options
</summary>
</member>
<member name="P:Binance.Net.Objects.Options.BinanceOptions.Socket">
<summary>
Socket client options
</summary>
</member>
<member name="P:Binance.Net.Objects.Options.BinanceOptions.Environment">
<summary>
Trade environment. Contains info about URL's to use to connect to the API. Use `BinanceEnvironment` to swap environment, for example `Environment = BinanceEnvironment.Live`
</summary>
</member>
<member name="P:Binance.Net.Objects.Options.BinanceOptions.ApiCredentials">
<summary>
The api credentials used for signing requests.
</summary>
</member>
<member name="P:Binance.Net.Objects.Options.BinanceOptions.SocketClientLifeTime">
<summary>
The DI service lifetime for the IBinanceSocketClient
</summary>
</member>
<member name="T:Binance.Net.Objects.Options.BinanceOrderBookOptions">
<summary>
Options for the Binance SymbolOrderBook
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ internal partial class BinanceRestClientCoinFuturesApi : IBinanceRestClientCoinF

#region Klines client

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

async Task<ExchangeWebResult<IEnumerable<SharedKline>>> IKlineRestClient.GetKlinesAsync(GetKlinesRequest request, INextPageToken? pageToken, CancellationToken ct)
{
Expand Down Expand Up @@ -305,7 +302,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, 100, 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 @@ -383,7 +380,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, 1000, 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 @@ -578,10 +575,7 @@ async Task<ExchangeWebResult<SharedLeverage>> ILeverageRestClient.SetLeverageAsy

#region Mark Klines client

GetKlinesOptions IMarkPriceKlineRestClient.GetMarkPriceKlinesOptions { get; } = new GetKlinesOptions(SharedPaginationSupport.Descending, false)
{
MaxRequestDataPoints = 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 @@ -656,7 +650,7 @@ async Task<ExchangeWebResult<SharedOrderBook>> IOrderBookRestClient.GetOrderBook
#endregion

#region Trade History client
GetTradeHistoryOptions ITradeHistoryRestClient.GetTradeHistoryOptions { get; } = new GetTradeHistoryOptions(SharedPaginationSupport.Ascending, false);
GetTradeHistoryOptions ITradeHistoryRestClient.GetTradeHistoryOptions { get; } = new GetTradeHistoryOptions(SharedPaginationSupport.Ascending, true, 1000, false);

async Task<ExchangeWebResult<IEnumerable<SharedTrade>>> ITradeHistoryRestClient.GetTradeHistoryAsync(GetTradeHistoryRequest request, INextPageToken? pageToken, CancellationToken ct)
{
Expand Down Expand Up @@ -693,10 +687,7 @@ async Task<ExchangeWebResult<IEnumerable<SharedTrade>>> ITradeHistoryRestClient.

#region Index Klines client

GetKlinesOptions IIndexPriceKlineRestClient.GetIndexPriceKlinesOptions { get; } = new GetKlinesOptions(SharedPaginationSupport.Descending, false)
{
MaxRequestDataPoints = 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 @@ -769,7 +760,7 @@ async Task<ExchangeWebResult<SharedOpenInterest>> IOpenInterestRestClient.GetOpe
#endregion

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

async Task<ExchangeWebResult<IEnumerable<SharedFundingRate>>> IFundingRateRestClient.GetFundingRateHistoryAsync(GetFundingRateHistoryRequest request, INextPageToken? pageToken, CancellationToken ct)
{
Expand Down Expand Up @@ -897,5 +888,26 @@ async Task<ExchangeWebResult<string>> IListenKeyRestClient.StopListenKeyAsync(St
return result.AsExchangeResult(Exchange, SupportedTradingModes, request.ListenKey);
}
#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.GetUserCommissionRateAsync(
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.MakerCommissionRate * 100, result.Data.TakerCommissionRate * 100));
}
#endregion
}
}
40 changes: 31 additions & 9 deletions Binance.Net/Clients/SpotApi/BinanceRestClientSpotApiShared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ internal partial class BinanceRestClientSpotApi : IBinanceRestClientSpotApiShare

#region Klines Client

GetKlinesOptions IKlineRestClient.GetKlinesOptions { get; } = new GetKlinesOptions(SharedPaginationSupport.Descending, false)
{
MaxRequestDataPoints = 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 @@ -155,7 +152,7 @@ async Task<ExchangeWebResult<IEnumerable<SharedTrade>>> IRecentTradeRestClient.G
#endregion

#region Trade History client
GetTradeHistoryOptions ITradeHistoryRestClient.GetTradeHistoryOptions { get; } = new GetTradeHistoryOptions(SharedPaginationSupport.Ascending, false);
GetTradeHistoryOptions ITradeHistoryRestClient.GetTradeHistoryOptions { get; } = new GetTradeHistoryOptions(SharedPaginationSupport.Ascending, true, 1000, false);

async Task<ExchangeWebResult<IEnumerable<SharedTrade>>> ITradeHistoryRestClient.GetTradeHistoryAsync(GetTradeHistoryRequest request, INextPageToken? pageToken, CancellationToken ct)
{
Expand Down Expand Up @@ -338,7 +335,7 @@ async Task<ExchangeWebResult<IEnumerable<SharedSpotOrder>>> ISpotOrderRestClient
}).ToArray());
}

PaginatedEndpointOptions<GetClosedOrdersRequest> ISpotOrderRestClient.GetClosedSpotOrdersOptions { get; } = new PaginatedEndpointOptions<GetClosedOrdersRequest>(SharedPaginationSupport.Ascending, true);
PaginatedEndpointOptions<GetClosedOrdersRequest> ISpotOrderRestClient.GetClosedSpotOrdersOptions { get; } = new PaginatedEndpointOptions<GetClosedOrdersRequest>(SharedPaginationSupport.Ascending, true, 1000, 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 @@ -413,7 +410,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, 1000, 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 @@ -591,7 +588,7 @@ async Task<ExchangeWebResult<IEnumerable<SharedDepositAddress>>> IDepositRestCli
});
}

GetDepositsOptions IDepositRestClient.GetDepositsOptions { get; } = new GetDepositsOptions(SharedPaginationSupport.Descending, true);
GetDepositsOptions IDepositRestClient.GetDepositsOptions { get; } = new GetDepositsOptions(SharedPaginationSupport.Descending, true, 1000);
async Task<ExchangeWebResult<IEnumerable<SharedDeposit>>> IDepositRestClient.GetDepositsAsync(GetDepositsRequest request, INextPageToken? pageToken, CancellationToken ct)
{
var validationError = ((IDepositRestClient)this).GetDepositsOptions.ValidateRequest(Exchange, request, TradingMode.Spot, SupportedTradingModes);
Expand Down Expand Up @@ -633,7 +630,7 @@ async Task<ExchangeWebResult<IEnumerable<SharedDeposit>>> IDepositRestClient.Get

#region Withdrawal client

GetWithdrawalsOptions IWithdrawalRestClient.GetWithdrawalsOptions { get; } = new GetWithdrawalsOptions(SharedPaginationSupport.Descending, true);
GetWithdrawalsOptions IWithdrawalRestClient.GetWithdrawalsOptions { get; } = new GetWithdrawalsOptions(SharedPaginationSupport.Descending, true, 1000);
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 Down Expand Up @@ -745,5 +742,30 @@ async Task<ExchangeWebResult<string>> IListenKeyRestClient.StopListenKeyAsync(St
return result.AsExchangeResult(Exchange, TradingMode.Spot, request.ListenKey);
}
#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.GetTradeFeeAsync(
request.Symbol.GetSymbol(FormatSymbol),
ct: ct).ConfigureAwait(false);
if (!result)
return result.AsExchangeResult<SharedFee>(Exchange, null, default);

var symbol = result.Data.SingleOrDefault();
if (symbol == null)
return result.AsExchangeError<SharedFee>(Exchange, new ServerError("Not found"));

// Return
return result.AsExchangeResult(Exchange, TradingMode.Spot, new SharedFee(symbol.MakerFee * 100, symbol.TakerFee * 100));
}
#endregion
}
}
Loading

0 comments on commit 3745252

Please sign in to comment.