public void Filter_WhenUniverseEventAndTradingHoursIsNotValid_MustBeFiltered() { var fundOne = ((Order)null).Random(); var eventOne = new UniverseEvent(UniverseStateEvent.Order, DateTime.UtcNow, fundOne); A.CallTo(() => _tradingHoursService.GetTradingHoursForMic(fundOne.Market.MarketIdentifierCode)) .Returns(new TradingHours() { IsValid = false }); var marketCapRangeRuleFilter = new DecimalRangeRuleFilter { Type = RuleFilterType.Include }; var highMarketCapFilter = new HighMarketCapFilter( _universeMarketCacheFactory, Engine.Rules.Rules.RuleRunMode.ValidationRun, marketCapRangeRuleFilter, _tradingHoursService, _operationRunRuleContext, _universeDataRequestsSubscriber, this.currencyConverterService, "test", _logger); var result = highMarketCapFilter.Filter(eventOne); Assert.IsTrue(result); }
protected virtual MarketDataRequest MarketDataRequest( string mic, InstrumentIdentifiers identifiers, DateTime universeDateTime, ISystemProcessOperationRunRuleContext ctx, DataSource dataSource) { var tradingHours = TradingHoursService.GetTradingHoursForMic(mic); if (!tradingHours.IsValid) { Logger.LogError($"RevenueCurrencyConvertingCalculator was not able to get meaningful trading hours for the mic {mic}. Unable to proceed with currency conversions."); return(null); } return(new MarketDataRequest( mic, string.Empty, identifiers, tradingHours.OpeningInUtcForDay(universeDateTime), tradingHours.MinimumOfCloseInUtcForDayOrUniverse(universeDateTime), ctx?.Id(), dataSource)); }
public bool Filter(IUniverseEvent universeEvent) { if (universeEvent == null) { return(false); } if (universeEvent.StateChange == UniverseStateEvent.EquityInterDayTick) { EquityInterDay(universeEvent); } if (universeEvent.StateChange == UniverseStateEvent.Eschaton && _requestData && _ruleRunMode == RuleRunMode.ValidationRun) { _universeDataRequestsSubscriber.SubmitRequest(); } if (universeEvent.StateChange != UniverseStateEvent.Order && universeEvent.StateChange != UniverseStateEvent.OrderPlaced) { return(false); } if (!(universeEvent.UnderlyingEvent is Order mostRecentTrade)) { return(false); } if (_marketCapFilter?.Type != RuleFilterType.Include) { return(false); } var tradingHours = _tradingHoursService.GetTradingHoursForMic(mostRecentTrade.Market?.MarketIdentifierCode); if (!tradingHours.IsValid) { _logger.LogError($"Request for trading hours was invalid. MIC - {mostRecentTrade.Market?.MarketIdentifierCode}"); return(true); } var universeDateTime = universeEvent.EventTime; var marketDataRequest = new MarketDataRequest( mostRecentTrade.Market?.MarketIdentifierCode, mostRecentTrade.Instrument.Cfi, mostRecentTrade.Instrument.Identifiers, tradingHours.OpeningInUtcForDay(universeDateTime), tradingHours.MinimumOfCloseInUtcForDayOrUniverse(universeDateTime), _operationRunRuleContext?.Id(), DataSource.AnyInterday); var securityResult = _universeEquityInterdayCache.Get(marketDataRequest); if (securityResult.HadMissingData && _ruleRunMode == RuleRunMode.ValidationRun) { _requestData = true; } if (securityResult.HadMissingData) { _logger.LogInformation($"Missing data for {marketDataRequest}."); return(true); } var security = securityResult.Response; var marketCap = security.DailySummaryTimeBar.MarketCap; if (marketCap == null) { this._logger.LogInformation($"Missing data for market cap from daily summary time bar {marketDataRequest}."); return(true); } var marketCapInUsd = this.currencyConverterService.Convert( new[] { marketCap.Value }, new Currency("USD"), universeDateTime, this._operationRunRuleContext).Result; if (marketCapInUsd == null) { this._logger.LogInformation($"Missing data for market cap currency conversion into USD at {universeEvent} from daily summary time bar {marketDataRequest}."); return(true); } var min = this._marketCapFilter.Min ?? marketCap.Value.Value; var max = this._marketCapFilter.Max ?? marketCap.Value.Value; return(!(marketCap.Value.Value >= min && marketCap.Value.Value <= max)); }