Skip to content

Commit

Permalink
Add PriceMatch parameter to order editing
Browse files Browse the repository at this point in the history
  • Loading branch information
Grepsy committed Dec 19, 2024
1 parent 5c18ce9 commit 5808ed6
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Binance.Net.UnitTests/RestRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<long> { 123 }), "CancelMultipleOrders", skipResponseValidation: true);
Expand Down
15 changes: 11 additions & 4 deletions Binance.Net/Binance.Net.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2214,7 +2214,7 @@
<member name="M:Binance.Net.Clients.UsdFuturesApi.BinanceRestClientUsdFuturesApiTrading.CancelAllOrdersAsync(System.String,System.Nullable{System.Int64},System.Threading.CancellationToken)">
<inheritdoc />
</member>
<member name="M:Binance.Net.Clients.UsdFuturesApi.BinanceRestClientUsdFuturesApiTrading.EditOrderAsync(System.String,Binance.Net.Enums.OrderSide,System.Decimal,System.Decimal,System.Nullable{System.Int64},System.String,System.Nullable{System.Int64},System.Threading.CancellationToken)">
<member name="M:Binance.Net.Clients.UsdFuturesApi.BinanceRestClientUsdFuturesApiTrading.EditOrderAsync(System.String,Binance.Net.Enums.OrderSide,System.Decimal,System.Nullable{System.Decimal},System.Nullable{Binance.Net.Enums.PriceMatch},System.Nullable{System.Int64},System.String,System.Nullable{System.Int64},System.Threading.CancellationToken)">
<inheritdoc />
</member>
<member name="M:Binance.Net.Clients.UsdFuturesApi.BinanceRestClientUsdFuturesApiTrading.EditMultipleOrdersAsync(System.Collections.Generic.IEnumerable{Binance.Net.Objects.Models.Futures.BinanceFuturesBatchEditOrder},System.Nullable{System.Int32},System.Threading.CancellationToken)">
Expand Down Expand Up @@ -2434,7 +2434,7 @@
<member name="M:Binance.Net.Clients.UsdFuturesApi.BinanceSocketClientUsdFuturesApiTrading.PlaceOrderAsync(System.String,Binance.Net.Enums.OrderSide,Binance.Net.Enums.FuturesOrderType,System.Nullable{System.Decimal},System.Nullable{System.Decimal},System.Nullable{Binance.Net.Enums.PositionSide},System.Nullable{Binance.Net.Enums.TimeInForce},System.Nullable{System.Boolean},System.String,System.Nullable{System.Decimal},System.Nullable{System.Decimal},System.Nullable{System.Decimal},System.Nullable{Binance.Net.Enums.WorkingType},System.Nullable{System.Boolean},System.Nullable{Binance.Net.Enums.OrderResponseType},System.Nullable{System.Boolean},System.Nullable{Binance.Net.Enums.PriceMatch},System.Nullable{Binance.Net.Enums.SelfTradePreventionMode},System.Nullable{System.DateTime},System.Nullable{System.Int32},System.Threading.CancellationToken)">
<inheritdoc />
</member>
<member name="M:Binance.Net.Clients.UsdFuturesApi.BinanceSocketClientUsdFuturesApiTrading.EditOrderAsync(System.String,Binance.Net.Enums.OrderSide,System.Decimal,System.Decimal,System.Nullable{System.Int64},System.String,System.Nullable{System.Int64},System.Threading.CancellationToken)">
<member name="M:Binance.Net.Clients.UsdFuturesApi.BinanceSocketClientUsdFuturesApiTrading.EditOrderAsync(System.String,Binance.Net.Enums.OrderSide,System.Decimal,System.Nullable{System.Decimal},System.Nullable{Binance.Net.Enums.PriceMatch},System.Nullable{System.Int64},System.String,System.Nullable{System.Int64},System.Threading.CancellationToken)">
<inheritdoc />
</member>
<member name="M:Binance.Net.Clients.UsdFuturesApi.BinanceSocketClientUsdFuturesApiTrading.CancelOrderAsync(System.String,System.Nullable{System.Int64},System.String,System.Nullable{System.Int64},System.Threading.CancellationToken)">
Expand Down Expand Up @@ -12288,7 +12288,7 @@
<param name="ct">Cancellation token</param>
<returns>Id's for canceled order</returns>
</member>
<member name="M:Binance.Net.Interfaces.Clients.UsdFuturesApi.IBinanceRestClientUsdFuturesApiTrading.EditOrderAsync(System.String,Binance.Net.Enums.OrderSide,System.Decimal,System.Decimal,System.Nullable{System.Int64},System.String,System.Nullable{System.Int64},System.Threading.CancellationToken)">
<member name="M:Binance.Net.Interfaces.Clients.UsdFuturesApi.IBinanceRestClientUsdFuturesApiTrading.EditOrderAsync(System.String,Binance.Net.Enums.OrderSide,System.Decimal,System.Nullable{System.Decimal},System.Nullable{Binance.Net.Enums.PriceMatch},System.Nullable{System.Int64},System.String,System.Nullable{System.Int64},System.Threading.CancellationToken)">
<summary>
Edit an existing order
<para><a href="https://binance-docs.github.io/apidocs/futures/en/#modify-order-trade" /></para>
Expand All @@ -12297,6 +12297,7 @@
<param name="side">Order side</param>
<param name="quantity">New quantity</param>
<param name="price">New price</param>
<param name="priceMatch">Only avaliable for Limit/Stop/TakeProfit order</param>
<param name="orderId">Order id of the order to edit</param>
<param name="origClientOrderId">Client order id of the order to edit</param>
<param name="receiveWindow">The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request</param>
Expand Down Expand Up @@ -12999,7 +13000,7 @@
<param name="receiveWindow">The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request</param>
<param name="ct">Cancellation token</param>
</member>
<member name="M:Binance.Net.Interfaces.Clients.UsdFuturesApi.IBinanceSocketClientUsdFuturesApiTrading.EditOrderAsync(System.String,Binance.Net.Enums.OrderSide,System.Decimal,System.Decimal,System.Nullable{System.Int64},System.String,System.Nullable{System.Int64},System.Threading.CancellationToken)">
<member name="M:Binance.Net.Interfaces.Clients.UsdFuturesApi.IBinanceSocketClientUsdFuturesApiTrading.EditOrderAsync(System.String,Binance.Net.Enums.OrderSide,System.Decimal,System.Nullable{System.Decimal},System.Nullable{Binance.Net.Enums.PriceMatch},System.Nullable{System.Int64},System.String,System.Nullable{System.Int64},System.Threading.CancellationToken)">
<summary>
Edit an existing order
<para><a href="https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Modify-Order" /></para>
Expand All @@ -13008,6 +13009,7 @@
<param name="side">Order side</param>
<param name="quantity">New quantity</param>
<param name="price">New price</param>
<param name="priceMatch">Only avaliable for Limit/Stop/TakeProfit order</param>
<param name="orderId">Order id of the order to edit</param>
<param name="origClientOrderId">Client order id of the order to edit</param>
<param name="receiveWindow">The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request</param>
Expand Down Expand Up @@ -26215,6 +26217,11 @@
Price
</summary>
</member>
<member name="P:Binance.Net.Objects.Models.Futures.BinanceFuturesBatchEditOrder.PriceMatch">
<summary>
PriceMatch
</summary>
</member>
<member name="T:Binance.Net.Objects.Models.Futures.BinanceFuturesBatchOrder">
<summary>
Parameters for a new futures batch order
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public async Task<WebCallResult<BinanceFuturesCancelAllOrders>> CancelAllOrdersA
#region Edit Order

/// <inheritdoc />
public async Task<WebCallResult<BinanceUsdFuturesOrder>> EditOrderAsync(string symbol, OrderSide side, decimal quantity, decimal price, long? orderId = null, string? origClientOrderId = null, long? receiveWindow = null, CancellationToken ct = default)
public async Task<WebCallResult<BinanceUsdFuturesOrder>> 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");
Expand All @@ -308,8 +308,9 @@ public async Task<WebCallResult<BinanceUsdFuturesOrder>> 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));
Expand Down Expand Up @@ -341,8 +342,9 @@ public async Task<WebCallResult<IEnumerable<CallResult<BinanceUsdFuturesOrder>>>
{
{ "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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public async Task<CallResult<BinanceResponse<BinanceUsdFuturesOrder>>> PlaceOrde
#region Edit Order

/// <inheritdoc />
public async Task<CallResult<BinanceResponse<BinanceUsdFuturesOrder>>> EditOrderAsync(string symbol, OrderSide side, decimal quantity, decimal price, long? orderId = null, string? origClientOrderId = null, long? receiveWindow = null, CancellationToken ct = default)
public async Task<CallResult<BinanceResponse<BinanceUsdFuturesOrder>>> 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");
Expand All @@ -102,8 +102,9 @@ public async Task<CallResult<BinanceResponse<BinanceUsdFuturesOrder>>> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,13 @@ Task<WebCallResult<IEnumerable<CallResult<BinanceUsdFuturesOrder>>>> PlaceMultip
/// <param name="side">Order side</param>
/// <param name="quantity">New quantity</param>
/// <param name="price">New price</param>
/// <param name="priceMatch">Only avaliable for Limit/Stop/TakeProfit order</param>
/// <param name="orderId">Order id of the order to edit</param>
/// <param name="origClientOrderId">Client order id of the order to edit</param>
/// <param name="receiveWindow">The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request</param>
/// <param name="ct">Cancellation token</param>
/// <returns></returns>
Task<WebCallResult<BinanceUsdFuturesOrder>> EditOrderAsync(string symbol, OrderSide side, decimal quantity, decimal price, long? orderId = null, string? origClientOrderId = null, long? receiveWindow = null, CancellationToken ct = default);
Task<WebCallResult<BinanceUsdFuturesOrder>> EditOrderAsync(string symbol, OrderSide side, decimal quantity, decimal? price, PriceMatch? priceMatch = null, long? orderId = null, string? origClientOrderId = null, long? receiveWindow = null, CancellationToken ct = default);

/// <summary>
/// Edit multiple existing orders
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@ Task<CallResult<BinanceResponse<BinanceUsdFuturesOrder>>> PlaceOrderAsync(string
/// <param name="side">Order side</param>
/// <param name="quantity">New quantity</param>
/// <param name="price">New price</param>
/// <param name="priceMatch">Only avaliable for Limit/Stop/TakeProfit order</param>
/// <param name="orderId">Order id of the order to edit</param>
/// <param name="origClientOrderId">Client order id of the order to edit</param>
/// <param name="receiveWindow">The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request</param>
/// <param name="ct">Cancellation token</param>
/// <returns></returns>
Task<CallResult<BinanceResponse<BinanceUsdFuturesOrder>>> EditOrderAsync(string symbol, OrderSide side, decimal quantity, decimal price, long? orderId = null, string? origClientOrderId = null, long? receiveWindow = null, CancellationToken ct = default);
Task<CallResult<BinanceResponse<BinanceUsdFuturesOrder>>> 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);

/// <summary>
/// Cancels a pending order
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public record BinanceFuturesBatchEditOrder
/// <summary>
/// Price
/// </summary>
public decimal Price { get; set; }
public decimal? Price { get; set; }
/// <summary>
/// PriceMatch
/// </summary>
public PriceMatch? PriceMatch { get; set; }
}
}

0 comments on commit 5808ed6

Please sign in to comment.