コード例 #1
0
        public void Filter_WhenUniverseEventAndHadMissingDataInUniverseEquityInterdayCache_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 = true
            });

            A.CallTo(() => _universeEquityInterDayCache.Get(
                         A <MarketDataRequest> .That.Matches(
                             m => m.MarketIdentifierCode == fundOne.Market.MarketIdentifierCode &&
                             m.Cfi == fundOne.Instrument.Cfi
                             )))
            .Returns(MarketDataResponse <EquityInstrumentInterDayTimeBar> .MissingData());

            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);
        }
コード例 #2
0
        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));
        }