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

Add PriceMatch parameter to order editing #1440

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 1 addition & 1 deletion Binance.Net.UnitTests/RestRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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 @@ -2191,7 +2191,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 @@ -2411,7 +2411,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 @@ -12186,7 +12186,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 @@ -12195,6 +12195,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 @@ -12897,7 +12898,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 @@ -12906,6 +12907,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 @@ -26038,6 +26040,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 @@ -284,7 +284,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 @@ -294,8 +294,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));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the documentation the price is required for USD futures

Copy link
Author

@Grepsy Grepsy Nov 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that, it's a bit contradictory because the parameter itself is there and mentions:

only avaliable for LIMIT/STOP/TAKE_PROFIT order; can be set to OPPONENT/ OPPONENT_5/ OPPONENT_10/ OPPONENT_20: /QUEUE/ QUEUE_5/ QUEUE_10/ QUEUE_20; Can't be passed together with price

I'll do some testing to see whether it gets accepted.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested it using the locally generated nuget package and the call does get accepted.

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 @@ -323,8 +324,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", order.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 @@ -99,8 +99,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; }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the actual model which gets send, you'll need to copy it in the actual EditMultipleOrdersAsync methods

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's being added to the orderParameters collection from this model like this:

orderParameters.AddOptionalEnum("priceMatch", order.PriceMatch);

Is that what you mean or do I misunderstand?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is added in the Coin futures I see, but not in the USD futures EditMultipleOrdersAsync method right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you mean the other way around :-) It's added on Usd but not Coin, I'll fix that!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any Edit* methods implemented on the BinanceRestClientCoinFuturesApiTrading. To be clear the changes I did are on UsdFuturesApi, both REST and Socket. Hope it makes sense.

}
}