/// <summary>
        /// Updates existing order using Alpaca REST API endpoint.
        /// </summary>
        /// <param name="request">Patch order request parameters.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        /// <returns>Read-only order information object for updated order.</returns>
        public async Task <IOrder> PatchOrderAsync(
            ChangeOrderRequest request,
            CancellationToken cancellationToken = default)
        {
            request.EnsureNotNull(nameof(request)).Validate();

            var changeOrder = new JsonChangeOrder
            {
                Quantity      = request.Quantity,
                TimeInForce   = request.Duration,
                LimitPrice    = request.LimitPrice,
                StopPrice     = request.StopPrice,
                ClientOrderId = request.ClientOrderId,
            };

            await _alpacaRestApiThrottler.WaitToProceed(cancellationToken).ConfigureAwait(false);

            using var httpRequest = new HttpRequestMessage(_httpMethodPatch,
                                                           new Uri($"orders/{request.OrderId:D}", UriKind.RelativeOrAbsolute))
                  {
                      Content = toStringContent(changeOrder)
                  };

            using var response = await _httpClient.SendAsync(httpRequest, cancellationToken)
                                 .ConfigureAwait(false);

            return(await response.DeserializeAsync <IOrder, JsonOrder>()
                   .ConfigureAwait(false));
        }
예제 #2
0
 /// <inheritdoc />
 public Task <IOrder> PatchOrderAsync(
     ChangeOrderRequest request,
     CancellationToken cancellationToken = default) =>
 _httpClient.PatchAsync <IOrder, JsonOrder, ChangeOrderRequest>(
     request.EnsureNotNull(nameof(request)).Validate().GetEndpointUri(),
     request, _alpacaRestApiThrottler, cancellationToken);