/// <summary>
        /// Add new watch list object into Alpaca REST API endpoint.
        /// </summary>
        /// <param name="request">New watch list 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>Newly created watch list object.</returns>
        public async Task <IWatchList> CreateWatchListAsync(
            NewWatchListRequest request,
            CancellationToken cancellationToken = default)
        {
            request.EnsureNotNull(nameof(request)).Validate();

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

            using var content  = toStringContent(request.Name, request.Assets);
            using var response = await _httpClient.PostAsync(
                      new Uri ("watchlists", UriKind.RelativeOrAbsolute), content, cancellationToken)
                                 .ConfigureAwait(false);

            return(await response.DeserializeAsync <IWatchList, JsonWatchList>()
                   .ConfigureAwait(false));
        }
示例#2
0
 /// <inheritdoc />
 public Task <IWatchList> CreateWatchListAsync(
     NewWatchListRequest request,
     CancellationToken cancellationToken = default) =>
 _httpClient.PostAsync <IWatchList, JsonWatchList, NewWatchListRequest>(
     "v2/watchlists", request, cancellationToken);