/// <summary> /// The retrieve market traded volume. /// </summary> /// <param name="mostRecentTrade"> /// The most recent trade. /// </param> /// <param name="tradingHours"> /// The trading hours. /// </param> /// <param name="activeHistory"> /// The active history. /// </param> /// <returns> /// The <see cref="long?"/>. /// </returns> private long?RetrieveMarketTradedVolume(Order mostRecentTrade, ITradingHours tradingHours, Stack <Order> activeHistory) { var closeTime = this.source == DataSource.AnyIntraday ? UniverseDateTime : tradingHours.ClosingInUtcForDay(UniverseDateTime); var marketDataRequest = new MarketDataRequest( mostRecentTrade.Market?.MarketIdentifierCode, mostRecentTrade.Instrument.Cfi, mostRecentTrade.Instrument.Identifiers, tradingHours.OpeningInUtcForDay(UniverseDateTime.Subtract(this.TradeBackwardWindowSize)), closeTime, RuleCtx.Id(), this.source); var hadMissingData = false; long?marketTradedVolume = null; switch (this.source) { case DataSource.AnyInterday: var securityResultInterday = UniverseEquityInterdayCache.GetMarkets(marketDataRequest); hadMissingData = securityResultInterday.HadMissingData; if (!hadMissingData) { marketTradedVolume = this.InterdayMarketTradedVolume(securityResultInterday); } break; case DataSource.AnyIntraday: var securityResultIntraday = UniverseEquityIntradayCache.GetMarkets(marketDataRequest); hadMissingData = securityResultIntraday.HadMissingData; if (!hadMissingData) { marketTradedVolume = this.IntradayMarketTradedVolume(securityResultIntraday); } break; } if (hadMissingData && RunMode == RuleRunMode.ForceRun) { this.UpdatePassedFilterWithOrders(activeHistory); return(null); } if (hadMissingData && RunMode == RuleRunMode.ValidationRun) { this.logger.LogInformation($"market traded volume was not calculable for {mostRecentTrade.Instrument.Identifiers} due to missing data"); this.hadMissingData = true; return(null); } return(marketTradedVolume); }
/// <summary> /// The set trading hour range. /// </summary> /// <param name="tradingHours"> /// The trading hours. /// </param> /// <param name="order"> /// The order. /// </param> /// <returns> /// The <see cref="DateRange"/>. /// </returns> private IReadOnlyCollection <DateRange> SetTradingHourRange(ITradingHours tradingHours, Order order) { var tradingHourFrom = tradingHours.OpeningInUtcForDay(this.UniverseDateTime.Subtract(this.TradeBackwardWindowSize)); var tradingHourTo = tradingHours.ClosingInUtcForDay(this.UniverseDateTime); var tradingDates = this.tradingHoursService.GetTradingDaysWithinRangeAdjustedToTime( tradingHourFrom, tradingHourTo, order.Market?.MarketIdentifierCode); return(tradingDates); }
/// <summary> /// The construct market data request window analysis. /// </summary> /// <param name="order"> /// The order. /// </param> /// <param name="tradingHours"> /// The trading hours. /// </param> /// <returns> /// The <see cref="MarketDataRequest"/>. /// </returns> private MarketDataRequest ConstructMarketDataRequestWindowAnalysis(Order order, ITradingHours tradingHours) { var openingHours = tradingHours.OpeningInUtcForDay(this.UniverseDateTime.Subtract(this.TradeBackwardWindowSize)); var closingHours = tradingHours.ClosingInUtcForDay(this.UniverseDateTime); return(new MarketDataRequest( order.Market?.MarketIdentifierCode, order.Instrument.Cfi, order.Instrument.Identifiers, openingHours, closingHours, this.RuleCtx?.Id(), DataSource.AnyIntraday)); }