public async Task Create_Creates_AsExpected() { var connectionStringFactory = new ConnectionStringFactory(this._configuration); var repo = new RuleBreachRepository(connectionStringFactory, this._logger); var caseMessage = new RuleBreach( 100, "rule-1", "correlation-id", true, DateTime.UtcNow, "case-title", "case-description", "xlon", DateTime.UtcNow, DateTime.UtcNow, "entspb", "RD00", "0", 0, "1", true, new int[0]); var result = await repo.Create(caseMessage); }
public async Task <long?> Create(RuleBreach message) { if (message == null) { this._logger.LogWarning("saving rule was passed a null message. Returning."); return(null); } lock (this._lock) { try { this._logger.LogInformation("saving rule breach to repository"); var dto = new RuleBreachDto(message); using (var dbConnection = this._dbConnectionFactory.BuildConn()) { var result = dbConnection.QueryFirstOrDefault <long?>(SaveRuleBreachSql, dto); this._logger.LogInformation("completed saving rule breach to repository"); return(result); } } catch (Exception e) { this._logger.LogError(e, $"error for Create"); } } return(await Task.FromResult <long?>(null)); }
public RuleBreach RuleBreachItem(IRuleBreach ruleBreach) { var oldestPosition = ruleBreach.Trades?.Get()?.Min(tr => tr.MostRecentDateEvent()); var latestPosition = ruleBreach.Trades?.Get()?.Max(tr => tr.MostRecentDateEvent()); var venue = ruleBreach.Trades?.Get()?.FirstOrDefault()?.Market?.Name; if (oldestPosition == null) { oldestPosition = latestPosition; } if (latestPosition == null) { latestPosition = oldestPosition; } var oldestPositionValue = oldestPosition ?? DateTime.UtcNow; var latestPositionValue = latestPosition ?? DateTime.UtcNow; if (ruleBreach.UniverseDateTime < oldestPositionValue) { oldestPositionValue = ruleBreach.UniverseDateTime; } if (ruleBreach.UniverseDateTime > latestPositionValue) { latestPositionValue = ruleBreach.UniverseDateTime; } var trades = ruleBreach.Trades?.Get()?.Select(io => io.ReddeerOrderId).Where(x => x.HasValue) .Select(y => y.Value).ToList(); var ruleBreachObj = new RuleBreach( null, ruleBreach.RuleParameterId, ruleBreach.CorrelationId, ruleBreach.IsBackTestRun, DateTime.UtcNow, ruleBreach.CaseTitle ?? string.Empty, ruleBreach.Description ?? string.Empty, venue, oldestPositionValue, latestPositionValue, ruleBreach.Security.Cfi, ruleBreach.Security.Identifiers.ReddeerEnrichmentId, ruleBreach.SystemOperationId, (int?)ruleBreach?.FactorValue?.OrganisationalFactors ?? 0, ruleBreach?.FactorValue?.Value ?? string.Empty, ruleBreach.RuleParameters.TunedParameters != null, trades); return(ruleBreachObj); }
public IRuleBreach Map(IHighProfitJudgementContext judgementContext) { if (judgementContext == null) { this._logger?.LogInformation($"{nameof(judgementContext)} was null in map. Returning."); return(null); } var caseTitle = $"Automated High Profit Rule Breach Detected"; var description = this.BuildDescription(judgementContext); var ruleBreach = new RuleBreach(judgementContext.RuleBreachContext, description, caseTitle); return(ruleBreach); }
/// <summary> /// The mapping from judgement to rule breach . /// </summary> /// <param name="judgementContext"> /// The judgement context. /// </param> /// <returns> /// The <see cref="IRuleBreach"/>. /// </returns> public IRuleBreach MapContextToBreach(IFixedIncomeHighVolumeJudgementContext judgementContext) { if (judgementContext == null) { this.logger?.LogInformation($"{nameof(judgementContext)} was null in map. Returning."); return(null); } var issuanceTitleSegment = judgementContext.IsIssuanceBreach ? " (%) issuance" : string.Empty; var caseTitle = $"Automated Fixed Income High Volume{issuanceTitleSegment} Rule Breach Detected"; var description = this.BuildDescription(judgementContext); var ruleBreach = new RuleBreach(judgementContext.RuleBreachContext, description, caseTitle); return(ruleBreach); }
public async Task Get_Duplicates_When_NoDuplicates_Reports_AsExpected() { var connectionStringFactory = new ConnectionStringFactory(this._configuration); var repo = new RuleBreachRepository(connectionStringFactory, this._logger); var caseMessage1 = new RuleBreach( 900, "rule-9", "correlation-id", true, DateTime.UtcNow, "case-title", "case-description", "xlon", DateTime.UtcNow, DateTime.UtcNow, "entspb", "RD00", "0", 0, "1", true, new int[0]); var result1 = await repo.Create(caseMessage1); var orderRepo = new RuleBreachOrdersRepository( connectionStringFactory, new NullLogger <RuleBreachOrdersRepository>()); var breaches1 = Enumerable.Range(0, 50).Select(i => new RuleBreachOrder(result1.ToString(), i.ToString())) .ToList(); await orderRepo.Create(breaches1); var result = await repo.HasDuplicate(result1.ToString()); Assert.IsFalse(result); }
public RuleBreachDto(RuleBreach message) { if (message == null) { return; } this.RuleId = message.RuleId; this.CorrelationId = message.CorrelationId; this.IsBackTest = message.IsBackTest; this.CreatedOn = DateTime.UtcNow; this.Title = message?.Title; this.Description = message?.Description; this.Venue = message?.Venue; this.StartOfPeriodUnderInvestigation = message.StartOfPeriodUnderInvestigation; this.EndOfPeriodUnderInvestigation = message.EndOfPeriodUnderInvestigation; this.AssetCfi = message?.AssetCfi; this.SystemOperationId = message?.SystemOperationId; this.ReddeerEnrichmentId = message?.ReddeerEnrichmentId; this.ParameterTuning = message?.ParameterTuning ?? false; this.OrganisationalFactorType = message?.OrganisationalFactor ?? 0; this.OrganisationalFactorValue = message?.OrganisationalFactorValue ?? string.Empty; }