From 5808ed6f678b1499f112b2098feb5274a538dd27 Mon Sep 17 00:00:00 2001 From: Robert Massa Date: Mon, 4 Nov 2024 14:57:25 +0100 Subject: [PATCH] Add PriceMatch parameter to order editing --- Binance.Net.UnitTests/RestRequestTests.cs | 2 +- Binance.Net/Binance.Net.xml | 15 +++++++++++---- .../BinanceRestClientUsdFuturesApiTrading.cs | 8 +++++--- .../BinanceSocketClientUsdFuturesApiTrading.cs | 5 +++-- .../IBinanceRestClientUsdFuturesApiTrading.cs | 3 ++- .../IBinanceSocketClientUsdFuturesApiTrading.cs | 3 ++- .../Futures/BinanceFuturesBatchEditOrder.cs | 6 +++++- 7 files changed, 29 insertions(+), 13 deletions(-) diff --git a/Binance.Net.UnitTests/RestRequestTests.cs b/Binance.Net.UnitTests/RestRequestTests.cs index f48cc9ff7..0d7a1c168 100644 --- a/Binance.Net.UnitTests/RestRequestTests.cs +++ b/Binance.Net.UnitTests/RestRequestTests.cs @@ -283,7 +283,7 @@ public async Task ValidateUsdFuturesTradingCalls() await tester.ValidateAsync(client => client.UsdFuturesApi.Trading.GetOrderEditHistoryAsync("ETHUSDT", 123), "GetOrderEditHistory"); await tester.ValidateAsync(client => client.UsdFuturesApi.Trading.CancelOrderAsync("ETHUSDT", 123), "CancelOrder"); await tester.ValidateAsync(client => client.UsdFuturesApi.Trading.CancelAllOrdersAsync("ETHUSDT"), "CancelAllOrders"); - await tester.ValidateAsync(client => client.UsdFuturesApi.Trading.EditOrderAsync("ETHUSDT", Enums.OrderSide.Buy, 1, 1, 123), "EditOrder"); + await tester.ValidateAsync(client => client.UsdFuturesApi.Trading.EditOrderAsync("ETHUSDT", Enums.OrderSide.Buy, 1, 1, Enums.PriceMatch.None, 123), "EditOrder"); await tester.ValidateAsync(client => client.UsdFuturesApi.Trading.EditMultipleOrdersAsync(new[] { new BinanceFuturesBatchEditOrder() }), "EditMultipleOrders", skipResponseValidation: true); await tester.ValidateAsync(client => client.UsdFuturesApi.Trading.CancelAllOrdersAfterTimeoutAsync("ETHUSDT", TimeSpan.Zero), "CancelAllOrdersAfterTimeout"); await tester.ValidateAsync(client => client.UsdFuturesApi.Trading.CancelMultipleOrdersAsync("ETHUSDT", new List { 123 }), "CancelMultipleOrders", skipResponseValidation: true); diff --git a/Binance.Net/Binance.Net.xml b/Binance.Net/Binance.Net.xml index 332bc9f48..a685cfef9 100644 --- a/Binance.Net/Binance.Net.xml +++ b/Binance.Net/Binance.Net.xml @@ -2214,7 +2214,7 @@ - + @@ -2434,7 +2434,7 @@ - + @@ -12288,7 +12288,7 @@ Cancellation token Id's for canceled order - + Edit an existing order @@ -12297,6 +12297,7 @@ Order side New quantity New price + Only avaliable for Limit/Stop/TakeProfit order Order id of the order to edit Client order id of the order to edit The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request @@ -12999,7 +13000,7 @@ The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request Cancellation token - + Edit an existing order @@ -13008,6 +13009,7 @@ Order side New quantity New price + Only avaliable for Limit/Stop/TakeProfit order Order id of the order to edit Client order id of the order to edit The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request @@ -26215,6 +26217,11 @@ Price + + + PriceMatch + + Parameters for a new futures batch order diff --git a/Binance.Net/Clients/UsdFuturesApi/BinanceRestClientUsdFuturesApiTrading.cs b/Binance.Net/Clients/UsdFuturesApi/BinanceRestClientUsdFuturesApiTrading.cs index 3deb876ed..53a1ebd21 100644 --- a/Binance.Net/Clients/UsdFuturesApi/BinanceRestClientUsdFuturesApiTrading.cs +++ b/Binance.Net/Clients/UsdFuturesApi/BinanceRestClientUsdFuturesApiTrading.cs @@ -295,7 +295,7 @@ public async Task> CancelAllOrdersA #region Edit Order /// - public async Task> EditOrderAsync(string symbol, OrderSide side, decimal quantity, decimal price, long? orderId = null, string? origClientOrderId = null, long? receiveWindow = null, CancellationToken ct = default) + public async Task> EditOrderAsync(string symbol, OrderSide side, decimal quantity, decimal? price = null, PriceMatch? priceMatch = null, long? orderId = null, string? origClientOrderId = null, long? receiveWindow = null, CancellationToken ct = default) { if (!orderId.HasValue && string.IsNullOrEmpty(origClientOrderId)) throw new ArgumentException("Either orderId or origClientOrderId must be sent"); @@ -308,8 +308,9 @@ public async Task> EditOrderAsync(string s { "symbol", symbol }, { "side", EnumConverter.GetString(side) }, { "quantity", quantity.ToString(CultureInfo.InvariantCulture) }, - { "price", price.ToString(CultureInfo.InvariantCulture) }, }; + parameters.AddOptionalParameter("price", price?.ToString(CultureInfo.InvariantCulture)); + parameters.AddOptionalEnum("priceMatch", priceMatch); parameters.AddOptionalParameter("orderId", orderId?.ToString(CultureInfo.InvariantCulture)); parameters.AddOptionalParameter("origClientOrderId", origClientOrderId); parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); @@ -341,8 +342,9 @@ public async Task>> { { "symbol", order.Symbol }, { "quantity", order.Quantity.ToString(CultureInfo.InvariantCulture) }, - { "price", order.Price.ToString(CultureInfo.InvariantCulture) }, }; + orderParameters.AddOptionalParameter("price", order.Price?.ToString(CultureInfo.InvariantCulture)); + orderParameters.AddOptionalEnum("priceMatch", order.PriceMatch); orderParameters.AddEnum("side", order.Side); orderParameters.AddOptionalParameter("orderId", order.OrderId?.ToString(CultureInfo.InvariantCulture)); orderParameters.AddOptionalParameter("origClientOrderId", clientOrderId); diff --git a/Binance.Net/Clients/UsdFuturesApi/BinanceSocketClientUsdFuturesApiTrading.cs b/Binance.Net/Clients/UsdFuturesApi/BinanceSocketClientUsdFuturesApiTrading.cs index 8a85650f3..26bcc0cc0 100644 --- a/Binance.Net/Clients/UsdFuturesApi/BinanceSocketClientUsdFuturesApiTrading.cs +++ b/Binance.Net/Clients/UsdFuturesApi/BinanceSocketClientUsdFuturesApiTrading.cs @@ -89,7 +89,7 @@ public async Task>> PlaceOrde #region Edit Order /// - public async Task>> EditOrderAsync(string symbol, OrderSide side, decimal quantity, decimal price, long? orderId = null, string? origClientOrderId = null, long? receiveWindow = null, CancellationToken ct = default) + public async Task>> EditOrderAsync(string symbol, OrderSide side, decimal quantity, decimal? price = null, PriceMatch? priceMatch = null, long? orderId = null, string? origClientOrderId = null, long? receiveWindow = null, CancellationToken ct = default) { if (!orderId.HasValue && string.IsNullOrEmpty(origClientOrderId)) throw new ArgumentException("Either orderId or origClientOrderId must be sent"); @@ -102,8 +102,9 @@ public async Task>> EditOrder { "symbol", symbol }, { "side", EnumConverter.GetString(side) }, { "quantity", quantity.ToString(CultureInfo.InvariantCulture) }, - { "price", price.ToString(CultureInfo.InvariantCulture) }, }; + parameters.AddOptionalParameter("price", price?.ToString(CultureInfo.InvariantCulture)); + parameters.AddOptionalEnum("priceMatch", priceMatch); parameters.AddOptionalParameter("orderId", orderId?.ToString(CultureInfo.InvariantCulture)); parameters.AddOptionalParameter("origClientOrderId", origClientOrderId); parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture)); diff --git a/Binance.Net/Interfaces/Clients/UsdFuturesApi/IBinanceRestClientUsdFuturesApiTrading.cs b/Binance.Net/Interfaces/Clients/UsdFuturesApi/IBinanceRestClientUsdFuturesApiTrading.cs index 6c900cdf4..16905e612 100644 --- a/Binance.Net/Interfaces/Clients/UsdFuturesApi/IBinanceRestClientUsdFuturesApiTrading.cs +++ b/Binance.Net/Interfaces/Clients/UsdFuturesApi/IBinanceRestClientUsdFuturesApiTrading.cs @@ -137,12 +137,13 @@ Task>>> PlaceMultip /// Order side /// New quantity /// New price + /// Only avaliable for Limit/Stop/TakeProfit order /// Order id of the order to edit /// Client order id of the order to edit /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request /// Cancellation token /// - Task> EditOrderAsync(string symbol, OrderSide side, decimal quantity, decimal price, long? orderId = null, string? origClientOrderId = null, long? receiveWindow = null, CancellationToken ct = default); + Task> EditOrderAsync(string symbol, OrderSide side, decimal quantity, decimal? price, PriceMatch? priceMatch = null, long? orderId = null, string? origClientOrderId = null, long? receiveWindow = null, CancellationToken ct = default); /// /// Edit multiple existing orders diff --git a/Binance.Net/Interfaces/Clients/UsdFuturesApi/IBinanceSocketClientUsdFuturesApiTrading.cs b/Binance.Net/Interfaces/Clients/UsdFuturesApi/IBinanceSocketClientUsdFuturesApiTrading.cs index dfd0f6c18..18a007c82 100644 --- a/Binance.Net/Interfaces/Clients/UsdFuturesApi/IBinanceSocketClientUsdFuturesApiTrading.cs +++ b/Binance.Net/Interfaces/Clients/UsdFuturesApi/IBinanceSocketClientUsdFuturesApiTrading.cs @@ -64,12 +64,13 @@ Task>> PlaceOrderAsync(string /// Order side /// New quantity /// New price + /// Only avaliable for Limit/Stop/TakeProfit order /// Order id of the order to edit /// Client order id of the order to edit /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request /// Cancellation token /// - Task>> EditOrderAsync(string symbol, OrderSide side, decimal quantity, decimal price, long? orderId = null, string? origClientOrderId = null, long? receiveWindow = null, CancellationToken ct = default); + Task>> EditOrderAsync(string symbol, OrderSide side, decimal quantity, decimal? price = null, PriceMatch? priceMatch = null, long? orderId = null, string? origClientOrderId = null, long? receiveWindow = null, CancellationToken ct = default); /// /// Cancels a pending order diff --git a/Binance.Net/Objects/Models/Futures/BinanceFuturesBatchEditOrder.cs b/Binance.Net/Objects/Models/Futures/BinanceFuturesBatchEditOrder.cs index 218fd29cf..ba13eb093 100644 --- a/Binance.Net/Objects/Models/Futures/BinanceFuturesBatchEditOrder.cs +++ b/Binance.Net/Objects/Models/Futures/BinanceFuturesBatchEditOrder.cs @@ -30,6 +30,10 @@ public record BinanceFuturesBatchEditOrder /// /// Price /// - public decimal Price { get; set; } + public decimal? Price { get; set; } + /// + /// PriceMatch + /// + public PriceMatch? PriceMatch { get; set; } } }