示例#1
0
        public async Task <ConfirmationResultResponse> BoxResult(TradeKey tradeKey, string apiJwtToken, IFidectusConfiguration fidectusConfiguration)
        {
            var tradeDataObject = await GetTradeAsync(tradeKey.TradeReference, tradeKey.TradeLeg, apiJwtToken);

            if (tradeDataObject is null)
            {
                return(new ConfirmationResultResponse());
            }

            var requestTokenResponse = await CreateAuthenticationTokenAsync(apiJwtToken, fidectusConfiguration);

            var companyId         = fidectusConfiguration.CompanyId();
            var boxResultResponse = await fidectusService.GetBoxResult(companyId, tradeDataObject.ConfirmationDocumentId(), requestTokenResponse, fidectusConfiguration);

            return(new ConfirmationResultResponse
            {
                Id = boxResultResponse.Id,
                DocumentId = boxResultResponse.BoxResult?.DocumentId,
                DocumentVersion = boxResultResponse.BoxResult?.DocumentVersion,
                DocumentType = boxResultResponse.BoxResult?.DocumentType,
                State = boxResultResponse.BoxResult?.State,
                Timestamp = boxResultResponse.BoxResult?.Timestamp,
                CounterpartyDocumentId = boxResultResponse.BoxResult?.Counterparty?.DocumentId,
                CounterpartyDocumentVersion = boxResultResponse.BoxResult?.Counterparty?.DocumentVersion
            });
        }
示例#2
0
        public async Task <ConfirmationResponse> ConfirmAsync(TradeKey tradeKey, string apiJwtToken, IFidectusConfiguration fidectusConfiguration)
        {
            var tradeDataObject = await GetTradeAsync(tradeKey.TradeReference, tradeKey.TradeLeg, apiJwtToken);

            if (tradeDataObject is null || tradeDataObject.IsConfirmationWithheld())
            {
                return(new ConfirmationResponse {
                    IsSuccessStatusCode = true
                });
            }

            var tradeConfirmation = await CreateTradeConfirmationAsync(tradeDataObject, apiJwtToken, fidectusConfiguration);

            var method = string.IsNullOrWhiteSpace(tradeDataObject.ConfirmationDocumentId())
                ? "POST"
                : "PUT";

            var confirmationResponse = await SendConfirmationAsync(method, tradeConfirmation, apiJwtToken, fidectusConfiguration);

            if (confirmationResponse.IsSuccessStatusCode)
            {
                return(confirmationResponse);
            }

            if (confirmationResponse.StatusCode == 409)
            {
                logger.LogInformation("Already sent ({StatusCode}), trying a PUT...", confirmationResponse.StatusCode);

                return(await SendConfirmationAsync("PUT", tradeConfirmation, apiJwtToken, fidectusConfiguration));
            }

            throw new DataException(string.IsNullOrWhiteSpace(confirmationResponse.Message)
                ? "Failed to send confirmation"
                : $"Failed to send confirmation ({confirmationResponse.Message})");
        }
示例#3
0
        public async Task TestPostConfirmation()
        {
            var test = fidectusTestFixture.ExpectedResults.SingleOrDefault(t => t.Description == "UK Power Baseload Month March GMT");

            Assert.NotNull(test);

            var fidectusConfiguration = await fidectusTestFixture.FidectusManager.GetFidectusConfiguration("apiJwtToken");

            var tradeKey             = new TradeKey(test.Inputs.TradeReference, test.Inputs.TradeLeg);
            var confirmationResponse = await fidectusTestFixture.FidectusManager.ConfirmAsync(tradeKey, "apiJwtToken", fidectusConfiguration);

            Assert.True(confirmationResponse.IsSuccessStatusCode);
        }
示例#4
0
        public async Task <ConfirmationResponse> CancelAsync(TradeKey tradeKey, string apiJwtToken, IFidectusConfiguration fidectusConfiguration)
        {
            var tradeDataObject = await GetTradeAsync(tradeKey.TradeReference, tradeKey.TradeLeg, apiJwtToken);

            if (tradeDataObject is null || tradeDataObject.IsConfirmationWithheld())
            {
                return(new ConfirmationResponse());
            }

            if (string.IsNullOrEmpty(tradeDataObject.ConfirmationDocumentId()))
            {
                return(new ConfirmationResponse
                {
                    IsSuccessStatusCode = false,
                    Message = "Cannot cancel confirmation, confirmation has yet to be submitted"
                });
            }

            return(await DeleteConfirmationAsync(tradeDataObject, await CreateTradeConfirmationAsync(tradeDataObject, apiJwtToken, fidectusConfiguration), apiJwtToken, fidectusConfiguration));
        }
        public async Task <IActionResult> ConfirmationResult([FromHeader] string apiJwtToken, [FromBody] TradeKey tradeKey)
        {
            try
            {
                if (tradeKey is null)
                {
                    return(BadRequest());
                }

                return(Json(await fidectusManager.BoxResult(tradeKey, apiJwtToken, await fidectusManager.GetFidectusConfiguration(apiJwtToken))));
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "{Message}", ex.Message);
                return(BadRequest(new ApiResponseWrapper <ConfirmationResultResponse>
                {
                    Message = ex.Message,
                    Status = ApiConstants.FailedResult,
                    StatusCode = (int?)HttpStatusCode.BadRequest,
                    Data = new ConfirmationResultResponse
                    {
                        Message = ex.Message
                    }
                }));
            }
        }