Esempio n. 1
0
 /// <inheritdoc />
 public async Task <IWatchList> DeleteAssetFromWatchListByNameAsync(
     ChangeWatchListRequest <String> request,
     CancellationToken cancellationToken = default) =>
 await _httpClient.DeleteAsync <IWatchList, JsonWatchList>(
     await getEndpointUriBuilderAsync(
         request.EnsureNotNull(nameof(request)).Validate().Key, request.Asset)
     .ConfigureAwait(false),
     cancellationToken).ConfigureAwait(false);
        /// <summary>
        /// Deletes asset from watch list using Alpaca REST API endpoint by watch list identifier.
        /// </summary>
        /// <param name="request">Asset deleting 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>Updated watch list object with proper <paramref name="request.Key"/> value.</returns>
        public async Task <IWatchList> DeleteAssetFromWatchListByIdAsync(
            ChangeWatchListRequest <Guid> request,
            CancellationToken cancellationToken = default)
        {
            request.EnsureNotNull(nameof(request)).Validate();

            return(await _httpClient.DeleteSingleObjectAsync <IWatchList, JsonWatchList>(
                       _alpacaRestApiThrottler, $"watchlists/{request.Key:D}/{request.Asset}", cancellationToken)
                   .ConfigureAwait(false));
        }
        /// <summary>
        /// Adds asset into watch list using Alpaca REST API endpoint by watch list identifier.
        /// </summary>
        /// <param name="request">Asset adding 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>Updated watch list object with proper <paramref name="request.Key"/> value.</returns>
        public async Task <IWatchList> AddAssetIntoWatchListByIdAsync(
            ChangeWatchListRequest <Guid> request,
            CancellationToken cancellationToken = default)
        {
            request.EnsureNotNull(nameof(request)).Validate();

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

            using var content  = toStringContent(request.Asset);
            using var response = await _httpClient.PostAsync(
                      new Uri ($"watchlists/{request.Key:D}", UriKind.RelativeOrAbsolute), content, cancellationToken)
                                 .ConfigureAwait(false);

            return(await response.DeserializeAsync <IWatchList, JsonWatchList>()
                   .ConfigureAwait(false));
        }
        /// <summary>
        /// Deletes asset from watch list using Alpaca REST API endpoint by watch list name.
        /// </summary>
        /// <param name="request">Asset deleting 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>Updated watch list object with proper <paramref name="request.Key"/> value.</returns>
        public async Task <IWatchList> DeleteAssetFromWatchListByNameAsync(
            ChangeWatchListRequest <String> request,
            CancellationToken cancellationToken = default)
        {
            request.EnsureNotNull(nameof(request)).Validate();

            var builder = new UriBuilder(_httpClient.BaseAddress)
            {
                Path  = _httpClient.BaseAddress.AbsolutePath + $"watchlists:by_name/{request.Asset}",
                Query = new QueryBuilder()
                        .AddParameter("name", request.Key)
            };

            return(await _httpClient
                   .DeleteSingleObjectAsync <IWatchList, JsonWatchList>(
                       _alpacaRestApiThrottler, builder, cancellationToken)
                   .ConfigureAwait(false));
        }
        /// <summary>
        /// Adds asset into watch list using Alpaca REST API endpoint by watch list name.
        /// </summary>
        /// <param name="request">Asset adding 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>Updated watch list object with proper <paramref name="request.Key"/> value.</returns>
        public async Task <IWatchList> AddAssetIntoWatchListByNameAsync(
            ChangeWatchListRequest <String> request,
            CancellationToken cancellationToken = default)
        {
            request.EnsureNotNull(nameof(request)).Validate();

            var builder = new UriBuilder(_httpClient.BaseAddress)
            {
                Path  = _httpClient.BaseAddress.AbsolutePath + "watchlists:by_name",
                Query = new QueryBuilder()
                        .AddParameter("name", request.Key)
            };

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

            using var content  = toStringContent(request.Asset);
            using var response = await _httpClient.PostAsync(builder.Uri, content, cancellationToken)
                                 .ConfigureAwait(false);

            return(await response.DeserializeAsync <IWatchList, JsonWatchList>()
                   .ConfigureAwait(false));
        }
Esempio n. 6
0
 /// <inheritdoc />
 public Task <IWatchList> DeleteAssetFromWatchListByIdAsync(
     ChangeWatchListRequest <Guid> request,
     CancellationToken cancellationToken = default) =>
 _httpClient.DeleteAsync <IWatchList, JsonWatchList>(
     getEndpointUri(request.EnsureNotNull(nameof(request)).Validate().Key, request.Asset),
     cancellationToken);
Esempio n. 7
0
 /// <inheritdoc />
 public Task <IWatchList> AddAssetIntoWatchListByIdAsync(
     ChangeWatchListRequest <Guid> request,
     CancellationToken cancellationToken = default) =>
 _httpClient.PostAsync <IWatchList, JsonWatchList, ChangeWatchListRequest <Guid> >(
     getEndpointUri(request.EnsureNotNull(nameof(request)).Validate().Key), request,
     cancellationToken);
Esempio n. 8
0
 /// <inheritdoc />
 public Task <IWatchList> DeleteAssetFromWatchListByNameAsync(
     ChangeWatchListRequest <String> request,
     CancellationToken cancellationToken = default) =>
 _httpClient.DeleteAsync <IWatchList, JsonWatchList>(
     getEndpointUriBuilder(request.EnsureNotNull(nameof(request)).Validate().Key, request.Asset),
     cancellationToken, _alpacaRestApiThrottler);