Ejemplo n.º 1
0
        public FormulaCalculateResponse Calculate(CalculateFormulaRequest calculateFormulaRequest)
        {
            try
            {
                var formula = StringHelper.Base64ToString(calculateFormulaRequest.Formula);

                var formulaDataWrapper = new FormulaDataWrapper
                {
                    Data = calculateFormulaRequest.Data
                };

                var json = TradeCubeJsonSerializer.Serialize(formulaDataWrapper);
                var formulaEvaluatorRequest = new FormulaEvaluatorRequest(json, formula, "main")
                {
                    TimeoutInterval = calculateFormulaRequest.TimeoutSeconds
                };

                return(FormulaEvaluator.Evaluate(formulaEvaluatorRequest));
            }
            catch (Exception ex)
            {
                return(new FormulaCalculateResponse
                {
                    IsSuccess = false,
                    Message = ex.Message
                });
            }
        }
        public static FormulaCalculateResponse Evaluate(FormulaEvaluatorRequest formulaEvaluatorRequest)
        {
            try
            {
                var engine = new Engine(options =>
                {
                    options.TimeoutInterval(TimeSpan.FromSeconds(formulaEvaluatorRequest.TimeoutInterval));
                });

                var data   = new JsonParser(engine).Parse(formulaEvaluatorRequest.Data);
                var result = engine
                             .Execute(formulaEvaluatorRequest.JavascriptFormula)
                             .GetValue(formulaEvaluatorRequest.MainFunction);

                var jsValue   = result.Invoke(data);
                var obj       = jsValue.ToObject();
                var serialize = TradeCubeJsonSerializer.Serialize(obj);

                return(new FormulaCalculateResponse
                {
                    IsSuccess = true,
                    Value = serialize
                });
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
                return(new FormulaCalculateResponse
                {
                    IsSuccess = false,
                    Message = ex.Message
                });
            }
        }
Ejemplo n.º 3
0
        public async Task <PhysicalTrade> CreatePhysicalTradeAsync(TradeDataObject tradeDataObject, string apiJwtToken)
        {
            var mappingHelper    = new MappingHelper(await equiasMappingService.GetMappingsAsync(apiJwtToken));
            var tradeSummary     = (await tradeSummaryService.TradeSummaryAsync(tradeDataObject.TradeReference, tradeDataObject.TradeLeg, apiJwtToken))?.Data?.FirstOrDefault();
            var cashflows        = (await cashflowService.CashflowAsync(tradeDataObject.TradeReference, tradeDataObject.TradeLeg, apiJwtToken))?.Data;
            var profileResponses = (await profileService.ProfileAsync(tradeDataObject.TradeReference, tradeDataObject.TradeLeg, apiJwtToken, ProfileTradeConstants.ProfileFormatSparse))?.Data;

            logger.LogTrace("Trade Summary: {TradeSummary}\r\n", TradeCubeJsonSerializer.Serialize(tradeSummary));
            logger.LogTrace("Trade Cashflows: {TradeCashflows}\r\n", TradeCubeJsonSerializer.Serialize(cashflows));
            logger.LogTrace("Trade Profile: {TradeProfile}\r\n", TradeCubeJsonSerializer.Serialize(profileResponses));

            return(await equiasMappingService.MapTrade(tradeDataObject, tradeSummary, cashflows, profileResponses, mappingHelper, apiJwtToken));
        }
Ejemplo n.º 4
0
        public async Task <EboTradeResponse> ModifyPhysicalTrade(PhysicalTrade physicalTrade, RequestTokenResponse requestTokenResponse, IEquiasConfiguration equiasConfiguration)
        {
            try
            {
                logger.LogInformation("Physical Trade: {PhysicalTrade}", TradeCubeJsonSerializer.Serialize(physicalTrade));

                var httpClient = httpClientFactory.CreateClient();

                httpClient.BaseAddress = new Uri(equiasConfiguration.ApiDomain);
                httpClient.DefaultRequestHeaders.Add("token", requestTokenResponse?.Token);

                return(await PostAsync <PhysicalTrade, EboTradeResponse>(httpClient, equiasConfiguration.ModifyPhysicalTradeUri, physicalTrade, false));
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "{Message}", ex.Message);
                return(new EboTradeResponse
                {
                    IsSuccessStatusCode = false,
                    Message = ex.Message
                });
            }
        }
Ejemplo n.º 5
0
 public static void JsonLogDebug <T, TV>(this ILogger <T> logger, TV body) =>
 logger.LogDebug(TradeCubeJsonSerializer.Serialize(body));
Ejemplo n.º 6
0
 public static void JsonLogDebug <T, TV>(this ILogger <T> logger, string message, TV body) =>
 logger.LogDebug(
     $"{message}: {TradeCubeJsonSerializer.Serialize(body)}");
Ejemplo n.º 7
0
        public async Task <EboTradeResponse> CreatePhysicalTradeAsync(string tradeReference, int tradeLeg, string apiJwtToken)
        {
            async Task <EboTradeResponse> Withhold(string jwt, TradeDataObject tradeDataObject)
            {
                tradeDataObject.External.Equias.EboSubmissionStatus = EquiasConstants.StatusWithheld;

                var saveTradeWithheld = await SaveTradeAsync(tradeDataObject, jwt);

                logger.LogInformation("Withheld Trade updated (EboSubmissionStatus={StatusWithheld}), result: {Status}",
                                      EquiasConstants.StatusWithheld,
                                      saveTradeWithheld.Status);

                return(new EboTradeResponse());
            }

            async Task <EboTradeResponse> NewTrade(PhysicalTrade physicalTrade, RequestTokenResponse requestTokenResponse, TradeDataObject updateTradePreSubmission)
            {
                var eboAddPhysicalTradeResponse = await AddPhysicalTradeAsync(physicalTrade, requestTokenResponse, apiJwtToken);

                if (!eboAddPhysicalTradeResponse.IsSuccessStatusCode)
                {
                    throw new DataException($"Add physical Trade failed result: {eboAddPhysicalTradeResponse.Message}");
                }

                logger.LogInformation("AddPhysicalTrade success response, TradeId: {TradeId}, TradeVersion: {TradeVersion}",
                                      eboAddPhysicalTradeResponse.TradeId,
                                      eboAddPhysicalTradeResponse.TradeVersion);

                var addTradePostSubmission = SetTradePostSubmission(eboAddPhysicalTradeResponse, updateTradePreSubmission);
                var savePostSubmissionAdd  = await SaveTradeAsync(addTradePostSubmission, apiJwtToken);

                logger.LogInformation("Add physical Trade updated (EboSubmissionStatus={EboSubmissionStatus}), result: {Status}",
                                      addTradePostSubmission.External.Equias.EboSubmissionStatus,
                                      savePostSubmissionAdd.Status);

                return(eboAddPhysicalTradeResponse);
            }

            async Task <EboTradeResponse> ExistingTrade(PhysicalTrade physicalTrade, TradeDataObject tradeDataObject, RequestTokenResponse requestTokenResponse)
            {
                var eboModifyPhysicalTradeResponse = await ModifyPhysicalTradeAsync(physicalTrade, requestTokenResponse, apiJwtToken);

                if (!eboModifyPhysicalTradeResponse.IsSuccessStatusCode)
                {
                    throw new DataException($"Modify physical Trade failed result: {eboModifyPhysicalTradeResponse.Message}");
                }

                logger.LogInformation("ModifyPhysicalTrade success response, TradeId: {TradeId}, TradeVersion: {TradeVersion}",
                                      eboModifyPhysicalTradeResponse.TradeId,
                                      eboModifyPhysicalTradeResponse.TradeVersion);

                var modifyTradePostSubmission = SetTradePostSubmission(eboModifyPhysicalTradeResponse, tradeDataObject);
                var savePostSubmissionModify  = await SaveTradeAsync(modifyTradePostSubmission, apiJwtToken);

                logger.LogInformation("Modify physical Trade updated (EboSubmissionStatus={EboSubmissionStatus}), result: {Status}",
                                      modifyTradePostSubmission.External.Equias.EboSubmissionStatus,
                                      savePostSubmissionModify.Status);

                return(eboModifyPhysicalTradeResponse);
            }

            try
            {
                var requestTokenResponse = await CreateAuthenticationTokenAsync(apiJwtToken);

                var tradeDataObject = await GetTradeAsync(tradeReference, tradeLeg, apiJwtToken);

                if (tradeDataObject.WithholdEquiasSubmission())
                {
                    return(await Withhold(apiJwtToken, tradeDataObject));
                }

                var tradeIds = new List <TradeKey> {
                    new() { TradeReference = tradeReference, TradeLeg = tradeLeg }
                };
                var eboGetTradeStatusResponse = await TradeStatusAsync(tradeIds, apiJwtToken);

                if (string.IsNullOrEmpty(tradeDataObject.EboActionType()))
                {
                    if (tradeDataObject.EboStatus() == EquiasConstants.StatusMatched || eboGetTradeStatusResponse.Status == EquiasConstants.StatusMatched)
                    {
                        return(new EboTradeResponse
                        {
                            Status = ApiConstants.FailedWithWarningResult,
                            Message = "Confirmation already matched. To resubmit, amend the Action Type"
                        });
                    }
                }

                var updateTradePreSubmission = SetTradePreSubmission(eboGetTradeStatusResponse, tradeDataObject);
                var savePreSubmission        = await SaveTradeAsync(updateTradePreSubmission, apiJwtToken);

                logger.LogInformation("Pre-submission Trade updated (EboSubmissionStatus={EboSubmissionStatus}), result: {Status}",
                                      updateTradePreSubmission.External.Equias.EboSubmissionStatus,
                                      savePreSubmission.Status);

                var physicalTrade = await CreatePhysicalTradeAsync(updateTradePreSubmission, apiJwtToken);

                logger.LogDebug("Physical Trade: {PhysicalTrade)}", TradeCubeJsonSerializer.Serialize(physicalTrade));

                return(eboGetTradeStatusResponse.States.SingleOrDefault()?.TradeVersion is null
                    ? await NewTrade(physicalTrade, requestTokenResponse, updateTradePreSubmission)
                    : await ExistingTrade(physicalTrade, tradeDataObject, requestTokenResponse));
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "{Message}", ex.Message);
                throw;
            }
        }
Ejemplo n.º 8
0
        public async Task <EboGetTradeStatusResponse> TradeStatusAsync(IEnumerable <TradeKey> tradeKeys, string apiJwtToken)
        {
            var enumerable           = tradeKeys.ToList();
            var tradeIds             = enumerable.Select(t => EquiasService.MapTradeId(t.TradeReference, t.TradeLeg)).ToList();
            var equiasConfiguration  = new EquiasConfiguration(await GetEquiasDomainAsync(apiJwtToken));
            var requestTokenResponse = await CreateAuthenticationTokenAsync(apiJwtToken);

            logger.LogInformation("Attempting to get trade status for trades {TradeIds}", TradeCubeJsonSerializer.Serialize(tradeIds));

            return(tradeIds.Any()
                ? await equiasService.EboGetTradeStatus(tradeIds, requestTokenResponse, equiasConfiguration)
                : new EboGetTradeStatusResponse());
        }