Skip to content

Commit

Permalink
Added FuturesApi.Trading.PlaceTpSlOrderAsync endpoint, added ClientOr…
Browse files Browse the repository at this point in the history
…derId property to futures order placement response
  • Loading branch information
JKorf committed Aug 28, 2024
1 parent abb00c5 commit b38e6fe
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Kucoin.Net.UnitTests/Endpoints/Futures/Trading/PlaceTpSlOrder.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
POST
/api/v1/st-orders
true
{
"code": "200000",
"data": {
"orderId": "5bd6e9286d99522a52e458de",
"clientOid": "5c52e11203aa677f33e493fb"
}
}
1 change: 1 addition & 0 deletions Kucoin.Net.UnitTests/RestRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ public async Task ValidateFuturesTradingCalls()
var tester = new RestRequestValidator<KucoinRestClient>(client, "Endpoints/Futures/Trading", "https://api-futures.kucoin.com", IsAuthenticated, "data", stjCompare: false);
await tester.ValidateAsync(client => client.FuturesApi.Trading.PlaceOrderAsync("ETHUSDT", Enums.OrderSide.Buy, Enums.NewOrderType.Market, 1, 1), "PlaceOrder");
await tester.ValidateAsync(client => client.FuturesApi.Trading.PlaceTestOrderAsync("ETHUSDT", Enums.OrderSide.Buy, Enums.NewOrderType.Market, 1, 1), "PlaceTestOrder");
await tester.ValidateAsync(client => client.FuturesApi.Trading.PlaceTpSlOrderAsync("ETHUSDT", Enums.OrderSide.Buy, Enums.NewOrderType.Market, 1, 1), "PlaceTpSlOrder");
await tester.ValidateAsync(client => client.FuturesApi.Trading.PlaceMultipleOrdersAsync(new[] { new KucoinFuturesOrderRequestEntry() }), "PlaceMultipleOrders");
await tester.ValidateAsync(client => client.FuturesApi.Trading.CancelOrderAsync("123"), "CancelOrder");
await tester.ValidateAsync(client => client.FuturesApi.Trading.CancelOrderByClientOrderIdAsync("ETHUSDT", "123"), "CancelOrderByClientOrderId");
Expand Down
52 changes: 52 additions & 0 deletions Kucoin.Net/Clients/FuturesApi/KucoinRestClientFuturesApiTrading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,58 @@ public async Task<WebCallResult<KucoinOrderId>> PlaceTestOrderAsync(
return await _baseClient.SendAsync<KucoinOrderId>(request, parameters, ct).ConfigureAwait(false);
}

/// <inheritdoc />
public async Task<WebCallResult<KucoinOrderId>> PlaceTpSlOrderAsync(
string symbol,
OrderSide side,
NewOrderType type,
decimal leverage,
int quantity,

decimal? price = null,
TimeInForce? timeInForce = null,
bool? postOnly = null,
bool? hidden = null,
bool? iceberg = null,
decimal? visibleSize = null,

string? remark = null,
decimal? takeProfitPrice = null,
decimal? stopLossPrice = null,
StopPriceType? stopPriceType = null,
bool? reduceOnly = null,
bool? closeOrder = null,
bool? forceHold = null,
string? clientOrderId = null,
SelfTradePrevention? selfTradePrevention = null,
CancellationToken ct = default)
{
var parameters = new ParameterCollection();
parameters.AddParameter("symbol", symbol);
parameters.AddParameter("side", JsonConvert.SerializeObject(side, new OrderSideConverter(false)));
parameters.AddParameter("type", JsonConvert.SerializeObject(type, new NewOrderTypeConverter(false)));
parameters.AddParameter("leverage", leverage.ToString(CultureInfo.InvariantCulture));
parameters.AddParameter("size", quantity.ToString(CultureInfo.InvariantCulture));
parameters.AddParameter("clientOid", clientOrderId ?? Guid.NewGuid().ToString());
parameters.AddOptionalParameter("remark", remark);
parameters.AddOptionalString("triggerStopUpPrice", takeProfitPrice);
parameters.AddOptionalParameter("stopPriceType", stopPriceType != null ? JsonConvert.SerializeObject(stopPriceType, new StopPriceTypeConverter(false)) : null);
parameters.AddOptionalString("triggerStopDownPrice", stopLossPrice);
parameters.AddOptionalParameter("reduceOnly", reduceOnly?.ToString());
parameters.AddOptionalParameter("closeOrder", closeOrder?.ToString());
parameters.AddOptionalParameter("forceHold", forceHold?.ToString());
parameters.AddOptionalParameter("price", price?.ToString(CultureInfo.InvariantCulture));
parameters.AddOptionalParameter("timeInForce", timeInForce != null ? JsonConvert.SerializeObject(timeInForce, new TimeInForceConverter(false)) : null);
parameters.AddOptionalParameter("postOnly", postOnly?.ToString());
parameters.AddOptionalParameter("hidden", hidden?.ToString());
parameters.AddOptionalParameter("iceberg", iceberg);
parameters.AddOptionalParameter("visibleSize", visibleSize?.ToString());
parameters.AddOptionalEnum("stp", selfTradePrevention);

var request = _definitions.GetOrCreate(HttpMethod.Post, $"api/v1/st-orders", KucoinExchange.RateLimiter.FuturesRest, 2, true);
return await _baseClient.SendAsync<KucoinOrderId>(request, parameters, ct).ConfigureAwait(false);
}

/// <inheritdoc />
public async Task<WebCallResult<IEnumerable<KucoinFuturesOrderResult>>> PlaceMultipleOrdersAsync(IEnumerable<KucoinFuturesOrderRequestEntry> orders, CancellationToken ct = default)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,58 @@ Task<WebCallResult<KucoinOrderId>> PlaceTestOrderAsync(
SelfTradePrevention? selfTradePrevention = null,
CancellationToken ct = default);


/// <summary>
/// Place a new take profit / stop loss order
/// <para><a href="https://www.kucoin.com/docs/rest/futures-trading/orders/place-take-profit-and-stop-loss-order" /></para>
/// </summary>
/// <param name="symbol">The contract for the order, for example `XBTUSDM`</param>
/// <param name="side">Side of the order</param>
/// <param name="type">Type of order</param>
/// <param name="leverage">Leverage of the order</param>
/// <param name="price">Limit price, only for limit orders</param>
/// <param name="timeInForce">Time in force, only for limit orders</param>
/// <param name="postOnly">Post only flag, invalid when timeInForce is IOC</param>
/// <param name="hidden">Orders not displaying in order book. When hidden chose</param>
/// <param name="iceberg">Only visible portion of the order is displayed in the order book</param>
/// <param name="visibleSize">The maximum visible size of an iceberg order</param>
/// <param name="quantity">Quantity of contract to buy or sell</param>
/// <param name="remark">Remark for the order</param>
/// <param name="stopPriceType">Price type</param>
/// <param name="takeProfitPrice">Take profit price</param>
/// <param name="stopLossPrice">Stop loss price</param>
/// <param name="reduceOnly">A mark to reduce the position size only. Set to false by default</param>
/// <param name="closeOrder">A mark to close the position. Set to false by default. All the positions will be closed if true</param>
/// <param name="forceHold">A mark to forcely hold the funds for an order, even though it's an order to reduce the position size. This helps the order stay on the order book and not get canceled when the position size changes. Set to false by default</param>
/// <param name="selfTradePrevention">Self Trade Prevention mode</param>
/// <param name="clientOrderId">Client order id</param>
/// <param name="ct">Cancellation token</param>
/// <returns>Order details</returns>
Task<WebCallResult<KucoinOrderId>> PlaceTpSlOrderAsync(
string symbol,
OrderSide side,
NewOrderType type,
decimal leverage,
int quantity,

decimal? price = null,
TimeInForce? timeInForce = null,
bool? postOnly = null,
bool? hidden = null,
bool? iceberg = null,
decimal? visibleSize = null,

string? remark = null,
decimal? takeProfitPrice = null,
decimal? stopLossPrice = null,
StopPriceType? stopPriceType = null,
bool? reduceOnly = null,
bool? closeOrder = null,
bool? forceHold = null,
string? clientOrderId = null,
SelfTradePrevention? selfTradePrevention = null,
CancellationToken ct = default);

/// <summary>
/// Place multiple orders
/// <para><a href="https://www.kucoin.com/docs/rest/futures-trading/orders/place-multiple-orders" /></para>
Expand Down
36 changes: 36 additions & 0 deletions Kucoin.Net/Kucoin.Net.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@
<member name="M:Kucoin.Net.Clients.FuturesApi.KucoinRestClientFuturesApiTrading.PlaceTestOrderAsync(System.String,Kucoin.Net.Enums.OrderSide,Kucoin.Net.Enums.NewOrderType,System.Decimal,System.Int32,System.Nullable{System.Decimal},System.Nullable{Kucoin.Net.Enums.TimeInForce},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Decimal},System.String,System.Nullable{Kucoin.Net.Enums.StopType},System.Nullable{Kucoin.Net.Enums.StopPriceType},System.Nullable{System.Decimal},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.String,System.Nullable{Kucoin.Net.Enums.SelfTradePrevention},System.Threading.CancellationToken)">
<inheritdoc />
</member>
<member name="M:Kucoin.Net.Clients.FuturesApi.KucoinRestClientFuturesApiTrading.PlaceTpSlOrderAsync(System.String,Kucoin.Net.Enums.OrderSide,Kucoin.Net.Enums.NewOrderType,System.Decimal,System.Int32,System.Nullable{System.Decimal},System.Nullable{Kucoin.Net.Enums.TimeInForce},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Decimal},System.String,System.Nullable{System.Decimal},System.Nullable{System.Decimal},System.Nullable{Kucoin.Net.Enums.StopPriceType},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.String,System.Nullable{Kucoin.Net.Enums.SelfTradePrevention},System.Threading.CancellationToken)">
<inheritdoc />
</member>
<member name="M:Kucoin.Net.Clients.FuturesApi.KucoinRestClientFuturesApiTrading.PlaceMultipleOrdersAsync(System.Collections.Generic.IEnumerable{Kucoin.Net.Objects.Models.Futures.KucoinFuturesOrderRequestEntry},System.Threading.CancellationToken)">
<inheritdoc />
</member>
Expand Down Expand Up @@ -2769,6 +2772,34 @@
<param name="ct">Cancellation token</param>
<returns>Order details</returns>
</member>
<member name="M:Kucoin.Net.Interfaces.Clients.FuturesApi.IKucoinRestClientFuturesApiTrading.PlaceTpSlOrderAsync(System.String,Kucoin.Net.Enums.OrderSide,Kucoin.Net.Enums.NewOrderType,System.Decimal,System.Int32,System.Nullable{System.Decimal},System.Nullable{Kucoin.Net.Enums.TimeInForce},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Decimal},System.String,System.Nullable{System.Decimal},System.Nullable{System.Decimal},System.Nullable{Kucoin.Net.Enums.StopPriceType},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.Nullable{System.Boolean},System.String,System.Nullable{Kucoin.Net.Enums.SelfTradePrevention},System.Threading.CancellationToken)">
<summary>
Place a new take profit / stop loss order
<para><a href="https://www.kucoin.com/docs/rest/futures-trading/orders/place-take-profit-and-stop-loss-order" /></para>
</summary>
<param name="symbol">The contract for the order, for example `XBTUSDM`</param>
<param name="side">Side of the order</param>
<param name="type">Type of order</param>
<param name="leverage">Leverage of the order</param>
<param name="price">Limit price, only for limit orders</param>
<param name="timeInForce">Time in force, only for limit orders</param>
<param name="postOnly">Post only flag, invalid when timeInForce is IOC</param>
<param name="hidden">Orders not displaying in order book. When hidden chose</param>
<param name="iceberg">Only visible portion of the order is displayed in the order book</param>
<param name="visibleSize">The maximum visible size of an iceberg order</param>
<param name="quantity">Quantity of contract to buy or sell</param>
<param name="remark">Remark for the order</param>
<param name="stopPriceType">Price type</param>
<param name="takeProfitPrice">Take profit price</param>
<param name="stopLossPrice">Stop loss price</param>
<param name="reduceOnly">A mark to reduce the position size only. Set to false by default</param>
<param name="closeOrder">A mark to close the position. Set to false by default. All the positions will be closed if true</param>
<param name="forceHold">A mark to forcely hold the funds for an order, even though it's an order to reduce the position size. This helps the order stay on the order book and not get canceled when the position size changes. Set to false by default</param>
<param name="selfTradePrevention">Self Trade Prevention mode</param>
<param name="clientOrderId">Client order id</param>
<param name="ct">Cancellation token</param>
<returns>Order details</returns>
</member>
<member name="M:Kucoin.Net.Interfaces.Clients.FuturesApi.IKucoinRestClientFuturesApiTrading.PlaceMultipleOrdersAsync(System.Collections.Generic.IEnumerable{Kucoin.Net.Objects.Models.Futures.KucoinFuturesOrderRequestEntry},System.Threading.CancellationToken)">
<summary>
Place multiple orders
Expand Down Expand Up @@ -10000,6 +10031,11 @@
The id of the order
</summary>
</member>
<member name="P:Kucoin.Net.Objects.Models.Spot.KucoinOrderId.ClientOrderId">
<summary>
The client order id
</summary>
</member>
<member name="T:Kucoin.Net.Objects.Models.Spot.KucoinRedemption">
<summary>
Redemption record
Expand Down
5 changes: 5 additions & 0 deletions Kucoin.Net/Objects/Models/Spot/KucoinOrderId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@ public record KucoinOrderId
/// </summary>
[JsonProperty("orderId")]
public string Id { get; set; } = string.Empty;
/// <summary>
/// The client order id
/// </summary>
[JsonProperty("clientOid")]
public string? ClientOrderId { get; set; }
}
}

0 comments on commit b38e6fe

Please sign in to comment.