From 74edb5807c9b763e2819e7b7fa13a341d798a2e4 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 b81187311..6c5d8d5e8 100644 --- a/Binance.Net.UnitTests/RestRequestTests.cs +++ b/Binance.Net.UnitTests/RestRequestTests.cs @@ -286,7 +286,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 2ebb3dbba..6e2a427bc 100644 --- a/Binance.Net/Binance.Net.xml +++ b/Binance.Net/Binance.Net.xml @@ -2191,7 +2191,7 @@ - + @@ -2411,7 +2411,7 @@ - + @@ -12186,7 +12186,7 @@ Cancellation token Id's for canceled order - + Edit an existing order @@ -12195,6 +12195,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 @@ -12897,7 +12898,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 @@ -12906,6 +12907,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 @@ -26038,6 +26040,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 7bd83191f..248054a4d 100644 --- a/Binance.Net/Clients/UsdFuturesApi/BinanceRestClientUsdFuturesApiTrading.cs +++ b/Binance.Net/Clients/UsdFuturesApi/BinanceRestClientUsdFuturesApiTrading.cs @@ -284,7 +284,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"); @@ -294,8 +294,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)); @@ -323,8 +324,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", order.ClientOrderId); diff --git a/Binance.Net/Clients/UsdFuturesApi/BinanceSocketClientUsdFuturesApiTrading.cs b/Binance.Net/Clients/UsdFuturesApi/BinanceSocketClientUsdFuturesApiTrading.cs index a71f507ea..e24ba82b5 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"); @@ -99,8 +99,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 ed7cdaddd..0310b0b3d 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; } } }