public async Task Send(IHighVolumeRuleBreach ruleBreach) { if (ruleBreach == null) { this.Logger.LogInformation("HighVolumeMessageSender send had a null rule breach. Returning"); return; } var description = this.BuildDescription(ruleBreach); await this.Send(ruleBreach, description); }
public string BuildDescription(IHighVolumeRuleBreach ruleBreach) { var description = $"High Volume rule breach detected for {ruleBreach.Security?.Name}."; var venueDailyDescription = ruleBreach.DailyBreach.Venue != null ? $" at the venue ({ruleBreach.DailyBreach.Venue?.MarketIdentifierCode}) {ruleBreach.DailyBreach.Venue?.Name}" : string.Empty; var venueWindowDescription = ruleBreach.WindowBreach.Venue != null ? $" at the venue ({ruleBreach.WindowBreach.Venue?.MarketIdentifierCode}) {ruleBreach.WindowBreach.Venue?.Name}" : string.Empty; var dailyDescription = string.Empty; var windowDescription = string.Empty; var marketCapDescription = string.Empty; if (ruleBreach.DailyBreach.HasBreach) { var dailyPercentage = Math.Round(ruleBreach.EquitiesParameters.HighVolumePercentageDaily.GetValueOrDefault(0) * 100, 2); var dailyBreachPercentage = Math.Round(ruleBreach.DailyBreach.BreachPercentage.GetValueOrDefault(0) * 100, 2); dailyDescription = $" Percentage of daily volume breach has occured. A daily volume limit of {dailyPercentage.ToString("0.##")}% was exceeded by trading {dailyBreachPercentage.ToString("0.##")}% of daily volume{venueDailyDescription}. {ruleBreach.TotalOrdersTradedInWindow.ToString("0.##")} volume was the allocated fill against a breach threshold volume of {ruleBreach.DailyBreach.BreachThresholdAmount.ToString("0.##")}."; } if (ruleBreach.WindowBreach.HasBreach) { var windowPercentage = Math.Round(ruleBreach.EquitiesParameters.HighVolumePercentageWindow.GetValueOrDefault(0) * 100, 2); var windowBreachPercentage = Math.Round(ruleBreach.WindowBreach.BreachPercentage.GetValueOrDefault(0) * 100, 2); windowDescription = $" Percentage of window volume breach has occured. A window volume limit of {windowPercentage.ToString("0.##")}% was exceeded by trading {windowBreachPercentage.ToString("0.##")}% of window volume within the window of {ruleBreach.EquitiesParameters.Windows.BackwardWindowSize.TotalMinutes} minutes{venueWindowDescription}. {ruleBreach.TotalOrdersTradedInWindow.ToString("0.##")} volume was the allocated fill against a breach threshold volume of {ruleBreach.WindowBreach.BreachThresholdAmount.ToString("0.##")}."; } if (ruleBreach.MarketCapBreach.HasBreach) { var marketCapPercentage = Math.Round( ruleBreach.EquitiesParameters.HighVolumePercentageMarketCap.GetValueOrDefault(0) * 100, 2); var marketCapBreachPercentage = Math.Round(ruleBreach.MarketCapBreach.BreachPercentage.GetValueOrDefault(0) * 100, 2); var tradedAmount = Math.Round(ruleBreach.MarketCapBreach.BreachTradedMoney.Value, 2, MidpointRounding.AwayFromZero); var currencyCode = string.IsNullOrWhiteSpace(ruleBreach.MarketCapBreach.BreachTradedMoney.Currency.Code) ? string.Empty : $"({ruleBreach.MarketCapBreach.BreachTradedMoney.Currency.Code})"; var thresholdAmount = Math.Round(ruleBreach.MarketCapBreach.BreachThresholdMoney.Value, 2, MidpointRounding.AwayFromZero); marketCapDescription = $" Percentage of market capitalisation breach has occured. A limit of {marketCapPercentage.ToString("0.##")}% was exceeded by trading {marketCapBreachPercentage.ToString("0.##")}% of market capitalisation. {currencyCode} {tradedAmount.ToString("0.##")} was traded against a breach threshold value of {currencyCode} {thresholdAmount.ToString("0.##")}."; } description = $"{description}{dailyDescription}{windowDescription}{marketCapDescription}"; return(description); }
/// <summary> /// Receive and cache rule breach in memory /// </summary> public void Send(IHighVolumeRuleBreach ruleBreach) { if (ruleBreach == null) { // ReSharper disable once InconsistentlySynchronizedField this._logger.LogInformation( "High Volume Rule Cached Message Sender received a rule breach that was null. Returning."); return; } lock (this._lock) { this._logger.LogInformation( $"High Volume Rule Cached Message Sender received rule breach for {ruleBreach.Security.Identifiers}"); var duplicates = this._messages.Where(msg => msg.Trades.PositionIsSubsetOf(ruleBreach.Trades)).ToList(); this._messages = this._messages.Except(duplicates).ToList(); this._messages.Add(ruleBreach); } }