Skip to content

Commit

Permalink
Added modify order to kucoin hf (#225)
Browse files Browse the repository at this point in the history
Co-authored-by: Ignas Vienazindys <[email protected]>
  • Loading branch information
IgnasVi and ignas-nord authored Jun 15, 2024
1 parent 48d3e12 commit 3cd4772
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Kucoin.Net/Clients/SpotApi/KucoinRestClientSpotApiProAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,34 @@ public async Task<WebCallResult<KucoinNewOrder>> PlaceOrderAsync(
_baseClient.InvokeOrderPlaced(new OrderId { SourceObject = result.Data, Id = result.Data.Id });
return result;
}

/// <inheritdoc />
public async Task<WebCallResult<KucoinModifiedOrder>> ModifyOrderAsync(
string symbol,
string? orderId = null,
string? clientOrderId = null,
decimal? newQuantity = null,
decimal? newPrice = null,
CancellationToken ct = default)
{
if (!newQuantity.HasValue && !newPrice.HasValue)
throw new ArgumentException("Must choose order parameter to edit");

if ((orderId is not null && clientOrderId is not null) || (orderId is null && clientOrderId is null))
throw new ArgumentException("Must choose one order id");

var parameters = new ParameterCollection
{
{ "symbol", symbol }
};
parameters.AddOptionalParameter("clientOid", clientOrderId);
parameters.AddOptionalParameter("orderId", orderId);
parameters.AddOptionalParameter("newPrice", newPrice);
parameters.AddOptionalParameter("newSize", newQuantity);

var request = _definitions.GetOrCreate(HttpMethod.Post, $"api/v1/hf/orders/alter", KucoinExchange.RateLimiter.SpotRest, 3, true);
return await _baseClient.SendAsync<KucoinModifiedOrder>(request, parameters, ct).ConfigureAwait(false);
}

/// <inheritdoc />
public async Task<WebCallResult<KucoinCanceledOrders>> CancelOrderAsync(string orderId, string symbol, CancellationToken ct = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,25 @@ Task<WebCallResult<KucoinNewOrder>> PlaceOrderAsync(
string? clientOrderId = null,
SelfTradePrevention? selfTradePrevention = null,
CancellationToken ct = default);

/// <summary>
/// Modify an order
/// <para><a href="https://www.kucoin.com/docs/rest/spot-trading/spot-hf-trade-pro-account/modify-hf-order" /></para>
/// </summary>
/// <param name="symbol">Trading pair, such as ETH-BTC</param>
/// <param name="orderId">The id of the order to modify</param>
/// <param name="clientOrderId">The client id of the order to modify</param>
/// <param name="newQuantity">New order quantity</param>
/// <param name="newPrice">New order price</param>
/// <param name="ct">Cancellation token</param>
/// <returns>The id of the modified order</returns>
Task<WebCallResult<KucoinModifiedOrder>> ModifyOrderAsync(
string symbol,
string? orderId = null,
string? clientOrderId = null,
decimal? newQuantity = null,
decimal? newPrice = null,
CancellationToken ct = default);

/// <summary>
/// Cancel an order
Expand Down
26 changes: 26 additions & 0 deletions Kucoin.Net/Kucoin.Net.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Kucoin.Net/Objects/Models/Spot/KucoinModifiedOrder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Newtonsoft.Json;

namespace Kucoin.Net.Objects.Models.Spot;

/// <summary>
/// New order id
/// </summary>
public class KucoinModifiedOrder
{
/// <summary>
/// The id of the new order
/// </summary>
[JsonProperty("newOrderId")]
public string Id { get; set; } = string.Empty;
}

0 comments on commit 3cd4772

Please sign in to comment.