/// <summary> /// Initializes a new instance of the <see cref="HighVolumeRule"/> class. /// </summary> /// <param name="equitiesParameters"> /// The equities parameters. /// </param> /// <param name="operationContext"> /// The operation context. /// </param> /// <param name="alertStream"> /// The alert stream. /// </param> /// <param name="orderFilter"> /// The order filter. /// </param> /// <param name="equityMarketCacheFactory"> /// The market cache factory. /// </param> /// <param name="fixedIncomeMarketCacheFactory"> /// The market cache factory. /// </param> /// <param name="tradingHoursService"> /// The trading hours service. /// </param> /// <param name="dataRequestSubscriber"> /// The data request subscriber. /// </param> /// <param name="currencyConverterService"> /// The currency converter service. /// </param> /// <param name="runMode"> /// The run mode. /// </param> /// <param name="logger"> /// The logger. /// </param> /// <param name="tradingHistoryLogger"> /// The trading history logger. /// </param> public HighVolumeRule( IHighVolumeRuleEquitiesParameters equitiesParameters, ISystemProcessOperationRunRuleContext operationContext, IUniverseAlertStream alertStream, IUniverseOrderFilter orderFilter, IUniverseEquityMarketCacheFactory equityMarketCacheFactory, IUniverseFixedIncomeMarketCacheFactory fixedIncomeMarketCacheFactory, IMarketTradingHoursService tradingHoursService, IUniverseDataRequestsSubscriber dataRequestSubscriber, ICurrencyConverterService currencyConverterService, RuleRunMode runMode, ILogger <IHighVolumeRule> logger, ILogger <TradingHistoryStack> tradingHistoryLogger) : base( equitiesParameters?.Windows.BackwardWindowSize ?? TimeSpan.FromDays(1), equitiesParameters?.Windows.BackwardWindowSize ?? TimeSpan.FromDays(1), equitiesParameters?.Windows?.FutureWindowSize ?? TimeSpan.Zero, Domain.Surveillance.Scheduling.Rules.HighVolume, EquityRuleHighVolumeFactory.Version, "High Volume Rule", operationContext, equityMarketCacheFactory, fixedIncomeMarketCacheFactory, runMode, logger, tradingHistoryLogger) { this.EquitiesParameters = equitiesParameters ?? throw new ArgumentNullException(nameof(equitiesParameters)); this.AlertStream = alertStream ?? throw new ArgumentNullException(nameof(alertStream)); this.OrderFilter = orderFilter ?? throw new ArgumentNullException(nameof(orderFilter)); this.TradingHoursService = tradingHoursService ?? throw new ArgumentNullException(nameof(tradingHoursService)); this.DataRequestSubscriber = dataRequestSubscriber ?? throw new ArgumentNullException(nameof(dataRequestSubscriber)); this.CurrencyConverterService = currencyConverterService ?? throw new ArgumentNullException(nameof(currencyConverterService)); this.Logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
public void Setup() { _alertStream = A.Fake <IUniverseAlertStream>(); _equitiesParameters = A.Fake <IHighVolumeRuleEquitiesParameters>(); _ruleCtx = A.Fake <ISystemProcessOperationRunRuleContext>(); _opCtx = A.Fake <ISystemProcessOperationContext>(); _dataRequestRepository = A.Fake <IRuleRunDataRequestRepository>(); _stubDataRequestRepository = A.Fake <IStubRuleRunDataRequestRepository>(); _equityFactoryCache = A.Fake <ILogger <UniverseEquityMarketCacheFactory> >(); _equityFactory = new UniverseEquityMarketCacheFactory(_stubDataRequestRepository, _dataRequestRepository, _equityFactoryCache); _fixedIncomeFactoryCache = A.Fake <ILogger <UniverseFixedIncomeMarketCacheFactory> >(); _fixedIncomeFactory = new UniverseFixedIncomeMarketCacheFactory(_stubDataRequestRepository, _dataRequestRepository, _fixedIncomeFactoryCache); _tradingHoursService = A.Fake <IMarketTradingHoursService>(); _dataRequestSubscriber = A.Fake <IUniverseDataRequestsSubscriber>(); this.currencyConverterService = A.Fake <ICurrencyConverterService>(); _logger = A.Fake <ILogger <IHighVolumeRule> >(); _tradingLogger = A.Fake <ILogger <TradingHistoryStack> >(); _orderFilter = A.Fake <IUniverseOrderFilter>(); A.CallTo(() => _orderFilter.Filter(A <IUniverseEvent> .Ignored)).ReturnsLazily(i => (IUniverseEvent)i.Arguments[0]); A.CallTo(() => _ruleCtx.EndEvent()).Returns(_opCtx); }
/// <summary> /// The decorate with filter. /// </summary> /// <param name="operationContext"> /// The operation context. /// </param> /// <param name="parameter"> /// The parameter. /// </param> /// <param name="highVolume"> /// The high volume. /// </param> /// <param name="dataRequestSubscriber"> /// The data request subscriber. /// </param> /// <param name="processOperationRunRuleContext"> /// The process operation run rule context. /// </param> /// <param name="ruleRunMode"> /// The rule run mode. /// </param> /// <returns> /// The <see cref="IUniverseRule"/>. /// </returns> private IUniverseRule DecorateWithFilter( ISystemProcessOperationContext operationContext, IHighVolumeRuleEquitiesParameters parameter, IUniverseRule highVolume, IUniverseDataRequestsSubscriber dataRequestSubscriber, ISystemProcessOperationRunRuleContext processOperationRunRuleContext, RuleRunMode ruleRunMode) { if (parameter.HasInternalFilters() || parameter.HasReferenceDataFilters() || parameter.HasMarketCapFilters() || parameter.HasVenueVolumeFilters()) { this.logger.LogInformation($"parameters had filters. Inserting filtered universe in {operationContext.Id} OpCtx"); var filteredUniverse = this.universeFilterFactory.Build( highVolume, parameter.Accounts, parameter.Traders, parameter.Markets, parameter.Funds, parameter.Strategies, parameter.Sectors, parameter.Industries, parameter.Regions, parameter.Countries, parameter.MarketCapFilter, ruleRunMode, "High Volume Equity", dataRequestSubscriber, processOperationRunRuleContext); var decoratedFilter = filteredUniverse; if (parameter.HasVenueVolumeFilters()) { decoratedFilter = this.decoratorFilterFactory.Build( parameter.Windows, filteredUniverse, parameter.VenueVolumeFilter, processOperationRunRuleContext, dataRequestSubscriber, this.HighVolumeDataSource(parameter), ruleRunMode); } decoratedFilter.Subscribe(highVolume); return(decoratedFilter); } return(highVolume); }
public void Setup() { _orderFilterService = A.Fake <IUniverseEquityOrderFilterService>(); _equityFactory = A.Fake <IUniverseEquityMarketCacheFactory>(); _fixedIncomeFactory = A.Fake <IUniverseFixedIncomeMarketCacheFactory>(); _tradingHoursService = A.Fake <IMarketTradingHoursService>(); this.currencyConverterService = A.Fake <ICurrencyConverterService>(); _logger = A.Fake <ILogger <IHighVolumeRule> >(); _tradingHistoryLogger = A.Fake <ILogger <TradingHistoryStack> >(); _equitiesParameters = A.Fake <IHighVolumeRuleEquitiesParameters>(); _opCtx = A.Fake <ISystemProcessOperationRunRuleContext>(); _alertStream = A.Fake <IUniverseAlertStream>(); _dataRequestSubscriber = A.Fake <IUniverseDataRequestsSubscriber>(); }
/// <summary> /// The subscribe to parameters. /// </summary> /// <param name="execution"> /// The execution. /// </param> /// <param name="operationContext"> /// The operation context. /// </param> /// <param name="alertStream"> /// The alert stream. /// </param> /// <param name="dataRequestSubscriber"> /// The data request subscriber. /// </param> /// <param name="parameter"> /// The parameter. /// </param> /// <returns> /// The <see cref="IUniverseRule"/>. /// </returns> private IUniverseRule SubscribeToParameters( ScheduledExecution execution, ISystemProcessOperationContext operationContext, IUniverseAlertStream alertStream, IUniverseDataRequestsSubscriber dataRequestSubscriber, IHighVolumeRuleEquitiesParameters parameter) { var ruleCtx = operationContext.CreateAndStartRuleRunContext( Rules.HighVolume.GetDescription(), EquityRuleHighVolumeFactory.Version, parameter.Id, (int)Rules.HighVolume, execution.IsBackTest, execution.TimeSeriesInitiation.DateTime, execution.TimeSeriesTermination.DateTime, execution.CorrelationId, execution.IsForceRerun); var runMode = execution.IsForceRerun ? RuleRunMode.ForceRun : RuleRunMode.ValidationRun; var highVolume = this.equityRuleHighVolumeFactory.Build( parameter, ruleCtx, alertStream, dataRequestSubscriber, runMode); var highVolumeOrgFactors = this.brokerServiceFactory.Build( highVolume, parameter.Factors, parameter.AggregateNonFactorableIntoOwnCategory); var decoratedHighVolumeRule = this.DecorateWithFilter( operationContext, parameter, highVolumeOrgFactors, dataRequestSubscriber, ruleCtx, runMode); return(decoratedHighVolumeRule); }
public IHighVolumeRule Build( IHighVolumeRuleEquitiesParameters equitiesParameters, ISystemProcessOperationRunRuleContext operationContext, IUniverseAlertStream alertStream, IUniverseDataRequestsSubscriber dataRequestSubscriber, RuleRunMode runMode) { return(new HighVolumeRule( equitiesParameters, operationContext, alertStream, this.orderFilterService, this.equityFactory, this.fixedIncomeFactory, this.tradingHoursService, dataRequestSubscriber, this.currencyConverterService, runMode, this.logger, this.tradingHistoryLogger)); }
/// <summary> /// The high volume data source. /// </summary> /// <param name="parameters"> /// The parameters. /// </param> /// <returns> /// The <see cref="DataSource"/>. /// </returns> private DataSource HighVolumeDataSource(IHighVolumeRuleEquitiesParameters parameters) { if (parameters == null) { return(DataSource.AnyInterday); } if (parameters.HighVolumePercentageWindow != null) { return(DataSource.AnyIntraday); } if (parameters.HighVolumePercentageDaily != null) { return(DataSource.AnyInterday); } if (parameters.HighVolumePercentageMarketCap != null) { return(DataSource.AnyInterday); } return(this.DataSourceForWindow(parameters.Windows)); }
public HighVolumeRuleBreach( IFactorValue factorValue, ISystemProcessOperationContext operationContext, string correlationId, TimeSpan window, ITradePosition trades, FinancialInstrument security, IHighVolumeRuleEquitiesParameters equitiesParameters, BreachDetails dailyBreach, BreachDetails windowBreach, BreachDetails marketCapBreach, decimal totalOrdersTradedInWindow, string description, string caseTitle, DateTime universeDateTime) { this.FactorValue = factorValue; this.Window = window; this.Trades = trades; this.Security = security; this.EquitiesParameters = equitiesParameters; this.DailyBreach = dailyBreach; this.WindowBreach = windowBreach; this.MarketCapBreach = marketCapBreach; this.TotalOrdersTradedInWindow = totalOrdersTradedInWindow; this.RuleParameterId = equitiesParameters?.Id ?? string.Empty; this.SystemOperationId = operationContext.Id.ToString(); this.CorrelationId = correlationId; this.RuleParameters = equitiesParameters; this.Description = description ?? string.Empty; this.CaseTitle = caseTitle ?? string.Empty; this.UniverseDateTime = universeDateTime; }