Skip to content

Commit

Permalink
CryptoExchange update, fixed futures doc references
Browse files Browse the repository at this point in the history
  • Loading branch information
JKorf committed Nov 28, 2024
1 parent 17d7744 commit af64c1f
Show file tree
Hide file tree
Showing 13 changed files with 133 additions and 147 deletions.
8 changes: 4 additions & 4 deletions BitMart.Net.UnitTests/BitMart.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.10.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 BitMart.Net/BitMart.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
99 changes: 37 additions & 62 deletions BitMart.Net/BitMart.Net.xml

Large diffs are not rendered by default.

32 changes: 24 additions & 8 deletions BitMart.Net/Clients/SpotApi/BitMartRestClientSpotApiShared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ internal partial class BitMartRestClientSpotApi : IBitMartRestClientSpotApiShare

#region Kline client

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

async Task<ExchangeWebResult<IEnumerable<SharedKline>>> IKlineRestClient.GetKlinesAsync(GetKlinesRequest request, INextPageToken? pageToken, CancellationToken ct)
{
Expand Down Expand Up @@ -292,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, 200, 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 @@ -365,7 +362,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, 200, 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 @@ -535,7 +532,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, 100);
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 @@ -583,7 +580,7 @@ async Task<ExchangeWebResult<SharedOrderBook>> IOrderBookRestClient.GetOrderBook

#region Withdrawal client

GetWithdrawalsOptions IWithdrawalRestClient.GetWithdrawalsOptions { get; } = new GetWithdrawalsOptions(SharedPaginationSupport.Descending, true);
GetWithdrawalsOptions IWithdrawalRestClient.GetWithdrawalsOptions { get; } = new GetWithdrawalsOptions(SharedPaginationSupport.Descending, true, 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 Down Expand Up @@ -638,5 +635,24 @@ async Task<ExchangeWebResult<SharedId>> IWithdrawRestClient.WithdrawAsync(Withdr
}

#endregion

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

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.GetSymbolTradeFeeAsync(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.BuyMakerFeeRate * 100, result.Data.BuyTakerFeeRate * 100));
}
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@ async Task<ExchangeWebResult<IEnumerable<SharedFuturesSymbol>>> IFuturesSymbolRe

#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 @@ -380,7 +377,7 @@ async Task<ExchangeWebResult<IEnumerable<SharedFuturesOrder>>> IFuturesOrderRest
}).ToArray());
}

PaginatedEndpointOptions<GetClosedOrdersRequest> IFuturesOrderRestClient.GetClosedFuturesOrdersOptions { get; } = new PaginatedEndpointOptions<GetClosedOrdersRequest>(SharedPaginationSupport.NotSupported, true);
PaginatedEndpointOptions<GetClosedOrdersRequest> IFuturesOrderRestClient.GetClosedFuturesOrdersOptions { get; } = new PaginatedEndpointOptions<GetClosedOrdersRequest>(SharedPaginationSupport.NotSupported, 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 @@ -448,7 +445,7 @@ async Task<ExchangeWebResult<IEnumerable<SharedUserTrade>>> IFuturesOrderRestCli
}).ToArray());
}

PaginatedEndpointOptions<GetUserTradesRequest> IFuturesOrderRestClient.GetFuturesUserTradesOptions { get; } = new PaginatedEndpointOptions<GetUserTradesRequest>(SharedPaginationSupport.NotSupported, true);
PaginatedEndpointOptions<GetUserTradesRequest> IFuturesOrderRestClient.GetFuturesUserTradesOptions { get; } = new PaginatedEndpointOptions<GetUserTradesRequest>(SharedPaginationSupport.NotSupported, true, 100, 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 @@ -586,6 +583,25 @@ private SharedOrderType ParseOrderType(FuturesOrderType type)

#endregion

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

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.GetSymbolTradeFeeAsync(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.MakerFeeRateA, result.Data.TakerFeeRateA));
}
#endregion

public static DateTime RoundDown(DateTime dt, TimeSpan d)
{
var delta = dt.Ticks % d.Ticks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public interface IBitMartRestClientSpotApiShared :
ISpotSymbolRestClient,
ISpotTickerRestClient,
IWithdrawalRestClient,
IWithdrawRestClient
IWithdrawRestClient,
IFeeRestClient
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public interface IBitMartRestClientUsdFuturesApiAccount
{
/// <summary>
/// Get account balances
/// <para><a href="https://developer-pro.bitmart.com/en/futures/#get-contract-assets-keyed" /></para>
/// <para><a href="https://developer-pro.bitmart.com/en/futuresv2/#get-contract-assets-keyed" /></para>
/// </summary>
/// <param name="ct">Cancellation token</param>
Task<WebCallResult<IEnumerable<BitMartFuturesBalance>>> GetBalancesAsync(CancellationToken ct = default);

/// <summary>
/// Get account transfer history
/// <para><a href="https://developer-pro.bitmart.com/en/futures/#get-transfer-list-signed" /></para>
/// <para><a href="https://developer-pro.bitmart.com/en/futuresv2/#get-transfer-list-signed" /></para>
/// </summary>
/// <param name="asset">Filter by asset, for example `USDT`</param>
/// <param name="startTime">Filter by start time</param>
Expand All @@ -34,7 +34,7 @@ public interface IBitMartRestClientUsdFuturesApiAccount

/// <summary>
/// Transfer between futures and spot account
/// <para><a href="https://developer-pro.bitmart.com/en/futures/#transfer-signed" /></para>
/// <para><a href="https://developer-pro.bitmart.com/en/futuresv2/#transfer-signed" /></para>
/// </summary>
/// <param name="asset">The asset, for example `USDT`</param>
/// <param name="quantity">Quantity to transfer</param>
Expand All @@ -44,7 +44,7 @@ public interface IBitMartRestClientUsdFuturesApiAccount

/// <summary>
/// Set leverage
/// <para><a href="https://developer-pro.bitmart.com/en/futures/#submit-leverage-signed" /></para>
/// <para><a href="https://developer-pro.bitmart.com/en/futuresv2/#submit-leverage-signed" /></para>
/// </summary>
/// <param name="symbol">The symbol, for example `ETHUSDT`</param>
/// <param name="leverage">Leverage</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,39 @@ public interface IBitMartRestClientUsdFuturesApiExchangeData
{
/// <summary>
/// Get contracts
/// <para><a href="https://developer-pro.bitmart.com/en/futures/#get-contract-details" /></para>
/// <para><a href="https://developer-pro.bitmart.com/en/futuresv2/#get-contract-details" /></para>
/// </summary>
/// <param name="symbol">Filter by symbol, for example `ETHUSDT`</param>
/// <param name="ct">Cancellation token</param>
Task<WebCallResult<IEnumerable<BitMartContract>>> GetContractsAsync(string? symbol = null, CancellationToken ct = default);

/// <summary>
/// Get the current order book
/// <para><a href="https://developer-pro.bitmart.com/en/futures/#get-market-depth" /></para>
/// <para><a href="https://developer-pro.bitmart.com/en/futuresv2/#get-market-depth" /></para>
/// </summary>
/// <param name="symbol">The symbol, for example `ETHUSDT`</param>
/// <param name="ct">Cancellation token</param>
Task<WebCallResult<BitMartOrderBook>> GetOrderBookAsync(string symbol, CancellationToken ct = default);

/// <summary>
/// Get open interest for a symbol
/// <para><a href="https://developer-pro.bitmart.com/en/futures/#get-futures-openinterest" /></para>
/// <para><a href="https://developer-pro.bitmart.com/en/futuresv2/#get-futures-openinterest" /></para>
/// </summary>
/// <param name="symbol">The symbol, for example `ETHUSDT`</param>
/// <param name="ct">Cancellation token</param>
Task<WebCallResult<BitMartOpenInterest>> GetOpenInterestAsync(string symbol, CancellationToken ct = default);

/// <summary>
/// Get the current funding rate for a symbol
/// <para><a href="https://developer-pro.bitmart.com/en/futures/#get-current-funding-rate" /></para>
/// <para><a href="https://developer-pro.bitmart.com/en/futuresv2/#get-current-funding-rate" /></para>
/// </summary>
/// <param name="symbol">The symbol, for example `ETHUSDT`</param>
/// <param name="ct">Cancellation token</param>
Task<WebCallResult<BitMartFundingRate>> GetCurrentFundingRateAsync(string symbol, CancellationToken ct = default);

/// <summary>
/// Get kline/candlestick data
/// <para><a href="https://developer-pro.bitmart.com/en/futures/#get-k-line" /></para>
/// <para><a href="https://developer-pro.bitmart.com/en/futuresv2/#get-k-line" /></para>
/// </summary>
/// <param name="symbol">The symbol, for example `ETHUSDT`</param>
/// <param name="klineInterval">Kline interval</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public interface IBitMartRestClientUsdFuturesApiShared :
ILeverageRestClient,
IOrderBookRestClient,
IOpenInterestRestClient,
IFuturesOrderRestClient
IFuturesOrderRestClient,
IFeeRestClient
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface IBitMartRestClientUsdFuturesApiSubAccount
{
/// <summary>
/// Transfer from sub futures account to main account, for main account
/// <para><a href="https://developer-pro.bitmart.com/en/futures/#sub-account-to-main-account-for-main-account-signed" /></para>
/// <para><a href="https://developer-pro.bitmart.com/en/futuresv2/#sub-account-to-main-account-for-main-account-signed" /></para>
/// </summary>
/// <param name="asset">The asset, for example `USDT`</param>
/// <param name="quantity">Quantity</param>
Expand All @@ -26,7 +26,7 @@ public interface IBitMartRestClientUsdFuturesApiSubAccount

/// <summary>
/// Transfer from main account to sub futures acount
/// <para><a href="https://developer-pro.bitmart.com/en/futures/#main-account-to-sub-account-for-main-account-signed" /></para>
/// <para><a href="https://developer-pro.bitmart.com/en/futuresv2/#main-account-to-sub-account-for-main-account-signed" /></para>
/// </summary>
/// <param name="asset">The asset, for example `USDT`</param>
/// <param name="quantity">Quantity</param>
Expand All @@ -37,7 +37,7 @@ public interface IBitMartRestClientUsdFuturesApiSubAccount

/// <summary>
/// Transfer from sub futures account to main account, for sub account
/// <para><a href="https://developer-pro.bitmart.com/en/futures/#sub-account-to-main-account-for-sub-account-signed" /></para>
/// <para><a href="https://developer-pro.bitmart.com/en/futuresv2/#sub-account-to-main-account-for-sub-account-signed" /></para>
/// </summary>
/// <param name="asset">The asset, for example `USDT`</param>
/// <param name="quantity">Quantity</param>
Expand All @@ -47,7 +47,7 @@ public interface IBitMartRestClientUsdFuturesApiSubAccount

/// <summary>
/// Get sub account futures balances
/// <para><a href="https://developer-pro.bitmart.com/en/futures/#get-sub-account-futures-wallet-balance-for-main-account-keyed" /></para>
/// <para><a href="https://developer-pro.bitmart.com/en/futuresv2/#get-sub-account-futures-wallet-balance-for-main-account-keyed" /></para>
/// </summary>
/// <param name="subAccount">Sub account name</param>
/// <param name="asset">The asset, for example `USDT`</param>
Expand All @@ -56,7 +56,7 @@ public interface IBitMartRestClientUsdFuturesApiSubAccount

/// <summary>
/// Get sub account transfer history, for main account
/// <para><a href="https://developer-pro.bitmart.com/en/futures/#get-sub-account-transfer-history-for-main-account-keyed" /></para>
/// <para><a href="https://developer-pro.bitmart.com/en/futuresv2/#get-sub-account-transfer-history-for-main-account-keyed" /></para>
/// </summary>
/// <param name="subAccount">Sub account name</param>
/// <param name="limit">Max number of results</param>
Expand All @@ -65,7 +65,7 @@ public interface IBitMartRestClientUsdFuturesApiSubAccount

/// <summary>
/// Get sub account transfer history
/// <para><a href="https://developer-pro.bitmart.com/en/futures/#get-account-futures-asset-transfer-history-for-main-sub-account-keyed" /></para>
/// <para><a href="https://developer-pro.bitmart.com/en/futuresv2/#get-account-futures-asset-transfer-history-for-main-sub-account-keyed" /></para>
/// </summary>
/// <param name="limit">Max number of results</param>
/// <param name="ct">Cancellation token</param>
Expand Down
Loading

0 comments on commit af64c1f

Please sign in to comment.