Пример #1
0
        public void Eschaton_SetsMissingData_WhenExchangeDataMissing()
        {
            A.CallTo(() => _equitiesParameters.HighVolumePercentageDaily).Returns(0.1m);
            var highVolumeRule = BuildRule();

            highVolumeRule.OnNext(Trade());
            highVolumeRule.OnNext(Eschaton());

            A.CallTo(() => _dataRequestSubscriber.SubmitRequest()).MustHaveHappenedOnceExactly();
            A.CallTo(() => _ruleCtx.EndEvent()).MustHaveHappenedOnceExactly();
        }
Пример #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));
        }