Exemplo n.º 1
0
        public void BuyInvestmentOnSecondaryMarketOk()
        {
            var request = new SecondaryMarketInvestment()
            {
                Amount = 21.98M
            };

            _zonkyApi.BuySecondaryMarketInvestmentAsync(1, request, _tokenProvider.GetToken(), CancellationToken.None).GetAwaiter().GetResult();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Buy secondary market investment offer
        /// </summary>
        /// <param name="offerId">Id of investment offer</param>
        /// <param name="secondaryMarketInvestment">Secondary market investment</param>
        /// <param name="authorizationToken"></param>
        /// <param name="ct"></param>
        /// <returns></returns>
        public async Task BuySecondaryMarketInvestmentAsync(int offerId, SecondaryMarketInvestment secondaryMarketInvestment, AuthorizationToken authorizationToken, CancellationToken ct = default)
        {
            CheckAuthorizationToken(authorizationToken);

            using (var request = PrepareAuthorizedRequest($"/smp/investments/{offerId}/shares", HttpMethod.Post, authorizationToken).AddJsonContent(secondaryMarketInvestment, Settings))
                using (var response = await _httpClient.SendAsync(request, HttpCompletionOption.ResponseContentRead, ct).ConfigureAwait(false))
                {
                    await _resolverFactory.Create(Settings, true)
                    .ConfigureStatusResponce(HttpStatusCode.OK, (message) => { })
                    .ConfigureStatusResponce(HttpStatusCode.NoContent, (message) => { })
                    .ConfigureStatusResponce <SecondaryMarketBuyError>(HttpStatusCode.BadRequest, (error, message) => throw new BuySecondaryMarketInvestmentException(offerId, secondaryMarketInvestment, error))
                    .ConfigureStatusResponce(HttpStatusCode.NotFound, (message) => throw new NotFoundSecondaryMarketInvestmentException(offerId))
                    .ConfigureDefaultResponce((message) => throw new ServerErrorException(message))
                    .ExtractDataAsync(response);
                }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Buy secondary market investment offer
        /// </summary>
        /// <param name="offerId">Id of investment offer</param>
        /// <param name="secondaryMarketInvestment">Secondary market investment</param>
        /// <param name="ct"></param>
        /// <returns></returns>
        public async Task BuySecondaryMarketInvestmentAsync(int offerId, SecondaryMarketInvestment secondaryMarketInvestment, CancellationToken ct = default)
        {
            CheckTradingPrerequisites();

            await HandleAuthorizedRequestAsync(() => ZonkyApi.BuySecondaryMarketInvestmentAsync(offerId, secondaryMarketInvestment, AuthorizationToken, ct), ct).ConfigureAwait(false);
        }
Exemplo n.º 4
0
 public BuySecondaryMarketInvestmentException(int investmentId, SecondaryMarketInvestment secondaryMarketInvestment, SecondaryMarketBuyError secondaryMarketBuyError) : base($"Buy secondary market investment id {investmentId} request {secondaryMarketInvestment.ToString()} failed with {secondaryMarketBuyError.ToString()}")
 {
 }