/// <summary> /// Initializes a new instance of the <see cref="LayeringRule"/> class. /// </summary> /// <param name="equitiesParameters"> /// The equities parameters. /// </param> /// <param name="alertStream"> /// The alert stream. /// </param> /// <param name="orderFilter"> /// The order filter. /// </param> /// <param name="logger"> /// The logger. /// </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="operationContext"> /// The op context. /// </param> /// <param name="runMode"> /// The run mode. /// </param> /// <param name="tradingHistoryLogger"> /// The trading history logger. /// </param> public LayeringRule( ILayeringRuleEquitiesParameters equitiesParameters, IUniverseAlertStream alertStream, IUniverseOrderFilter orderFilter, ILogger logger, IUniverseEquityMarketCacheFactory equityMarketCacheFactory, IUniverseFixedIncomeMarketCacheFactory fixedIncomeMarketCacheFactory, IMarketTradingHoursService tradingHoursService, ISystemProcessOperationRunRuleContext operationContext, RuleRunMode runMode, ILogger <TradingHistoryStack> tradingHistoryLogger) : base( equitiesParameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromMinutes(20), equitiesParameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromMinutes(20), equitiesParameters?.Windows?.FutureWindowSize ?? TimeSpan.Zero, Domain.Surveillance.Scheduling.Rules.Layering, EquityRuleLayeringFactory.Version, "Layering Rule", operationContext, equityMarketCacheFactory, fixedIncomeMarketCacheFactory, runMode, logger, tradingHistoryLogger) { this.equitiesParameters = equitiesParameters ?? throw new ArgumentNullException(nameof(equitiesParameters)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); this.tradingHoursService = tradingHoursService ?? throw new ArgumentNullException(nameof(tradingHoursService)); this.ruleContext = operationContext ?? throw new ArgumentNullException(nameof(operationContext)); this.alertStream = alertStream ?? throw new ArgumentNullException(nameof(alertStream)); this.orderFilter = orderFilter ?? throw new ArgumentNullException(nameof(orderFilter)); }
/// <summary> /// The build subscriptions. /// </summary> /// <param name="execution"> /// The execution. /// </param> /// <param name="player"> /// The player. /// </param> /// <param name="alertStream"> /// The alert stream. /// </param> /// <param name="dataRequestSubscriber"> /// The data request subscriber. /// </param> /// <param name="judgementService"> /// The judgement service. /// </param> /// <param name="operationContext"> /// The operation context. /// </param> /// <param name="ruleParameters"> /// The rule parameters. /// </param> /// <param name="args"> /// The args. /// </param> /// <returns> /// The <see cref="IUniverseRule"/>. /// </returns> private IReadOnlyCollection <IUniverseRule> BuildSubscriptions( ScheduledExecution execution, IUniversePlayer player, IUniverseAlertStream alertStream, IUniverseDataRequestsSubscriber dataRequestSubscriber, IJudgementService judgementService, ISystemProcessOperationContext operationContext, RuleParameterDto ruleParameters, params Func <ScheduledExecution, RuleParameterDto, ISystemProcessOperationContext, IUniverseDataRequestsSubscriber, IJudgementService, IUniverseAlertStream, IReadOnlyCollection <IUniverseRule> >[] args) { var universeRules = new List <IUniverseRule>(); foreach (var func in args) { var result = func.Invoke( execution, ruleParameters, operationContext, dataRequestSubscriber, judgementService, alertStream); universeRules.AddRange(result); } return(universeRules); }
/// <summary> /// The subscribe to universe. /// </summary> /// <param name="execution"> /// The execution. /// </param> /// <param name="operationContext"> /// The operation context. /// </param> /// <param name="alertStream"> /// The alert stream. /// </param> /// <param name="universeDataRequestsSubscriber"> /// The universe data requests subscriber. /// </param> /// <param name="layeringParameters"> /// The layering parameters. /// </param> /// <returns> /// The <see cref="IUniverseRule"/>. /// </returns> private IReadOnlyCollection <IUniverseRule> SubscribeToUniverse( ScheduledExecution execution, ISystemProcessOperationContext operationContext, IUniverseAlertStream alertStream, IUniverseDataRequestsSubscriber universeDataRequestsSubscriber, IReadOnlyCollection <ILayeringRuleEquitiesParameters> layeringParameters) { var subscriptions = new List <IUniverseRule>(); // ReSharper disable once ConditionIsAlwaysTrueOrFalse if (layeringParameters != null && layeringParameters.Any()) { foreach (var param in layeringParameters) { var paramSubscriptions = this.SubscribeToParameters( execution, operationContext, alertStream, universeDataRequestsSubscriber, param); subscriptions.Add(paramSubscriptions); } } else { const string ErrorMessage = "tried to schedule a layering rule execution with no parameters set"; this.logger.LogError(ErrorMessage); operationContext.EventError(ErrorMessage); } return(subscriptions); }
/// <summary> /// Initializes a new instance of the <see cref="CancelledOrderRule"/> class. /// </summary> /// <param name="parameters"> /// The 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="runMode"> /// The run mode. /// </param> /// <param name="logger"> /// The logger. /// </param> /// <param name="tradingHistoryLogger"> /// The trading history logger. /// </param> public CancelledOrderRule( ICancelledOrderRuleEquitiesParameters parameters, ISystemProcessOperationRunRuleContext operationContext, IUniverseAlertStream alertStream, IUniverseOrderFilter orderFilter, IUniverseEquityMarketCacheFactory equityMarketCacheFactory, IUniverseFixedIncomeMarketCacheFactory fixedIncomeMarketCacheFactory, RuleRunMode runMode, ILogger <CancelledOrderRule> logger, ILogger <TradingHistoryStack> tradingHistoryLogger) : base( parameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromMinutes(60), parameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromMinutes(60), parameters?.Windows?.FutureWindowSize ?? TimeSpan.Zero, Rules.CancelledOrders, Versioner.Version(2, 0), "Cancelled Order Rule", operationContext, equityMarketCacheFactory, fixedIncomeMarketCacheFactory, runMode, logger, tradingHistoryLogger) { this.parameters = parameters ?? throw new ArgumentNullException(nameof(parameters)); this.operationContext = operationContext ?? throw new ArgumentNullException(nameof(operationContext)); this.alertStream = alertStream ?? throw new ArgumentNullException(nameof(alertStream)); this.orderFilter = orderFilter ?? throw new ArgumentNullException(nameof(orderFilter)); 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> /// Initializes a new instance of the <see cref="MarkingTheCloseRule"/> class. /// </summary> /// <param name="equitiesParameters"> /// The equities parameters. /// </param> /// <param name="alertStream"> /// The alert stream. /// </param> /// <param name="ruleContext"> /// The rule context. /// </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="runMode"> /// The run mode. /// </param> /// <param name="logger"> /// The logger. /// </param> /// <param name="tradingHistoryLogger"> /// The trading history logger. /// </param> public MarkingTheCloseRule( IMarkingTheCloseEquitiesParameters equitiesParameters, IUniverseAlertStream alertStream, ISystemProcessOperationRunRuleContext ruleContext, IUniverseOrderFilter orderFilter, IUniverseEquityMarketCacheFactory equityMarketCacheFactory, IUniverseFixedIncomeMarketCacheFactory fixedIncomeMarketCacheFactory, IMarketTradingHoursService tradingHoursService, IUniverseDataRequestsSubscriber dataRequestSubscriber, RuleRunMode runMode, ILogger <MarkingTheCloseRule> logger, ILogger <TradingHistoryStack> tradingHistoryLogger) : base( equitiesParameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromMinutes(30), equitiesParameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromMinutes(30), equitiesParameters?.Windows?.FutureWindowSize ?? TimeSpan.FromMinutes(30), Domain.Surveillance.Scheduling.Rules.MarkingTheClose, EquityRuleMarkingTheCloseFactory.Version, "Marking The Close", ruleContext, equityMarketCacheFactory, fixedIncomeMarketCacheFactory, runMode, logger, tradingHistoryLogger) { this.equitiesParameters = equitiesParameters ?? throw new ArgumentNullException(nameof(equitiesParameters)); this.alertStream = alertStream ?? throw new ArgumentNullException(nameof(alertStream)); this.ruleContext = ruleContext ?? throw new ArgumentNullException(nameof(ruleContext)); 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.logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
/// <summary> /// Initializes a new instance of the <see cref="WashTradeRule"/> class. /// </summary> /// <param name="equitiesParameters"> /// The equities parameters. /// </param> /// <param name="ruleContext"> /// The rule context. /// </param> /// <param name="clustering"> /// The clustering. /// </param> /// <param name="alertStream"> /// The alert stream. /// </param> /// <param name="currencyConverterService"> /// The currency converter service. /// </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="runMode"> /// The run mode. /// </param> /// <param name="logger"> /// The logger. /// </param> /// <param name="tradingHistoryLogger"> /// The trading history logger. /// </param> public WashTradeRule( IWashTradeRuleEquitiesParameters equitiesParameters, ISystemProcessOperationRunRuleContext ruleContext, IClusteringService clustering, IUniverseAlertStream alertStream, ICurrencyConverterService currencyConverterService, IUniverseOrderFilter orderFilter, IUniverseEquityMarketCacheFactory equityMarketCacheFactory, IUniverseFixedIncomeMarketCacheFactory fixedIncomeMarketCacheFactory, RuleRunMode runMode, ILogger logger, ILogger <TradingHistoryStack> tradingHistoryLogger) : base( equitiesParameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromDays(1), equitiesParameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromDays(1), equitiesParameters?.Windows?.FutureWindowSize ?? TimeSpan.Zero, Rules.WashTrade, EquityRuleWashTradeFactory.Version, "Wash Trade Rule", ruleContext, equityMarketCacheFactory, fixedIncomeMarketCacheFactory, runMode, logger, tradingHistoryLogger) { this.equitiesParameters = equitiesParameters ?? throw new ArgumentNullException(nameof(equitiesParameters)); this.clustering = clustering ?? throw new ArgumentNullException(nameof(clustering)); this.currencyConverterService = currencyConverterService ?? throw new ArgumentNullException(nameof(currencyConverterService)); this.orderFilter = orderFilter ?? throw new ArgumentNullException(nameof(orderFilter)); this.alertStream = alertStream ?? throw new ArgumentNullException(nameof(alertStream)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
/// <summary> /// Initializes a new instance of the <see cref="FixedIncomeWashTradeRule"/> class. /// </summary> /// <param name="parameters"> /// The parameters. /// </param> /// <param name="orderFilterService"> /// The order filter service. /// </param> /// <param name="ruleContext"> /// The rule context. /// </param> /// <param name="equityFactory"> /// The factory. /// </param> /// <param name="fixedIncomeFactory"> /// The factory. /// </param> /// <param name="runMode"> /// The run mode. /// </param> /// <param name="alertStream"> /// The alert stream. /// </param> /// <param name="clusteringService"> /// The clustering service. /// </param> /// <param name="portfolioFactory"> /// The portfolio factory. /// </param> /// <param name="logger"> /// The logger. /// </param> /// <param name="tradingStackLogger"> /// The trading stack logger. /// </param> public FixedIncomeWashTradeRule( IWashTradeRuleFixedIncomeParameters parameters, IUniverseFixedIncomeOrderFilterService orderFilterService, ISystemProcessOperationRunRuleContext ruleContext, IUniverseEquityMarketCacheFactory equityFactory, IUniverseFixedIncomeMarketCacheFactory fixedIncomeFactory, RuleRunMode runMode, IUniverseAlertStream alertStream, IClusteringService clusteringService, IPortfolioFactory portfolioFactory, ILogger <FixedIncomeWashTradeRule> logger, ILogger <TradingHistoryStack> tradingStackLogger) : base( parameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromDays(1), parameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromDays(1), parameters?.Windows?.FutureWindowSize ?? TimeSpan.Zero, Rules.FixedIncomeWashTrades, Versioner.Version(1, 0), $"{nameof(FixedIncomeWashTradeRule)}", ruleContext, equityFactory, fixedIncomeFactory, runMode, logger, tradingStackLogger) { this.parameters = parameters ?? throw new ArgumentNullException(nameof(parameters)); this.orderFilterService = orderFilterService ?? throw new ArgumentNullException(nameof(orderFilterService)); this.alertStream = alertStream ?? throw new ArgumentNullException(nameof(alertStream)); this.clusteringService = clusteringService ?? throw new ArgumentNullException(nameof(clusteringService)); this.portfolioFactory = portfolioFactory ?? throw new ArgumentNullException(nameof(portfolioFactory)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
/// <summary> /// The collate subscriptions. /// </summary> /// <param name="execution"> /// The execution. /// </param> /// <param name="ruleParameters"> /// The rule parameters. /// </param> /// <param name="operationContext"> /// The operation context. /// </param> /// <param name="dataRequestSubscriber"> /// The data request subscriber. /// </param> /// <param name="judgementService"> /// The judgement service. /// </param> /// <param name="alertStream"> /// The alert stream. /// </param> /// <returns> /// The <see cref="IUniverseEvent"/>. /// </returns> public IReadOnlyCollection <IUniverseRule> CollateSubscriptions( ScheduledExecution execution, RuleParameterDto ruleParameters, ISystemProcessOperationContext operationContext, IUniverseDataRequestsSubscriber dataRequestSubscriber, IJudgementService judgementService, IUniverseAlertStream alertStream) { if (!execution.Rules?.Select(ru => ru.Rule).Contains(Rules.FixedIncomeWashTrades) ?? true) { return(new IUniverseRule[0]); } var filteredParameters = execution.Rules.SelectMany(ru => ru.Ids).Where(ru => ru != null).ToList(); var dtos = ruleParameters.FixedIncomeWashTrades.Where( wt => filteredParameters.Contains(wt.Id, StringComparer.InvariantCultureIgnoreCase)).ToList(); var fixedIncomeWashTradeParameters = this.ruleParameterMapper.Map(execution, dtos); var subscriptions = this.SubscribeToUniverse( execution, operationContext, alertStream, dataRequestSubscriber, fixedIncomeWashTradeParameters); return(subscriptions); }
/// <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)); }
/// <summary> /// Initializes a new instance of the <see cref="PlacingOrdersWithNoIntentToExecuteRule"/> class. /// </summary> /// <param name="parameters"> /// The parameters. /// </param> /// <param name="orderFilter"> /// The order filter. /// </param> /// <param name="ruleContext"> /// The rule context. /// </param> /// <param name="equityMarketCacheFactory"> /// The market cache factory. /// </param> /// <param name="fixedIncomeMarketCacheFactory"> /// The market cache factory. /// </param> /// <param name="alertStream"> /// The alert stream. /// </param> /// <param name="dataRequestSubscriber"> /// The data request subscriber. /// </param> /// <param name="tradingHoursService"> /// The trading hours service. /// </param> /// <param name="runMode"> /// The run mode. /// </param> /// <param name="logger"> /// The logger. /// </param> /// <param name="tradingStackLogger"> /// The trading stack logger. /// </param> public PlacingOrdersWithNoIntentToExecuteRule( IPlacingOrderWithNoIntentToExecuteRuleEquitiesParameters parameters, IUniverseOrderFilter orderFilter, ISystemProcessOperationRunRuleContext ruleContext, IUniverseEquityMarketCacheFactory equityMarketCacheFactory, IUniverseFixedIncomeMarketCacheFactory fixedIncomeMarketCacheFactory, IUniverseAlertStream alertStream, IUniverseDataRequestsSubscriber dataRequestSubscriber, IMarketTradingHoursService tradingHoursService, RuleRunMode runMode, ILogger logger, ILogger <TradingHistoryStack> tradingStackLogger) : base( TimeSpan.FromHours(24), TimeSpan.FromHours(24), TimeSpan.Zero, Domain.Surveillance.Scheduling.Rules.PlacingOrderWithNoIntentToExecute, EquityRulePlacingOrdersWithoutIntentToExecuteFactory.Version, "Placing Orders With No Intent To Execute Rule", ruleContext, equityMarketCacheFactory, fixedIncomeMarketCacheFactory, runMode, logger, tradingStackLogger) { this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); this.ruleContext = ruleContext ?? throw new ArgumentNullException(nameof(ruleContext)); this.alertStream = alertStream ?? throw new ArgumentNullException(nameof(alertStream)); this.dataRequestSubscriber = dataRequestSubscriber ?? throw new ArgumentNullException(nameof(dataRequestSubscriber)); this.orderFilter = orderFilter ?? throw new ArgumentNullException(nameof(orderFilter)); this.parameters = parameters ?? throw new ArgumentNullException(nameof(parameters)); this.tradingHoursService = tradingHoursService ?? throw new ArgumentNullException(nameof(tradingHoursService)); }
/// <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="universeDataRequestsSubscriber"> /// The universe data requests subscriber. /// </param> /// <param name="parameter"> /// The parameter. /// </param> /// <returns> /// The <see cref="IUniverseRule"/>. /// </returns> private IUniverseRule SubscribeToParameters( ScheduledExecution execution, ISystemProcessOperationContext operationContext, IUniverseAlertStream alertStream, IUniverseDataRequestsSubscriber universeDataRequestsSubscriber, IWashTradeRuleFixedIncomeParameters parameter) { var ctx = operationContext.CreateAndStartRuleRunContext( Rules.FixedIncomeWashTrades.GetDescription(), FixedIncomeWashTradeFactory.Version, parameter.Id, (int)Rules.FixedIncomeWashTrades, execution.IsBackTest, execution.TimeSeriesInitiation.DateTime, execution.TimeSeriesTermination.DateTime, execution.CorrelationId, execution.IsForceRerun); var runMode = execution.IsForceRerun ? RuleRunMode.ForceRun : RuleRunMode.ValidationRun; var washTrade = this.fixedIncomeRuleWashTradeFactory.BuildRule(parameter, ctx, alertStream, runMode); var washTradeOrgFactors = this.brokerServiceFactory.Build( washTrade, parameter.Factors, parameter.AggregateNonFactorableIntoOwnCategory); var washTradeFilters = this.DecorateWithFilters( operationContext, parameter, washTradeOrgFactors, universeDataRequestsSubscriber, ctx, runMode); return(washTradeFilters); }
public SpoofingSteps(ScenarioContext scenarioContext, UniverseSelectionState universeSelectionState) { this._scenarioContext = scenarioContext ?? throw new ArgumentNullException(nameof(scenarioContext)); this._universeSelectionState = universeSelectionState ?? throw new ArgumentNullException(nameof(universeSelectionState)); this._orderAnalysisService = new OrderAnalysisService(); this._ruleCtx = A.Fake <ISystemProcessOperationRunRuleContext>(); this._alertStream = A.Fake <IUniverseAlertStream>(); var equityMarketCacheFactory = new UniverseEquityMarketCacheFactory( new StubRuleRunDataRequestRepository(), new StubRuleRunDataRequestRepository(), new NullLogger <UniverseEquityMarketCacheFactory>()); var fixedIncomeMarketCacheFactory = new UniverseFixedIncomeMarketCacheFactory( new StubRuleRunDataRequestRepository(), new StubRuleRunDataRequestRepository(), new NullLogger <UniverseFixedIncomeMarketCacheFactory>()); this._equityRuleSpoofingFactory = new EquityRuleSpoofingFactory( equityMarketCacheFactory, fixedIncomeMarketCacheFactory, new UniverseEquityOrderFilterService(new NullLogger <UniverseEquityOrderFilterService>()), new PortfolioFactory(), this._orderAnalysisService, new NullLogger <SpoofingRule>(), new NullLogger <TradingHistoryStack>()); }
/// <summary> /// The subscribe to universe. /// </summary> /// <param name="execution"> /// The execution. /// </param> /// <param name="operationContext"> /// The operation context. /// </param> /// <param name="alertStream"> /// The alert stream. /// </param> /// <param name="rampingParameters"> /// The ramping parameters. /// </param> /// <param name="dataRequestSubscriber"> /// The data request subscriber. /// </param> /// <returns> /// The <see cref="IUniverseRule"/>. /// </returns> private IReadOnlyCollection <IUniverseRule> SubscribeToUniverse( ScheduledExecution execution, ISystemProcessOperationContext operationContext, IUniverseAlertStream alertStream, IReadOnlyCollection <IRampingRuleEquitiesParameters> rampingParameters, IUniverseDataRequestsSubscriber dataRequestSubscriber) { var subscriptions = new List <IUniverseRule>(); if (rampingParameters != null && rampingParameters.Any()) { foreach (var param in rampingParameters) { var baseSubscriber = this.SubscribeParameterToUniverse( execution, operationContext, alertStream, param, dataRequestSubscriber); subscriptions.Add(baseSubscriber); } } else { const string ErrorMessage = "tried to schedule a cancelled order rule execution with no parameters set"; this.logger.LogError(ErrorMessage); operationContext.EventError(ErrorMessage); } return(subscriptions); }
/// <summary> /// The subscribe for parameters. /// </summary> /// <param name="execution"> /// The execution. /// </param> /// <param name="operationContext"> /// The operation context. /// </param> /// <param name="alertStream"> /// The alert stream. /// </param> /// <param name="universeDataRequestsSubscriber"> /// The universe data requests subscriber. /// </param> /// <param name="parameter"> /// The parameter. /// </param> /// <returns> /// The <see cref="IUniverseRule"/>. /// </returns> private IUniverseRule SubscribeForParameters( ScheduledExecution execution, ISystemProcessOperationContext operationContext, IUniverseAlertStream alertStream, IUniverseDataRequestsSubscriber universeDataRequestsSubscriber, ISpoofingRuleEquitiesParameters parameter) { var ruleCtx = operationContext.CreateAndStartRuleRunContext( Rules.Spoofing.GetDescription(), EquityRuleSpoofingFactory.Version, parameter.Id, (int)Rules.Spoofing, execution.IsBackTest, execution.TimeSeriesInitiation.DateTime, execution.TimeSeriesTermination.DateTime, execution.CorrelationId, execution.IsForceRerun); var runMode = execution.IsForceRerun ? RuleRunMode.ForceRun : RuleRunMode.ValidationRun; var spoofingRule = this.equityRuleSpoofingFactory.Build(parameter, ruleCtx, alertStream, runMode); var spoofingRuleOrgFactors = this.brokerServiceFactory.Build( spoofingRule, parameter.Factors, parameter.AggregateNonFactorableIntoOwnCategory); var filteredSpoofingRule = this.DecorateWithFilters( operationContext, parameter, spoofingRuleOrgFactors, universeDataRequestsSubscriber, ruleCtx, runMode); return(filteredSpoofingRule); }
public IWashTradeRule Build( IWashTradeRuleEquitiesParameters equitiesParameters, ISystemProcessOperationRunRuleContext ruleCtx, IUniverseAlertStream alertStream, RuleRunMode runMode) { if (ruleCtx == null) { throw new ArgumentNullException(nameof(ruleCtx)); } if (equitiesParameters == null) { throw new ArgumentNullException(nameof(equitiesParameters)); } return(new WashTradeRule( equitiesParameters, ruleCtx, this._clustering, alertStream, this._currencyConverterService, this._orderFilterService, this._equityFactory, this._fixedIncomeFactory, runMode, this._logger, this._tradingHistoryLogger)); }
/// <summary> /// Initializes a new instance of the <see cref="SpoofingRule"/> class. /// </summary> /// <param name="equitiesParameters"> /// The equities parameters. /// </param> /// <param name="ruleContext"> /// The rule 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="runMode"> /// The run mode. /// </param> /// <param name="portfolioFactory"> /// The portfolio factory. /// </param> /// <param name="analysisService"> /// The analysis service. /// </param> /// <param name="logger"> /// The logger. /// </param> /// <param name="tradingHistoryLogger"> /// The trading history logger. /// </param> public SpoofingRule( ISpoofingRuleEquitiesParameters equitiesParameters, ISystemProcessOperationRunRuleContext ruleContext, IUniverseAlertStream alertStream, IUniverseOrderFilter orderFilter, IUniverseEquityMarketCacheFactory equityMarketCacheFactory, IUniverseFixedIncomeMarketCacheFactory fixedIncomeMarketCacheFactory, RuleRunMode runMode, IPortfolioFactory portfolioFactory, IOrderAnalysisService analysisService, ILogger logger, ILogger <TradingHistoryStack> tradingHistoryLogger) : base( equitiesParameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromMinutes(30), equitiesParameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromMinutes(30), equitiesParameters?.Windows?.FutureWindowSize ?? TimeSpan.Zero, Rules.Spoofing, EquityRuleSpoofingFactory.Version, "Spoofing Rule", ruleContext, equityMarketCacheFactory, fixedIncomeMarketCacheFactory, runMode, logger, tradingHistoryLogger) { this.equitiesParameters = equitiesParameters ?? throw new ArgumentNullException(nameof(equitiesParameters)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); this.alertStream = alertStream ?? throw new ArgumentNullException(nameof(alertStream)); this.orderFilter = orderFilter ?? throw new ArgumentNullException(nameof(orderFilter)); this.portfolioFactory = portfolioFactory ?? throw new ArgumentNullException(nameof(portfolioFactory)); this.analysisService = analysisService ?? throw new ArgumentNullException(nameof(analysisService)); this.ruleContext = ruleContext ?? throw new ArgumentNullException(nameof(ruleContext)); }
/// <summary> /// The collate subscriptions. /// </summary> /// <param name="execution"> /// The execution. /// </param> /// <param name="ruleParameters"> /// The rule parameters. /// </param> /// <param name="operationContext"> /// The operation context. /// </param> /// <param name="dataRequestSubscriber"> /// The data request subscriber. /// </param> /// <param name="judgementService"> /// The judgement service. /// </param> /// <param name="alertStream"> /// The alert stream. /// </param> /// <returns> /// The <see cref="IUniverseRule"/>. /// </returns> public IReadOnlyCollection <IUniverseRule> CollateSubscriptions( ScheduledExecution execution, RuleParameterDto ruleParameters, ISystemProcessOperationContext operationContext, IUniverseDataRequestsSubscriber dataRequestSubscriber, IJudgementService judgementService, IUniverseAlertStream alertStream) { if (!execution.Rules?.Select(_ => _.Rule)?.Contains(Rules.PlacingOrderWithNoIntentToExecute) ?? true) { return(new IUniverseRule[0]); } var filteredParameters = execution.Rules.SelectMany(_ => _.Ids).Where(_ => _ != null).ToList(); var dtos = ruleParameters.PlacingOrders .Where(_ => filteredParameters.Contains(_.Id, StringComparer.InvariantCultureIgnoreCase)).ToList(); var placingOrderParameters = this.ruleParameterMapper.Map(execution, dtos); var subscriptions = this.SubscribeToUniverse( execution, operationContext, alertStream, placingOrderParameters, dataRequestSubscriber); return(subscriptions); }
public void Setup() { this._currencyConverterService = A.Fake <ICurrencyConverterService>(); this._ruleCtx = A.Fake <ISystemProcessOperationRunRuleContext>(); this._alertStream = A.Fake <IUniverseAlertStream>(); this._clustering = new ClusteringService(); this._equitiesParameters = A.Fake <IWashTradeRuleEquitiesParameters>(); this._logger = A.Fake <ILogger>(); this._ruleRunRepository = A.Fake <IRuleRunDataRequestRepository>(); this._stubRuleRunRepository = A.Fake <IStubRuleRunDataRequestRepository>(); this._loggerEquityCache = A.Fake <ILogger <UniverseEquityMarketCacheFactory> >(); this._loggerFixedIncomeCache = A.Fake <ILogger <UniverseFixedIncomeMarketCacheFactory> >(); this._tradingLogger = A.Fake <ILogger <TradingHistoryStack> >(); this._orderFilter = A.Fake <IUniverseOrderFilter>(); this._equityFactory = new UniverseEquityMarketCacheFactory( this._stubRuleRunRepository, this._ruleRunRepository, this._loggerEquityCache); this._fixedIncomeFactory = new UniverseFixedIncomeMarketCacheFactory( this._stubRuleRunRepository, this._ruleRunRepository, this._loggerFixedIncomeCache); A.CallTo(() => this._orderFilter.Filter(A <IUniverseEvent> .Ignored)) .ReturnsLazily(i => (IUniverseEvent)i.Arguments[0]); A.CallTo(() => this._equitiesParameters.PerformClusteringPositionAnalysis).Returns(true); A.CallTo(() => this._equitiesParameters.ClusteringPercentageValueDifferenceThreshold).Returns(0.05m); }
public CancelledOrdersSteps(ScenarioContext scenarioContext, UniverseSelectionState universeSelectionState) { this._scenarioContext = scenarioContext; this._universeSelectionState = universeSelectionState; this._equityMarketCacheFactory = new UniverseEquityMarketCacheFactory( new StubRuleRunDataRequestRepository(), new StubRuleRunDataRequestRepository(), new NullLogger <UniverseEquityMarketCacheFactory>()); this._fixedIncomeMarketCacheFactory = new UniverseFixedIncomeMarketCacheFactory( new StubRuleRunDataRequestRepository(), new StubRuleRunDataRequestRepository(), new NullLogger <UniverseFixedIncomeMarketCacheFactory>()); this._alertStream = A.Fake <IUniverseAlertStream>(); this._ruleCtx = A.Fake <ISystemProcessOperationRunRuleContext>(); this._universeOrderFilterService = A.Fake <IUniverseEquityOrderFilterService>(); this._equityRuleCancelledOrderFactory = new EquityRuleCancelledOrderFactory( this._universeOrderFilterService, this._equityMarketCacheFactory, this._fixedIncomeMarketCacheFactory, new NullLogger <CancelledOrderRule>(), new NullLogger <TradingHistoryStack>()); }
/// <summary> /// The subscribe to universe. /// </summary> /// <param name="execution"> /// The execution. /// </param> /// <param name="operationContext"> /// The operation context. /// </param> /// <param name="alertStream"> /// The alert stream. /// </param> /// <param name="universeDataRequestsSubscriber"> /// The universe data requests subscriber. /// </param> /// <param name="washTradeParameters"> /// The wash trade parameters. /// </param> /// <returns> /// The <see cref="IUniverseRule"/>. /// </returns> private IReadOnlyCollection <IUniverseRule> SubscribeToUniverse( ScheduledExecution execution, ISystemProcessOperationContext operationContext, IUniverseAlertStream alertStream, IUniverseDataRequestsSubscriber universeDataRequestsSubscriber, IReadOnlyCollection <IWashTradeRuleFixedIncomeParameters> washTradeParameters) { var subscriptions = new List <IUniverseRule>(); if (washTradeParameters != null && washTradeParameters.Any()) { foreach (var param in washTradeParameters) { var paramSubscriptions = this.SubscribeToParameters( execution, operationContext, alertStream, universeDataRequestsSubscriber, param); subscriptions.Add(paramSubscriptions); } } else { const string ErrorMessage = "tried to schedule a wash trade rule execution with no parameters set"; this.logger.LogError(ErrorMessage); operationContext.EventError(ErrorMessage); } return(subscriptions); }
public void Setup() { this._orderFilterService = A.Fake <IUniverseEquityOrderFilterService>(); this._equityFactory = A.Fake <IUniverseEquityMarketCacheFactory>(); this._fixedIncomeFactory = A.Fake <IUniverseFixedIncomeMarketCacheFactory>(); this._logger = A.Fake <ILogger <CancelledOrderRule> >(); this._tradingHistoryLogger = A.Fake <ILogger <TradingHistoryStack> >(); this._parameters = A.Fake <ICancelledOrderRuleEquitiesParameters>(); this._ruleCtx = A.Fake <ISystemProcessOperationRunRuleContext>(); this._alertStream = A.Fake <IUniverseAlertStream>(); }
public void Setup() { this._parameters = A.Fake <IWashTradeRuleFixedIncomeParameters>(); this._fixedIncomeOrderFile = A.Fake <IUniverseFixedIncomeOrderFilterService>(); this._ruleCtx = A.Fake <ISystemProcessOperationRunRuleContext>(); this._equityMarketCacheFactory = A.Fake <IUniverseEquityMarketCacheFactory>(); this._fixedIncomeMarketCacheFactory = A.Fake <IUniverseFixedIncomeMarketCacheFactory>(); this._alertStream = A.Fake <IUniverseAlertStream>(); this._clusteringService = A.Fake <IClusteringService>(); this._portfolioFactory = A.Fake <IPortfolioFactory>(); this._logger = new NullLogger <FixedIncomeHighProfitsRule>(); this._tradingStackLogger = new NullLogger <TradingHistoryStack>(); }
public void Setup() { this._orderFilterService = A.Fake <IUniverseEquityOrderFilterService>(); this._equityFactory = A.Fake <IUniverseEquityMarketCacheFactory>(); this._fixedIncomeFactory = A.Fake <IUniverseFixedIncomeMarketCacheFactory>(); this._portfolioFactory = A.Fake <IPortfolioFactory>(); this._orderAnalysisService = A.Fake <IOrderAnalysisService>(); this._logger = new NullLogger <SpoofingRule>(); this._tradingHistoryLogger = new NullLogger <TradingHistoryStack>(); this._spoofingEquitiesParameters = A.Fake <ISpoofingRuleEquitiesParameters>(); this._ruleCtx = A.Fake <ISystemProcessOperationRunRuleContext>(); this._alertStream = A.Fake <IUniverseAlertStream>(); }
public void Setup() { this._orderFilterService = A.Fake <IUniverseEquityOrderFilterService>(); this._equityFactory = A.Fake <IUniverseEquityMarketCacheFactory>(); this._fixedIncomeFactory = A.Fake <IUniverseFixedIncomeMarketCacheFactory>(); this._tradingHoursService = A.Fake <IMarketTradingHoursService>(); this._logger = new NullLogger <MarkingTheCloseRule>(); this._tradingHistoryLogger = new NullLogger <TradingHistoryStack>(); this._dataRequestSubscriber = A.Fake <IUniverseDataRequestsSubscriber>(); this._equitiesParameters = A.Fake <IMarkingTheCloseEquitiesParameters>(); this._ruleCtx = A.Fake <ISystemProcessOperationRunRuleContext>(); this._alertStream = A.Fake <IUniverseAlertStream>(); }
public void Setup() { this._currencyConverterService = A.Fake <ICurrencyConverterService>(); this._clustering = A.Fake <IClusteringService>(); this._orderFilterService = A.Fake <IUniverseEquityOrderFilterService>(); this._equityFactory = A.Fake <IUniverseEquityMarketCacheFactory>(); this._fixedIncomeFactory = A.Fake <IUniverseFixedIncomeMarketCacheFactory>(); this._logger = new NullLogger <WashTradeRule>(); this._tradingHistoryLogger = new NullLogger <TradingHistoryStack>(); this._equitiesParameters = A.Fake <IWashTradeRuleEquitiesParameters>(); this._ruleCtx = A.Fake <ISystemProcessOperationRunRuleContext>(); this._alertStream = A.Fake <IUniverseAlertStream>(); }
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>(); }
private void Setup() { this._orderFilterService = A.Fake <IUniverseFixedIncomeOrderFilterService>(); this._ruleCtx = A.Fake <ISystemProcessOperationRunRuleContext>(); this._alertStream = A.Fake <IUniverseAlertStream>(); this._portfolioFactory = new PortfolioFactory(); this._clusteringService = new ClusteringService(); this._equityMarketCacheFactory = new UniverseEquityMarketCacheFactory( new StubRuleRunDataRequestRepository(), new StubRuleRunDataRequestRepository(), new NullLogger <UniverseEquityMarketCacheFactory>()); this._fixedIncomeMarketCacheFactory = new UniverseFixedIncomeMarketCacheFactory( new StubRuleRunDataRequestRepository(), new StubRuleRunDataRequestRepository(), new NullLogger <UniverseFixedIncomeMarketCacheFactory>()); }
public ICancelledOrderRule Build( ICancelledOrderRuleEquitiesParameters parameters, ISystemProcessOperationRunRuleContext ruleCtx, IUniverseAlertStream alertStream, RuleRunMode runMode) { return(new CancelledOrderRule( parameters, ruleCtx, alertStream, this._orderFilterService, this._equityFactory, this._fixedIncomeFactory, runMode, this._logger, this._tradingHistoryLogger)); }
public WashTradeSteps(ScenarioContext scenarioContext, UniverseSelectionState universeSelectionState) { this._scenarioContext = scenarioContext; this._universeSelectionState = universeSelectionState; var exchangeRateApiRepository = A.Fake <IExchangeRateApiCachingDecorator>(); var exchangeRateDto = new ExchangeRateDto { DateTime = new DateTime(2018, 01, 01), Name = "GBX/USD", FixedCurrency = "GBX", VariableCurrency = "USD", Rate = 200d }; A.CallTo(() => exchangeRateApiRepository.GetAsync(A <DateTime> .Ignored, A <DateTime> .Ignored)).Returns( new Dictionary <DateTime, IReadOnlyCollection <ExchangeRateDto> > { { new DateTime(2018, 01, 01), new[] { exchangeRateDto } } }); var currencyLogger = new NullLogger <CurrencyConverterService>(); this._currencyConverterService = new CurrencyConverterService(exchangeRateApiRepository, currencyLogger); this._washTradeClustering = new ClusteringService(); this._universeOrderFilterService = A.Fake <IUniverseEquityOrderFilterService>(); this._equityMarketCacheFactory = A.Fake <IUniverseEquityMarketCacheFactory>(); this._fixedIncomeMarketCacheFactory = A.Fake <IUniverseFixedIncomeMarketCacheFactory>(); this._logger = new NullLogger <WashTradeRule>(); this._tradingLogger = new NullLogger <TradingHistoryStack>(); this._equityRuleWashTradeFactory = new EquityRuleWashTradeFactory( this._currencyConverterService, this._washTradeClustering, this._universeOrderFilterService, this._equityMarketCacheFactory, this._fixedIncomeMarketCacheFactory, this._logger, this._tradingLogger); this._ruleCtx = A.Fake <ISystemProcessOperationRunRuleContext>(); this._alertStream = A.Fake <IUniverseAlertStream>(); }