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

Added futures premium index kline data #1424

Merged
merged 1 commit into from
Sep 22, 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: 2 additions & 0 deletions Binance.Net.UnitTests/BinanceRestIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ public async Task TestUsdFuturesExchangeData()
await RunAndCheckResult(client => client.UsdFuturesApi.ExchangeData.GetGlobalLongShortAccountRatioAsync("ETHUSDT", Enums.PeriodInterval.OneDay, null, null, null, CancellationToken.None), false);
await RunAndCheckResult(client => client.UsdFuturesApi.ExchangeData.GetMarkPriceKlinesAsync("ETHUSDT", Enums.KlineInterval.OneDay, null, null, null, CancellationToken.None), false);
await RunAndCheckResult(client => client.UsdFuturesApi.ExchangeData.GetKlinesAsync("ETHUSDT", Enums.KlineInterval.OneHour, DateTime.UtcNow.AddDays(-1), DateTime.UtcNow, 1, CancellationToken.None), false);
await RunAndCheckResult(client => client.UsdFuturesApi.ExchangeData.GetPremiumIndexKlinesAsync("ETHUSDT", Enums.KlineInterval.OneHour, DateTime.UtcNow.AddDays(-1), DateTime.UtcNow, 1, CancellationToken.None), false);
await RunAndCheckResult(client => client.UsdFuturesApi.ExchangeData.GetTickerAsync("ETHUSDT", CancellationToken.None), false);
await RunAndCheckResult(client => client.UsdFuturesApi.ExchangeData.GetTickersAsync(CancellationToken.None), false);
await RunAndCheckResult(client => client.UsdFuturesApi.ExchangeData.GetPriceAsync("ETHUSDT", CancellationToken.None), false);
Expand Down Expand Up @@ -267,6 +268,7 @@ public async Task TestCoinFuturesExchangeData()
await RunAndCheckResult(client => client.CoinFuturesApi.ExchangeData.GetIndexPriceKlinesAsync("ETHUSD", Enums.KlineInterval.OneDay, null, null, null, CancellationToken.None), false);
await RunAndCheckResult(client => client.CoinFuturesApi.ExchangeData.GetContinuousContractKlinesAsync("ETHUSD", Enums.ContractType.Perpetual, Enums.KlineInterval.OneDay, null, null, null, CancellationToken.None), false);
await RunAndCheckResult(client => client.CoinFuturesApi.ExchangeData.GetKlinesAsync("ETHUSD_PERP", Enums.KlineInterval.OneDay, null, null, null, CancellationToken.None), false);
await RunAndCheckResult(client => client.CoinFuturesApi.ExchangeData.GetPremiumIndexKlinesAsync("ETHUSD_PERP", Enums.KlineInterval.OneDay, null, null, null, CancellationToken.None), false);
await RunAndCheckResult(client => client.CoinFuturesApi.ExchangeData.GetMarkPricesAsync(null, null, CancellationToken.None), false);
await RunAndCheckResult(client => client.CoinFuturesApi.ExchangeData.GetMarkPriceKlinesAsync("ETHUSD_PERP", Enums.KlineInterval.OneDay, null, null, null, CancellationToken.None), false);
await RunAndCheckResult(client => client.CoinFuturesApi.ExchangeData.GetGlobalLongShortAccountRatioAsync("ETHUSD", Enums.PeriodInterval.OneDay, null, null, null, CancellationToken.None), false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
GET
/dapi/v1/premiumIndexKlines
false
[
[
1691603820000,
"-0.00042931",
"-0.00023641",
"-0.00059406",
"-0.00043659",
"0",
1691603879999,
"0",
12,
"0",
"0",
"0"
]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
GET
/fapi/v1/premiumIndexKlines
false
[
[
1691603820000,
"-0.00042931",
"-0.00023641",
"-0.00059406",
"-0.00043659",
"0",
1691603879999,
"0",
12,
"0",
"0",
"0"
]
]
6 changes: 4 additions & 2 deletions Binance.Net.UnitTests/RestRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public async Task ValidateSpotAccountCalls()
await tester.ValidateAsync(client => client.SpotApi.Account.GetWalletBalancesAsync(), "GetWalletBalances");
await tester.ValidateAsync(client => client.SpotApi.Account.GetAssetDividendRecordsAsync(), "GetAssetDividendRecords");
await tester.ValidateAsync(client => client.SpotApi.Account.GetDustLogAsync(), "GetDustLog");
await tester.ValidateAsync(client => client.SpotApi.Account.DustTransferAsync(new[] {"ETH"}), "DustTransfer");
await tester.ValidateAsync(client => client.SpotApi.Account.DustTransferAsync(new[] { "ETH" }), "DustTransfer");
await tester.ValidateAsync(client => client.SpotApi.Account.GetAssetsForDustTransferAsync(), "GetAssetsForDustTransfer");
await tester.ValidateAsync(client => client.SpotApi.Account.GetBnbBurnStatusAsync(), "GetBnbBurnStatus");
await tester.ValidateAsync(client => client.SpotApi.Account.SetBnbBurnStatusAsync(true), "SetBnbBurnStatus");
Expand Down Expand Up @@ -176,7 +176,7 @@ public async Task ValidateSpotTradingCalls()
await tester.ValidateAsync(client => client.SpotApi.Trading.GetLeveragedTokensRedemptionRecordsAsync("ETHUSDT", 1), "GetLeveragedTokensRedemptionRecords");
await tester.ValidateAsync(client => client.SpotApi.Trading.GetC2CTradeHistoryAsync(Enums.OrderSide.Buy), "GetC2CTradeHistory", "data");
//await tester.ValidateAsync(client => client.SpotApi.Trading.GetPayTradeHistoryAsync(), "GetPayTradeHistory", "data", new List<string>{ "walletTypes", "walletAssetCost" });
await tester.ValidateAsync(client => client.SpotApi.Trading.GetPayTradeHistoryAsync(), "GetPayTradeHistory2", "data", new List<string>{ "walletTypes", "walletAssetCost" });
await tester.ValidateAsync(client => client.SpotApi.Trading.GetPayTradeHistoryAsync(), "GetPayTradeHistory2", "data", new List<string> { "walletTypes", "walletAssetCost" });
await tester.ValidateAsync(client => client.SpotApi.Trading.ConvertQuoteRequestAsync("USDT", "ETH", 1), "ConvertQuoteRequest");
await tester.ValidateAsync(client => client.SpotApi.Trading.GetConvertOrderStatusAsync("123"), "GetConvertOrderStatus");
await tester.ValidateAsync(client => client.SpotApi.Trading.GetConvertTradeHistoryAsync(DateTime.UtcNow, DateTime.UtcNow), "GetConvertTradeHistory");
Expand Down Expand Up @@ -257,6 +257,7 @@ public async Task ValidateUsdFuturesExchangeDataCalls()
await tester.ValidateAsync(client => client.UsdFuturesApi.ExchangeData.GetMarkPriceAsync("ETHUSDT"), "GetMarkPrice");
await tester.ValidateAsync(client => client.UsdFuturesApi.ExchangeData.GetTickerAsync("ETHUSDT"), "GetTicker");
await tester.ValidateAsync(client => client.UsdFuturesApi.ExchangeData.GetKlinesAsync("ETHUSDT", Enums.KlineInterval.OneDay), "GetKlines");
await tester.ValidateAsync(client => client.UsdFuturesApi.ExchangeData.GetPremiumIndexKlinesAsync("ETHUSDT", Enums.KlineInterval.OneDay), "GetPremiumIndexKlines");
await tester.ValidateAsync(client => client.UsdFuturesApi.ExchangeData.GetBookPriceAsync("ETHUSDT"), "GetBookPrice");
await tester.ValidateAsync(client => client.UsdFuturesApi.ExchangeData.GetOpenInterestAsync("ETHUSDT"), "GetOpenInterest");
await tester.ValidateAsync(client => client.UsdFuturesApi.ExchangeData.GetOpenInterestHistoryAsync("ETHUSDT", Enums.PeriodInterval.OneDay), "GetOpenInterestHistory");
Expand Down Expand Up @@ -373,6 +374,7 @@ public async Task ValidateCoinFuturesExchangeDataCalls()
await tester.ValidateAsync(client => client.CoinFuturesApi.ExchangeData.GetTradeHistoryAsync("ETHUSDT"), "GetTradeHistory");
await tester.ValidateAsync(client => client.CoinFuturesApi.ExchangeData.GetMarkPricesAsync("ETHUSDT"), "GetMarkPrices");
await tester.ValidateAsync(client => client.CoinFuturesApi.ExchangeData.GetKlinesAsync("ETHUSDT", Enums.KlineInterval.OneSecond), "GetKlines");
await tester.ValidateAsync(client => client.CoinFuturesApi.ExchangeData.GetPremiumIndexKlinesAsync("ETHUSDT", Enums.KlineInterval.OneSecond), "GetPremiumIndexKlines");
await tester.ValidateAsync(client => client.CoinFuturesApi.ExchangeData.GetContinuousContractKlinesAsync("ETHUSDT", Enums.ContractType.Perpetual, Enums.KlineInterval.OneSecond), "GetContinuousContractKlines");
await tester.ValidateAsync(client => client.CoinFuturesApi.ExchangeData.GetIndexPriceKlinesAsync("ETHUSDT", Enums.KlineInterval.OneSecond), "GetIndexPriceKlines");
await tester.ValidateAsync(client => client.CoinFuturesApi.ExchangeData.GetTickersAsync("ETHUSDT"), "GetTickers");
Expand Down
34 changes: 33 additions & 1 deletion Binance.Net/Binance.Net.xml
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@
<member name="M:Binance.Net.Clients.CoinFuturesApi.BinanceRestClientCoinFuturesApiExchangeData.GetKlinesAsync(System.String,Binance.Net.Enums.KlineInterval,System.Nullable{System.DateTime},System.Nullable{System.DateTime},System.Nullable{System.Int32},System.Threading.CancellationToken)">
<inheritdoc />
</member>
<member name="M:Binance.Net.Clients.CoinFuturesApi.BinanceRestClientCoinFuturesApiExchangeData.GetPremiumIndexKlinesAsync(System.String,Binance.Net.Enums.KlineInterval,System.Nullable{System.DateTime},System.Nullable{System.DateTime},System.Nullable{System.Int32},System.Threading.CancellationToken)">
<inheritdoc />
</member>
<member name="M:Binance.Net.Clients.CoinFuturesApi.BinanceRestClientCoinFuturesApiExchangeData.GetContinuousContractKlinesAsync(System.String,Binance.Net.Enums.ContractType,Binance.Net.Enums.KlineInterval,System.Nullable{System.DateTime},System.Nullable{System.DateTime},System.Nullable{System.Int32},System.Threading.CancellationToken)">
<inheritdoc />
</member>
Expand Down Expand Up @@ -2085,6 +2088,9 @@
<member name="M:Binance.Net.Clients.UsdFuturesApi.BinanceRestClientUsdFuturesApiExchangeData.GetKlinesAsync(System.String,Binance.Net.Enums.KlineInterval,System.Nullable{System.DateTime},System.Nullable{System.DateTime},System.Nullable{System.Int32},System.Threading.CancellationToken)">
<inheritdoc />
</member>
<member name="M:Binance.Net.Clients.UsdFuturesApi.BinanceRestClientUsdFuturesApiExchangeData.GetPremiumIndexKlinesAsync(System.String,Binance.Net.Enums.KlineInterval,System.Nullable{System.DateTime},System.Nullable{System.DateTime},System.Nullable{System.Int32},System.Threading.CancellationToken)">
<inheritdoc />
</member>
<member name="M:Binance.Net.Clients.UsdFuturesApi.BinanceRestClientUsdFuturesApiExchangeData.GetBookPriceAsync(System.String,System.Threading.CancellationToken)">
<inheritdoc />
</member>
Expand Down Expand Up @@ -5762,6 +5768,19 @@
<param name="ct">Cancellation token</param>
<returns>The candlestick data for the provided symbol</returns>
</member>
<member name="M:Binance.Net.Interfaces.Clients.CoinFuturesApi.IBinanceRestClientCoinFuturesApiExchangeData.GetPremiumIndexKlinesAsync(System.String,Binance.Net.Enums.KlineInterval,System.Nullable{System.DateTime},System.Nullable{System.DateTime},System.Nullable{System.Int32},System.Threading.CancellationToken)">
<summary>
Get premium index kline data for the provided symbol
<para><a href="https://binance-docs.github.io/apidocs/delivery/en/#premium-index-kline-data" /></para>
</summary>
<param name="symbol">The symbol to get the data for, for example `BTCUSD_PERP`</param>
<param name="interval">The candlestick timespan</param>
<param name="startTime">Start time to get candlestick data</param>
<param name="endTime">End time to get candlestick data</param>
<param name="limit">Max number of results</param>
<param name="ct">Cancellation token</param>
<returns>The candlestick data for the provided symbol</returns>
</member>
<member name="M:Binance.Net.Interfaces.Clients.CoinFuturesApi.IBinanceRestClientCoinFuturesApiExchangeData.GetFundingInfoAsync(System.Threading.CancellationToken)">
<summary>
Get funding rate info for symbols that had FundingRateCap/ FundingRateFloor / fundingIntervalHours adjustment
Expand Down Expand Up @@ -11570,6 +11589,19 @@
<param name="ct">Cancellation token</param>
<returns></returns>
</member>
<member name="M:Binance.Net.Interfaces.Clients.UsdFuturesApi.IBinanceRestClientUsdFuturesApiExchangeData.GetPremiumIndexKlinesAsync(System.String,Binance.Net.Enums.KlineInterval,System.Nullable{System.DateTime},System.Nullable{System.DateTime},System.Nullable{System.Int32},System.Threading.CancellationToken)">
<summary>
Get premium index klines for a symbol
<para><a href="https://binance-docs.github.io/apidocs/futures/en/#premium-index-kline-data" /></para>
</summary>
<param name="symbol">The symbol, for example `ETHUSDT`</param>
<param name="interval">The kline interval</param>
<param name="startTime">Filter by start time</param>
<param name="endTime">Filter by end time</param>
<param name="limit">Max number of results</param>
<param name="ct">Cancellation token</param>
<returns></returns>
</member>
<member name="M:Binance.Net.Interfaces.Clients.UsdFuturesApi.IBinanceRestClientUsdFuturesApiExchangeData.GetFundingInfoAsync(System.Threading.CancellationToken)">
<summary>
Get funding rate info for symbols that had FundingRateCap/ FundingRateFloor / fundingIntervalHours adjustment
Expand Down Expand Up @@ -16768,7 +16800,7 @@
</member>
<member name="T:Binance.Net.Objects.Models.Spot.BinanceMarkIndexKline">
<summary>
Kline for mark or index price
Kline for mark or index price or Premium index
</summary>
</member>
<member name="P:Binance.Net.Objects.Models.Spot.BinanceMarkIndexKline.OpenTime">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System.Diagnostics;
using Binance.Net.Converters;
using Binance.Net.Enums;
using Binance.Net.Enums;
using Binance.Net.Interfaces;
using Binance.Net.Interfaces.Clients.CoinFuturesApi;
using Binance.Net.Objects.Models.Futures;
using Binance.Net.Objects.Models.Spot;
using CryptoExchange.Net.RateLimiting.Guards;
using System.Diagnostics;

namespace Binance.Net.Clients.CoinFuturesApi
{
Expand Down Expand Up @@ -123,7 +122,7 @@ public async Task<WebCallResult<IEnumerable<BinanceFuturesFundingRateHistory>>>
}

#endregion

#region Get Funding Info

/// <inheritdoc />
Expand Down Expand Up @@ -289,6 +288,27 @@ public async Task<WebCallResult<IEnumerable<IBinanceKline>>> GetKlinesAsync(stri

#endregion

#region Kline/Premium Index

/// <inheritdoc />
public async Task<WebCallResult<IEnumerable<BinanceMarkIndexKline>>> GetPremiumIndexKlinesAsync(string symbol, KlineInterval interval, DateTime? startTime = null, DateTime? endTime = null, int? limit = null, CancellationToken ct = default)
{
limit?.ValidateIntBetween(nameof(limit), 1, 1500);
var parameters = new ParameterCollection {
{ "symbol", symbol },
};
parameters.AddEnum("interval", interval);
parameters.AddOptionalParameter("startTime", DateTimeConverter.ConvertToMilliseconds(startTime));
parameters.AddOptionalParameter("endTime", DateTimeConverter.ConvertToMilliseconds(endTime));
parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture));

var requestWeight = limit == null ? 5 : limit <= 100 ? 1 : limit <= 500 ? 2 : limit <= 1000 ? 5 : 10;
var request = _definitions.GetOrCreate(HttpMethod.Get, "dapi/v1/premiumIndexKlines", BinanceExchange.RateLimiter.FuturesRest, requestWeight);
return await _baseClient.SendAsync<IEnumerable<BinanceMarkIndexKline>>(request, parameters, ct, requestWeight).ConfigureAwait(false);
}

#endregion

#region Continuous contract Kline Data

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System.Diagnostics;
using Binance.Net.Converters;
using Binance.Net.Enums;
using Binance.Net.Enums;
using Binance.Net.Interfaces;
using Binance.Net.Interfaces.Clients.UsdFuturesApi;
using Binance.Net.Objects.Models.Futures;
using Binance.Net.Objects.Models.Spot;
using CryptoExchange.Net.RateLimiting.Guards;
using System.Diagnostics;

namespace Binance.Net.Clients.UsdFuturesApi
{
Expand Down Expand Up @@ -319,6 +318,27 @@ public async Task<WebCallResult<IEnumerable<IBinanceKline>>> GetKlinesAsync(stri

#endregion

#region Kline/Premium Index

/// <inheritdoc />
public async Task<WebCallResult<IEnumerable<BinanceMarkIndexKline>>> GetPremiumIndexKlinesAsync(string symbol, KlineInterval interval, DateTime? startTime = null, DateTime? endTime = null, int? limit = null, CancellationToken ct = default)
{
limit?.ValidateIntBetween(nameof(limit), 1, 1500);
var parameters = new ParameterCollection {
{ "symbol", symbol },
};
parameters.AddEnum("interval", interval);
parameters.AddOptionalParameter("startTime", DateTimeConverter.ConvertToMilliseconds(startTime));
parameters.AddOptionalParameter("endTime", DateTimeConverter.ConvertToMilliseconds(endTime));
parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture));

var requestWeight = limit == null ? 5 : limit <= 100 ? 1 : limit <= 500 ? 2 : limit <= 1000 ? 5 : 10;
var request = _definitions.GetOrCreate(HttpMethod.Get, "fapi/v1/premiumIndexKlines", BinanceExchange.RateLimiter.FuturesRest, requestWeight);
return await _baseClient.SendAsync<IEnumerable<BinanceMarkIndexKline>>(request, parameters, ct, requestWeight).ConfigureAwait(false);
}

#endregion

#region Symbol Order Book Ticker

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ public interface IBinanceRestClientCoinFuturesApiExchangeData
Task<WebCallResult<IEnumerable<IBinanceKline>>> GetKlinesAsync(string symbol, KlineInterval interval,
DateTime? startTime = null, DateTime? endTime = null, int? limit = null, CancellationToken ct = default);

/// <summary>
/// Get premium index kline data for the provided symbol
/// <para><a href="https://binance-docs.github.io/apidocs/delivery/en/#premium-index-kline-data" /></para>
/// </summary>
/// <param name="symbol">The symbol to get the data for, for example `BTCUSD_PERP`</param>
/// <param name="interval">The candlestick timespan</param>
/// <param name="startTime">Start time to get candlestick data</param>
/// <param name="endTime">End time to get candlestick data</param>
/// <param name="limit">Max number of results</param>
/// <param name="ct">Cancellation token</param>
/// <returns>The candlestick data for the provided symbol</returns>
Task<WebCallResult<IEnumerable<BinanceMarkIndexKline>>> GetPremiumIndexKlinesAsync(string symbol, KlineInterval interval,
DateTime? startTime = null, DateTime? endTime = null, int? limit = null, CancellationToken ct = default);

/// <summary>
/// Get funding rate info for symbols that had FundingRateCap/ FundingRateFloor / fundingIntervalHours adjustment
/// <para><a href="https://binance-docs.github.io/apidocs/delivery/en/#get-funding-rate-info" /></para>
Expand Down
Loading
Loading