/// <summary> /// Cancel an active order. /// </summary> /// <param name="client"></param> /// <param name="user"></param> /// <param name="symbol"></param> /// <param name="orderId"></param> /// <param name="origClientOrderId"></param> /// <param name="newClientOrderId">Used to uniquely identify this cancel. Automatically generated by default.</param> /// <param name="recvWindow"></param> /// <param name="token"></param> /// <returns></returns> public static async Task <string> CancelOrderAsync(this IKucoinHttpClient client, IKucoinApiUser user, string symbol, long orderId = KucoinApi.NullId, string origClientOrderId = null, string newClientOrderId = null, long recvWindow = default, CancellationToken token = default) { Throw.IfNull(client, nameof(client)); Throw.IfNull(user, nameof(user)); Throw.IfNullOrWhiteSpace(symbol, nameof(symbol)); if (orderId < 0 && string.IsNullOrWhiteSpace(origClientOrderId)) { throw new ArgumentException($"Either '{nameof(orderId)}' or '{nameof(origClientOrderId)}' must be provided, but both were invalid."); } if (recvWindow <= 0) { recvWindow = client.Options.RecvWindowDefault ?? 0; } if (user.RateLimiter != null) { await user.RateLimiter.DelayAsync(token : token) .ConfigureAwait(false); } var request = new KucoinHttpRequest("/api/v3/order") { ApiKey = user.ApiKey }; request.AddParameter("symbol", symbol.FormatSymbol()); if (orderId >= 0) { request.AddParameter("orderId", orderId); } if (!string.IsNullOrWhiteSpace(origClientOrderId)) { request.AddParameter("origClientOrderId", origClientOrderId); } if (!string.IsNullOrWhiteSpace(newClientOrderId)) { request.AddParameter("newClientOrderId", newClientOrderId); } if (recvWindow > 0) { request.AddParameter("recvWindow", recvWindow); } await client.SignAsync(request, user, token) .ConfigureAwait(false); return(await client.DeleteAsync(request, token) .ConfigureAwait(false)); }
/// <summary> /// Close out a user data stream. /// </summary> /// <param name="client"></param> /// <param name="apiKey"></param> /// <param name="listenKey"></param> /// <param name="token"></param> /// <returns></returns> public static async Task <string> UserStreamCloseAsync(this IKucoinHttpClient client, string apiKey, string listenKey, CancellationToken token = default) { Throw.IfNullOrWhiteSpace(apiKey, nameof(apiKey)); Throw.IfNullOrWhiteSpace(listenKey, nameof(listenKey)); if (client.RateLimiter != null) { await client.RateLimiter.DelayAsync(token : token) .ConfigureAwait(false); } var request = new KucoinHttpRequest("/api/v1/userDataStream") { ApiKey = apiKey }; request.AddParameter("listenKey", listenKey); return(await client.DeleteAsync(request, token) .ConfigureAwait(false)); }