From b3f7ea95ce0749e1ca68672977d27026d65e5a98 Mon Sep 17 00:00:00 2001 From: Kenneth Tang Date: Mon, 23 Sep 2024 00:54:22 +0800 Subject: [PATCH] Added futures premium index kline data --- .../BinanceRestIntegrationTests.cs | 2 ++ .../ExchangeData/GetPremiumIndexKlines.txt | 19 +++++++++++ .../ExchangeData/GetPremiumIndexKlines.txt | 19 +++++++++++ Binance.Net.UnitTests/RestRequestTests.cs | 6 ++-- Binance.Net/Binance.Net.xml | 34 ++++++++++++++++++- ...nceRestClientCoinFuturesApiExchangeData.cs | 28 ++++++++++++--- ...anceRestClientUsdFuturesApiExchangeData.cs | 26 ++++++++++++-- ...nceRestClientCoinFuturesApiExchangeData.cs | 14 ++++++++ ...anceRestClientUsdFuturesApiExchangeData.cs | 13 +++++++ .../Models/Spot/BinanceMarkIndexKline.cs | 2 +- 10 files changed, 152 insertions(+), 11 deletions(-) create mode 100644 Binance.Net.UnitTests/Endpoints/CoinFutures/ExchangeData/GetPremiumIndexKlines.txt create mode 100644 Binance.Net.UnitTests/Endpoints/UsdFutures/ExchangeData/GetPremiumIndexKlines.txt diff --git a/Binance.Net.UnitTests/BinanceRestIntegrationTests.cs b/Binance.Net.UnitTests/BinanceRestIntegrationTests.cs index 4b3c9b1e1..e8d36ec2a 100644 --- a/Binance.Net.UnitTests/BinanceRestIntegrationTests.cs +++ b/Binance.Net.UnitTests/BinanceRestIntegrationTests.cs @@ -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); @@ -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); diff --git a/Binance.Net.UnitTests/Endpoints/CoinFutures/ExchangeData/GetPremiumIndexKlines.txt b/Binance.Net.UnitTests/Endpoints/CoinFutures/ExchangeData/GetPremiumIndexKlines.txt new file mode 100644 index 000000000..3cf0a50b6 --- /dev/null +++ b/Binance.Net.UnitTests/Endpoints/CoinFutures/ExchangeData/GetPremiumIndexKlines.txt @@ -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" + ] +] \ No newline at end of file diff --git a/Binance.Net.UnitTests/Endpoints/UsdFutures/ExchangeData/GetPremiumIndexKlines.txt b/Binance.Net.UnitTests/Endpoints/UsdFutures/ExchangeData/GetPremiumIndexKlines.txt new file mode 100644 index 000000000..8b6281c45 --- /dev/null +++ b/Binance.Net.UnitTests/Endpoints/UsdFutures/ExchangeData/GetPremiumIndexKlines.txt @@ -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" + ] +] \ No newline at end of file diff --git a/Binance.Net.UnitTests/RestRequestTests.cs b/Binance.Net.UnitTests/RestRequestTests.cs index 8613cd623..b81187311 100644 --- a/Binance.Net.UnitTests/RestRequestTests.cs +++ b/Binance.Net.UnitTests/RestRequestTests.cs @@ -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"); @@ -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{ "walletTypes", "walletAssetCost" }); - await tester.ValidateAsync(client => client.SpotApi.Trading.GetPayTradeHistoryAsync(), "GetPayTradeHistory2", "data", new List{ "walletTypes", "walletAssetCost" }); + await tester.ValidateAsync(client => client.SpotApi.Trading.GetPayTradeHistoryAsync(), "GetPayTradeHistory2", "data", new List { "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"); @@ -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"); @@ -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"); diff --git a/Binance.Net/Binance.Net.xml b/Binance.Net/Binance.Net.xml index 86c458526..de91990c8 100644 --- a/Binance.Net/Binance.Net.xml +++ b/Binance.Net/Binance.Net.xml @@ -394,6 +394,9 @@ + + + @@ -2085,6 +2088,9 @@ + + + @@ -5762,6 +5768,19 @@ Cancellation token The candlestick data for the provided symbol + + + Get premium index kline data for the provided symbol + + + The symbol to get the data for, for example `BTCUSD_PERP` + The candlestick timespan + Start time to get candlestick data + End time to get candlestick data + Max number of results + Cancellation token + The candlestick data for the provided symbol + Get funding rate info for symbols that had FundingRateCap/ FundingRateFloor / fundingIntervalHours adjustment @@ -11570,6 +11589,19 @@ Cancellation token + + + Get premium index klines for a symbol + + + The symbol, for example `ETHUSDT` + The kline interval + Filter by start time + Filter by end time + Max number of results + Cancellation token + + Get funding rate info for symbols that had FundingRateCap/ FundingRateFloor / fundingIntervalHours adjustment @@ -16768,7 +16800,7 @@ - Kline for mark or index price + Kline for mark or index price or Premium index diff --git a/Binance.Net/Clients/CoinFuturesApi/BinanceRestClientCoinFuturesApiExchangeData.cs b/Binance.Net/Clients/CoinFuturesApi/BinanceRestClientCoinFuturesApiExchangeData.cs index 4f23ac3b3..0838500e6 100644 --- a/Binance.Net/Clients/CoinFuturesApi/BinanceRestClientCoinFuturesApiExchangeData.cs +++ b/Binance.Net/Clients/CoinFuturesApi/BinanceRestClientCoinFuturesApiExchangeData.cs @@ -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 { @@ -123,7 +122,7 @@ public async Task>> } #endregion - + #region Get Funding Info /// @@ -289,6 +288,27 @@ public async Task>> GetKlinesAsync(stri #endregion + #region Kline/Premium Index + + /// + public async Task>> 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>(request, parameters, ct, requestWeight).ConfigureAwait(false); + } + + #endregion + #region Continuous contract Kline Data /// diff --git a/Binance.Net/Clients/UsdFuturesApi/BinanceRestClientUsdFuturesApiExchangeData.cs b/Binance.Net/Clients/UsdFuturesApi/BinanceRestClientUsdFuturesApiExchangeData.cs index b6a81a79f..beac4bcb8 100644 --- a/Binance.Net/Clients/UsdFuturesApi/BinanceRestClientUsdFuturesApiExchangeData.cs +++ b/Binance.Net/Clients/UsdFuturesApi/BinanceRestClientUsdFuturesApiExchangeData.cs @@ -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 { @@ -319,6 +318,27 @@ public async Task>> GetKlinesAsync(stri #endregion + #region Kline/Premium Index + + /// + public async Task>> 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>(request, parameters, ct, requestWeight).ConfigureAwait(false); + } + + #endregion + #region Symbol Order Book Ticker /// diff --git a/Binance.Net/Interfaces/Clients/CoinFuturesApi/IBinanceRestClientCoinFuturesApiExchangeData.cs b/Binance.Net/Interfaces/Clients/CoinFuturesApi/IBinanceRestClientCoinFuturesApiExchangeData.cs index ff35f9969..024602306 100644 --- a/Binance.Net/Interfaces/Clients/CoinFuturesApi/IBinanceRestClientCoinFuturesApiExchangeData.cs +++ b/Binance.Net/Interfaces/Clients/CoinFuturesApi/IBinanceRestClientCoinFuturesApiExchangeData.cs @@ -82,6 +82,20 @@ public interface IBinanceRestClientCoinFuturesApiExchangeData Task>> GetKlinesAsync(string symbol, KlineInterval interval, DateTime? startTime = null, DateTime? endTime = null, int? limit = null, CancellationToken ct = default); + /// + /// Get premium index kline data for the provided symbol + /// + /// + /// The symbol to get the data for, for example `BTCUSD_PERP` + /// The candlestick timespan + /// Start time to get candlestick data + /// End time to get candlestick data + /// Max number of results + /// Cancellation token + /// The candlestick data for the provided symbol + Task>> GetPremiumIndexKlinesAsync(string symbol, KlineInterval interval, + DateTime? startTime = null, DateTime? endTime = null, int? limit = null, CancellationToken ct = default); + /// /// Get funding rate info for symbols that had FundingRateCap/ FundingRateFloor / fundingIntervalHours adjustment /// diff --git a/Binance.Net/Interfaces/Clients/UsdFuturesApi/IBinanceRestClientUsdFuturesApiExchangeData.cs b/Binance.Net/Interfaces/Clients/UsdFuturesApi/IBinanceRestClientUsdFuturesApiExchangeData.cs index 2f2093bdf..c264d088a 100644 --- a/Binance.Net/Interfaces/Clients/UsdFuturesApi/IBinanceRestClientUsdFuturesApiExchangeData.cs +++ b/Binance.Net/Interfaces/Clients/UsdFuturesApi/IBinanceRestClientUsdFuturesApiExchangeData.cs @@ -47,6 +47,19 @@ public interface IBinanceRestClientUsdFuturesApiExchangeData /// Task>> GetKlinesAsync(string symbol, KlineInterval interval, DateTime? startTime = null, DateTime? endTime = null, int? limit = null, CancellationToken ct = default); + /// + /// Get premium index klines for a symbol + /// + /// + /// The symbol, for example `ETHUSDT` + /// The kline interval + /// Filter by start time + /// Filter by end time + /// Max number of results + /// Cancellation token + /// + Task>> GetPremiumIndexKlinesAsync(string symbol, KlineInterval interval, DateTime? startTime = null, DateTime? endTime = null, int? limit = null, CancellationToken ct = default); + /// /// Get funding rate info for symbols that had FundingRateCap/ FundingRateFloor / fundingIntervalHours adjustment /// diff --git a/Binance.Net/Objects/Models/Spot/BinanceMarkIndexKline.cs b/Binance.Net/Objects/Models/Spot/BinanceMarkIndexKline.cs index e1022f509..484929ebb 100644 --- a/Binance.Net/Objects/Models/Spot/BinanceMarkIndexKline.cs +++ b/Binance.Net/Objects/Models/Spot/BinanceMarkIndexKline.cs @@ -3,7 +3,7 @@ namespace Binance.Net.Objects.Models.Spot { /// - /// Kline for mark or index price + /// Kline for mark or index price or Premium index /// [JsonConverter(typeof(ArrayConverter))] public record BinanceMarkIndexKline