Esempio n. 1
0
        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);
        }
        public void RunRule_RaisesAlertInEschaton_WhenBidirectionalTrade()
        {
            _tradingHoursService = new MarketTradingHoursService(_tradingHoursRepository, new NullLogger <MarketTradingHoursService>());
            var parameters = new LayeringRuleEquitiesParameters("id", TimeSpan.FromMinutes(30), null, null, null, null, false, true);
            var rule       = new LayeringRule(parameters, _alertStream, _orderFilter, _logger, _equityFactory, _fixedIncomeFactory, _tradingHoursService, _ruleCtx, RuleRunMode.ValidationRun, _tradingLogger);
            var tradeBuy   = ((Order)null).Random();
            var tradeSell  = ((Order)null).Random();

            tradeBuy.OrderDirection  = OrderDirections.BUY;
            tradeBuy.FilledDate      = tradeBuy.PlacedDate.Value.AddMinutes(1);
            tradeSell.OrderDirection = OrderDirections.SELL;
            tradeSell.FilledDate     = tradeSell.PlacedDate.Value.AddMinutes(1);

            var genesis   = new UniverseEvent(UniverseStateEvent.Genesis, tradeBuy.PlacedDate.Value.AddMinutes(-1), new object());
            var buyEvent  = new UniverseEvent(UniverseStateEvent.OrderPlaced, tradeBuy.PlacedDate.Value, tradeBuy);
            var sellEvent = new UniverseEvent(UniverseStateEvent.OrderPlaced, tradeSell.PlacedDate.Value, tradeSell);
            var eschaton  = new UniverseEvent(UniverseStateEvent.Eschaton, tradeSell.PlacedDate.Value.AddMinutes(-1), new object());

            rule.OnNext(genesis);
            rule.OnNext(buyEvent);
            rule.OnNext(sellEvent);
            rule.OnNext(eschaton);

            A.CallTo(() => _alertStream.Add(A <IUniverseAlertEvent> .Ignored)).MustHaveHappenedTwiceExactly();
        }
Esempio n. 3
0
        public HighMarketCapFilter(
            IUniverseEquityMarketCacheFactory factory,
            RuleRunMode ruleRunMode,
            DecimalRangeRuleFilter marketCap,
            IMarketTradingHoursService tradingHoursService,
            ISystemProcessOperationRunRuleContext operationRunRuleContext,
            IUniverseDataRequestsSubscriber universeDataRequestsSubscriber,
            ICurrencyConverterService currencyConverterService,
            string ruleName,
            ILogger <HighMarketCapFilter> logger
            )
        {
            _universeEquityInterdayCache =
                factory?.BuildInterday(ruleRunMode)
                ?? throw new ArgumentNullException(nameof(factory));

            _ruleRunMode     = ruleRunMode;
            _marketCapFilter = marketCap ?? DecimalRangeRuleFilter.None();

            _tradingHoursService            = tradingHoursService ?? throw new ArgumentNullException(nameof(tradingHoursService));
            _operationRunRuleContext        = operationRunRuleContext ?? throw new ArgumentNullException(nameof(operationRunRuleContext));
            _universeDataRequestsSubscriber = universeDataRequestsSubscriber;
            this.currencyConverterService   = currencyConverterService ?? throw new ArgumentNullException(nameof(currencyConverterService));
            _name   = ruleName;
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));
        }
Esempio n. 4
0
 /// <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));
 }
Esempio n. 5
0
 /// <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));
 }
Esempio n. 6
0
 public RevenueMarkingCloseCalculator(
     IMarketTradingHoursService tradingHoursService,
     ICurrencyConverterService currencyConverterService,
     ILogger <RevenueCalculator> logger)
     : base(tradingHoursService, currencyConverterService, logger)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FixedIncomeHighVolumeRule"/> 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="judgementService">
 /// The judgement service.
 /// </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 FixedIncomeHighVolumeRule(
     IHighVolumeIssuanceRuleFixedIncomeParameters parameters,
     IUniverseFixedIncomeOrderFilterService orderFilterService,
     ISystemProcessOperationRunRuleContext ruleContext,
     IUniverseEquityMarketCacheFactory equityFactory,
     IUniverseFixedIncomeMarketCacheFactory fixedIncomeFactory,
     IFixedIncomeHighVolumeJudgementService judgementService,
     IUniverseDataRequestsSubscriber dataRequestSubscriber,
     IMarketTradingHoursService tradingHoursService,
     RuleRunMode runMode,
     ILogger <FixedIncomeHighVolumeRule> logger,
     ILogger <TradingHistoryStack> tradingStackLogger)
     : base(
         parameters.Windows.BackwardWindowSize,
         parameters.Windows.BackwardWindowSize,
         parameters.Windows.FutureWindowSize,
         Rules.FixedIncomeHighVolumeIssuance,
         FixedIncomeHighVolumeFactory.Version,
         $"{nameof(FixedIncomeHighVolumeRule)}",
         ruleContext,
         equityFactory,
         fixedIncomeFactory,
         runMode,
         logger,
         tradingStackLogger)
 {
     this.parameters            = parameters ?? throw new ArgumentNullException(nameof(parameters));
     this.orderFilterService    = orderFilterService ?? throw new ArgumentNullException(nameof(orderFilterService));
     this.judgementService      = judgementService ?? throw new ArgumentNullException(nameof(judgementService));
     this.dataRequestSubscriber = dataRequestSubscriber ?? throw new ArgumentNullException(nameof(dataRequestSubscriber));
     this.tradingHoursService   = tradingHoursService ?? throw new ArgumentNullException(nameof(tradingHoursService));
     this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Esempio n. 8
0
 /// <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));
 }
Esempio n. 9
0
 /// <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));
 }
 public RevenueCurrencyConvertingMarkingCloseCalculator(
     Domain.Core.Financial.Money.Currency targetCurrency,
     ICurrencyConverterService currencyConverterService,
     IMarketTradingHoursService tradingHoursService,
     ILogger <RevenueCurrencyConvertingCalculator> logger)
     : base(targetCurrency, currencyConverterService, tradingHoursService, logger)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="RevenueCalculator"/> class.
 /// </summary>
 /// <param name="tradingHoursService">
 /// The trading hours service.
 /// </param>
 /// <param name="logger">
 /// The logger.
 /// </param>
 public RevenueCalculator(
     IMarketTradingHoursService tradingHoursService,
     ICurrencyConverterService currencyConverterService,
     ILogger <RevenueCalculator> logger)
 {
     this.TradingHoursService      = tradingHoursService ?? throw new ArgumentNullException(nameof(tradingHoursService));
     this.CurrencyConverterService = currencyConverterService ?? throw new ArgumentNullException(nameof(currencyConverterService));
     this.Logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Esempio n. 12
0
 public void Setup()
 {
     this.parameters                    = A.Fake <IHighVolumeIssuanceRuleFixedIncomeParameters>();
     this.fixedIncomeOrderFile          = A.Fake <IUniverseFixedIncomeOrderFilterService>();
     this.ruleContext                   = A.Fake <ISystemProcessOperationRunRuleContext>();
     this.equityMarketCacheFactory      = A.Fake <IUniverseEquityMarketCacheFactory>();
     this.fixedIncomeMarketCacheFactory = A.Fake <IUniverseFixedIncomeMarketCacheFactory>();
     this.marketTradingHoursService     = A.Fake <IMarketTradingHoursService>();
     this.tradingStackLogger            = new NullLogger <TradingHistoryStack>();
 }
        public void RunRule_DoesNotRaiseAlertInEschaton_WhenBidirectionalTradeAndDoesNotExceedsWindowThreshold_AndNoMarketData()
        {
            var parameters = new LayeringRuleEquitiesParameters("id", TimeSpan.FromMinutes(30), null, 0.1m, null, null, false, true);

            _tradingHoursService = new MarketTradingHoursService(_tradingHoursRepository, new NullLogger <MarketTradingHoursService>());
            var rule      = new LayeringRule(parameters, _alertStream, _orderFilter, _logger, _equityFactory, _fixedIncomeFactory, _tradingHoursService, _ruleCtx, RuleRunMode.ValidationRun, _tradingLogger);
            var tradeBuy  = ((Order)null).Random();
            var tradeSell = ((Order)null).Random();

            tradeBuy.OrderDirection  = OrderDirections.BUY;
            tradeBuy.FilledDate      = tradeBuy.PlacedDate.Value.AddMinutes(1);
            tradeSell.OrderDirection = OrderDirections.SELL;
            tradeSell.FilledDate     = tradeSell.PlacedDate.Value.AddMinutes(1);

            tradeBuy.OrderFilledVolume  = 100;
            tradeSell.OrderFilledVolume = 100;
            var market = new Market("1", "XLON", "London Stock Exchange", MarketTypes.STOCKEXCHANGE);

            var marketData = new EquityIntraDayTimeBarCollection(market, tradeBuy.PlacedDate.Value.AddSeconds(-55),
                                                                 new List <EquityInstrumentIntraDayTimeBar>
            {
                new EquityInstrumentIntraDayTimeBar(
                    tradeBuy.Instrument,
                    new SpreadTimeBar(
                        tradeBuy.OrderAverageFillPrice.Value,
                        tradeSell.OrderAverageFillPrice.Value,
                        tradeSell.OrderAverageFillPrice.Value,
                        new Volume(2000)),
                    new DailySummaryTimeBar(
                        1000,
                        "USD",
                        new IntradayPrices(tradeBuy.OrderAverageFillPrice.Value, tradeBuy.OrderAverageFillPrice.Value,
                                           tradeBuy.OrderAverageFillPrice.Value, tradeBuy.OrderAverageFillPrice.Value),
                        1000,
                        new Volume(2000),
                        tradeBuy.PlacedDate.Value.AddSeconds(-55)),
                    tradeBuy.PlacedDate.Value.AddSeconds(-55),
                    market)
            });

            var genesis         = new UniverseEvent(UniverseStateEvent.Genesis, tradeBuy.PlacedDate.Value.AddMinutes(-1), new object());
            var marketDataEvent = new UniverseEvent(UniverseStateEvent.EquityIntraDayTick, tradeBuy.PlacedDate.Value.AddSeconds(-55), marketData);
            var buyEvent        = new UniverseEvent(UniverseStateEvent.OrderPlaced, tradeBuy.PlacedDate.Value, tradeBuy);
            var sellEvent       = new UniverseEvent(UniverseStateEvent.OrderPlaced, tradeSell.PlacedDate.Value, tradeSell);
            var eschaton        = new UniverseEvent(UniverseStateEvent.Eschaton, tradeSell.PlacedDate.Value.AddMinutes(1), new object());

            rule.OnNext(genesis);
            rule.OnNext(buyEvent);
            rule.OnNext(sellEvent);
            rule.OnNext(marketDataEvent);
            rule.OnNext(eschaton);

            A.CallTo(() => _alertStream.Add(A <IUniverseAlertEvent> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => _ruleCtx.EndEvent()).MustHaveHappenedOnceExactly();
        }
Esempio n. 14
0
        public void Setup()
        {
            this._equityMarketCacheFactory      = A.Fake <IUniverseEquityMarketCacheFactory>();
            this._fixedIncomeMarketCacheFactory = A.Fake <IUniverseFixedIncomeMarketCacheFactory>();
            this._ruleRunContext            = A.Fake <ISystemProcessOperationRunRuleContext>();
            this._ruleRunMode               = RuleRunMode.ValidationRun;
            this._universeOrderFilter       = A.Fake <IUniverseOrderFilter>();
            this._timeWindows               = new TimeWindows("id-1", TimeSpan.FromDays(1));
            this._decimalRangeRuleFilter    = new DecimalRangeRuleFilter();
            this._marketTradingHoursService = A.Fake <IMarketTradingHoursService>();
            this._dataRequestSubscriber     = A.Fake <IUniverseDataRequestsSubscriber>();
            this._baseLogger    = A.Fake <ILogger>();
            this._tradingLogger = A.Fake <ILogger <TradingHistoryStack> >();
            this._logger        = A.Fake <ILogger <HighVolumeVenueFilter> >();

            A.CallTo(() => this._universeOrderFilter.Filter(A <IUniverseEvent> .Ignored))
            .ReturnsLazily(_ => _.Arguments.First() as IUniverseEvent);

            var repository = A.Fake <IMarketOpenCloseApiCachingDecorator>();

            A.CallTo(() => repository.GetAsync()).Returns(
                new[]
            {
                new ExchangeDto
                {
                    Code              = "XLON",
                    MarketOpenTime    = TimeSpan.FromHours(8),
                    MarketCloseTime   = TimeSpan.FromHours(16),
                    IsOpenOnMonday    = true,
                    IsOpenOnTuesday   = true,
                    IsOpenOnWednesday = true,
                    IsOpenOnThursday  = true,
                    IsOpenOnFriday    = true,
                    IsOpenOnSaturday  = true,
                    IsOpenOnSunday    = true
                },
                new ExchangeDto
                {
                    Code              = "NASDAQ",
                    MarketOpenTime    = TimeSpan.FromHours(15),
                    MarketCloseTime   = TimeSpan.FromHours(23),
                    IsOpenOnMonday    = true,
                    IsOpenOnTuesday   = true,
                    IsOpenOnWednesday = true,
                    IsOpenOnThursday  = true,
                    IsOpenOnFriday    = true,
                    IsOpenOnSaturday  = true,
                    IsOpenOnSunday    = true
                }
            });

            this._tradingHoursService = new MarketTradingHoursService(
                repository,
                new NullLogger <MarketTradingHoursService>());
        }
 public RevenueCurrencyConvertingCalculator(
     Domain.Core.Financial.Money.Currency targetCurrency,
     ICurrencyConverterService currencyConverterService,
     IMarketTradingHoursService tradingHoursService,
     ILogger <RevenueCurrencyConvertingCalculator> logger)
 {
     _targetCurrency           = targetCurrency;
     _currencyConverterService = currencyConverterService ?? throw new ArgumentNullException(nameof(currencyConverterService));
     TradingHoursService       = tradingHoursService ?? throw new ArgumentNullException(nameof(tradingHoursService));
     Logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Esempio n. 16
0
 public HighMarketCapFilterFactory(
     ICurrencyConverterService currencyConverterService,
     IUniverseEquityMarketCacheFactory universeMarketCacheFactory,
     IMarketTradingHoursService tradingHoursService,
     ILoggerFactory loggerFactory)
 {
     this.currencyConverterService = currencyConverterService ?? throw new ArgumentNullException(nameof(currencyConverterService));
     _universeMarketCacheFactory   = universeMarketCacheFactory ?? throw new ArgumentNullException(nameof(universeMarketCacheFactory));
     _tradingHoursService          = tradingHoursService ?? throw new ArgumentNullException(nameof(tradingHoursService));
     _loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
 }
        public void Setup()
        {
            this._tradingHoursService = A.Fake <IMarketTradingHoursService>();
            this._equityFactory       = A.Fake <IUniverseEquityMarketCacheFactory>();
            this._fixedIncomeFactory  = A.Fake <IUniverseFixedIncomeMarketCacheFactory>();
            this._orderFilterService  = A.Fake <IUniverseEquityOrderFilterService>();
            this._logger        = A.Fake <ILogger <EquityRuleLayeringFactory> >();
            this._tradingLogger = A.Fake <ILogger <TradingHistoryStack> >();

            this._equitiesParameters = A.Fake <ILayeringRuleEquitiesParameters>();
            this._ruleCtx            = A.Fake <ISystemProcessOperationRunRuleContext>();
            this._alertStream        = A.Fake <IUniverseAlertStream>();
        }
Esempio n. 18
0
        public void SetUp()
        {
            this.currencyConverterService   = A.Fake <ICurrencyConverterService>();
            _universeMarketCacheFactory     = A.Fake <IUniverseEquityMarketCacheFactory>();
            _universeEquityInterDayCache    = A.Fake <IUniverseEquityInterDayCache>();
            _universeDataRequestsSubscriber = A.Fake <IUniverseDataRequestsSubscriber>();

            A.CallTo(() => _universeMarketCacheFactory.BuildInterday(Engine.Rules.Rules.RuleRunMode.ValidationRun))
            .Returns(_universeEquityInterDayCache);

            _tradingHoursService     = A.Fake <IMarketTradingHoursService>();
            _operationRunRuleContext = A.Fake <ISystemProcessOperationRunRuleContext>();
            _logger = A.Fake <ILogger <HighMarketCapFilter> >();
        }
Esempio n. 19
0
        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>();
        }
Esempio n. 20
0
        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>();
        }
 public EquityRuleHighVolumeFactory(
     IUniverseEquityOrderFilterService orderFilterService,
     IUniverseEquityMarketCacheFactory equityFactory,
     IUniverseFixedIncomeMarketCacheFactory fixedIncomeFactory,
     IMarketTradingHoursService tradingHoursService,
     ICurrencyConverterService currencyConverterService,
     ILogger <IHighVolumeRule> logger,
     ILogger <TradingHistoryStack> tradingHistoryLogger)
 {
     this.orderFilterService       = orderFilterService ?? throw new ArgumentNullException(nameof(orderFilterService));
     this.equityFactory            = equityFactory ?? throw new ArgumentNullException(nameof(equityFactory));
     this.fixedIncomeFactory       = fixedIncomeFactory ?? throw new ArgumentNullException(nameof(fixedIncomeFactory));
     this.tradingHoursService      = tradingHoursService ?? throw new ArgumentNullException(nameof(tradingHoursService));
     this.currencyConverterService = currencyConverterService ?? throw new ArgumentNullException(nameof(currencyConverterService));
     this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
     this.tradingHistoryLogger = tradingHistoryLogger ?? throw new ArgumentNullException(nameof(tradingHistoryLogger));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FixedIncomeHighVolumeFactory"/> class.
 /// </summary>
 /// <param name="filterService">
 /// The filter service.
 /// </param>
 /// <param name="equityMarketCacheFactory">
 /// The market cache factory.
 /// </param>
 /// <param name="fixedIncomeMarketCacheFactory">
 /// The market cache factory.
 /// </param>
 /// <param name="logger">
 /// The logger.
 /// </param>
 /// <param name="tradingLogger">
 /// The trading logger.
 /// </param>
 /// <param name="marketTradingHoursService">
 /// The trading hours service.
 /// </param>
 public FixedIncomeHighVolumeFactory(
     IUniverseFixedIncomeOrderFilterService filterService,
     IUniverseEquityMarketCacheFactory equityMarketCacheFactory,
     IUniverseFixedIncomeMarketCacheFactory fixedIncomeMarketCacheFactory,
     ILogger <FixedIncomeHighVolumeRule> logger,
     ILogger <TradingHistoryStack> tradingLogger,
     IMarketTradingHoursService marketTradingHoursService)
 {
     this.filterService            = filterService ?? throw new ArgumentNullException(nameof(filterService));
     this.equityMarketCacheFactory =
         equityMarketCacheFactory ?? throw new ArgumentNullException(nameof(this.equityMarketCacheFactory));
     this.fixedIncomeMarketCacheFactory =
         fixedIncomeMarketCacheFactory ?? throw new ArgumentNullException(nameof(this.fixedIncomeMarketCacheFactory));
     this.marketTradingHoursService = marketTradingHoursService ?? throw new ArgumentNullException(nameof(marketTradingHoursService));
     this.logger        = logger ?? throw new ArgumentNullException(nameof(logger));
     this.tradingLogger = tradingLogger ?? throw new ArgumentNullException(nameof(tradingLogger));
 }
        public void RunRule_DoesNotRaiseAlertInEschaton_WhenBidirectionalTradeAndNoPriceMovementData()
        {
            var parameters = new LayeringRuleEquitiesParameters("id", TimeSpan.FromMinutes(30), null, null, true, null, false, true);

            _tradingHoursService = new MarketTradingHoursService(_tradingHoursRepository, new NullLogger <MarketTradingHoursService>());
            var rule      = new LayeringRule(parameters, _alertStream, _orderFilter, _logger, _equityFactory, _fixedIncomeFactory, _tradingHoursService, _ruleCtx, RuleRunMode.ValidationRun, _tradingLogger);
            var tradeBuy  = ((Order)null).Random();
            var tradeSell = ((Order)null).Random();

            tradeBuy.OrderDirection  = OrderDirections.BUY;
            tradeBuy.FilledDate      = tradeBuy.PlacedDate.Value.AddMinutes(1);
            tradeSell.OrderDirection = OrderDirections.SELL;
            tradeSell.FilledDate     = tradeSell.PlacedDate.Value.AddMinutes(1);

            tradeBuy.OrderFilledVolume  = 300;
            tradeSell.OrderFilledVolume = 5;

            tradeBuy.PlacedDate  = new DateTime(2018, 10, 14, 10, 30, 0);
            tradeSell.PlacedDate = tradeBuy.PlacedDate.Value.AddSeconds(30);

            var market       = new Market("1", "XLON", "London Stock Exchange", MarketTypes.STOCKEXCHANGE);
            var initialPrice = tradeBuy.OrderAverageFillPrice.Value.Value;
            var marketData5  = SetExchangeFrameToPrice(market, tradeBuy, tradeSell, initialPrice * 1.2m, tradeSell.PlacedDate.Value.AddSeconds(5));
            var marketData6  = SetExchangeFrameToPrice(market, tradeBuy, tradeSell, initialPrice * 1.25m, tradeSell.PlacedDate.Value.AddSeconds(10));


            var genesis   = new UniverseEvent(UniverseStateEvent.Genesis, tradeBuy.PlacedDate.Value.AddMinutes(-1), new object());
            var buyEvent  = new UniverseEvent(UniverseStateEvent.OrderPlaced, tradeBuy.PlacedDate.Value, tradeBuy);
            var sellEvent = new UniverseEvent(UniverseStateEvent.OrderPlaced, tradeSell.PlacedDate.Value, tradeSell);

            var marketDataEvent5 = new UniverseEvent(UniverseStateEvent.EquityIntraDayTick, marketData5.Epoch, marketData5);
            var marketDataEvent6 = new UniverseEvent(UniverseStateEvent.EquityIntraDayTick, marketData6.Epoch, marketData6);

            var eschaton = new UniverseEvent(UniverseStateEvent.Eschaton, tradeSell.PlacedDate.Value.AddMinutes(1), new object());

            rule.OnNext(genesis);
            rule.OnNext(buyEvent);
            rule.OnNext(sellEvent);
            rule.OnNext(marketDataEvent5);
            rule.OnNext(marketDataEvent6);
            rule.OnNext(eschaton);

            A.CallTo(() => _alertStream.Add(A <IUniverseAlertEvent> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => _ruleCtx.EndEvent()).MustHaveHappenedOnceExactly();
        }
 public EquityRuleMarkingTheCloseFactory(
     IUniverseEquityOrderFilterService orderFilterService,
     IUniverseEquityMarketCacheFactory equityFactory,
     IUniverseFixedIncomeMarketCacheFactory fixedIncomeFactory,
     IMarketTradingHoursService tradingHoursService,
     ILogger <MarkingTheCloseRule> logger,
     ILogger <TradingHistoryStack> tradingHistoryLogger)
 {
     this._orderFilterService =
         orderFilterService ?? throw new ArgumentNullException(nameof(orderFilterService));
     this._equityFactory       = equityFactory ?? throw new ArgumentNullException(nameof(equityFactory));
     this._fixedIncomeFactory  = fixedIncomeFactory ?? throw new ArgumentNullException(nameof(fixedIncomeFactory));
     this._tradingHoursService =
         tradingHoursService ?? throw new ArgumentNullException(nameof(tradingHoursService));
     this._logger = logger ?? throw new ArgumentNullException(nameof(logger));
     this._tradingHistoryLogger =
         tradingHistoryLogger ?? throw new ArgumentNullException(nameof(tradingHistoryLogger));
 }
        public void Setup()
        {
            _logger             = A.Fake <ILogger>();
            _tradingLogger      = A.Fake <ILogger <TradingHistoryStack> >();
            _alertStream        = A.Fake <IUniverseAlertStream>();
            _ruleCtx            = A.Fake <ISystemProcessOperationRunRuleContext>();
            _operationCtx       = A.Fake <ISystemProcessOperationContext>();
            _equitiesParameters = new LayeringRuleEquitiesParameters("id", TimeSpan.FromMinutes(30), 0.2m, null, null, null, false, true);

            _orderFilter = A.Fake <IUniverseOrderFilter>();
            A.CallTo(() => _orderFilter.Filter(A <IUniverseEvent> .Ignored)).ReturnsLazily(i => (IUniverseEvent)i.Arguments[0]);

            _ruleRunRepository        = A.Fake <IRuleRunDataRequestRepository>();
            _stubRuleRunRepository    = A.Fake <IStubRuleRunDataRequestRepository>();
            _equityFactoryLogger      = A.Fake <ILogger <UniverseEquityMarketCacheFactory> >();
            _equityFactory            = new UniverseEquityMarketCacheFactory(_stubRuleRunRepository, _ruleRunRepository, _equityFactoryLogger);
            _fixedIncomeFactoryLogger = A.Fake <ILogger <UniverseFixedIncomeMarketCacheFactory> >();
            _fixedIncomeFactory       = new UniverseFixedIncomeMarketCacheFactory(_stubRuleRunRepository, _ruleRunRepository, _fixedIncomeFactoryLogger);
            _tradingHoursService      = A.Fake <IMarketTradingHoursService>();

            _tradingHoursRepository = A.Fake <IMarketOpenCloseApiCachingDecorator>();
            A.CallTo(() => _tradingHoursRepository.GetAsync())
            .Returns(
                new ExchangeDto[]
            {
                new ExchangeDto
                {
                    Code              = "XLON",
                    MarketOpenTime    = TimeSpan.FromHours(8),
                    MarketCloseTime   = TimeSpan.FromHours(16),
                    IsOpenOnMonday    = true,
                    IsOpenOnTuesday   = true,
                    IsOpenOnWednesday = true,
                    IsOpenOnThursday  = true,
                    IsOpenOnFriday    = true,
                    IsOpenOnSaturday  = true,
                    IsOpenOnSunday    = true,
                }
            });

            A.CallTo(() => _ruleCtx.EndEvent()).Returns(_operationCtx);
        }
 public HighVolumeVenueDecoratorFilterFactory(
     IUniverseEquityOrderFilterService equityOrderFilterService,
     IUniverseEquityMarketCacheFactory equityMarketCacheFactory,
     IUniverseFixedIncomeMarketCacheFactory fixedIncomeMarketCacheFactory,
     IMarketTradingHoursService marketTradingHoursService,
     ILogger <TradingHistoryStack> tradingHistoryLogger,
     ILogger <HighVolumeVenueFilter> venueLogger)
 {
     this._equityOrderFilterService = equityOrderFilterService
                                      ?? throw new ArgumentNullException(nameof(equityOrderFilterService));
     this._equityMarketCacheFactory = equityMarketCacheFactory
                                      ?? throw new ArgumentNullException(nameof(equityMarketCacheFactory));
     this._fixedIncomeMarketCacheFactory = fixedIncomeMarketCacheFactory
                                           ?? throw new ArgumentNullException(nameof(fixedIncomeMarketCacheFactory));
     this._marketTradingHoursService = marketTradingHoursService
                                       ?? throw new ArgumentNullException(nameof(marketTradingHoursService));
     this._tradingHistoryLogger =
         tradingHistoryLogger ?? throw new ArgumentNullException(nameof(tradingHistoryLogger));
     this._venueLogger = venueLogger ?? throw new ArgumentNullException(nameof(venueLogger));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="HighVolumeVenueFilter"/> class.
 /// </summary>
 /// <param name="timeWindows">
 /// The time windows.
 /// </param>
 /// <param name="decimalRangeRuleFilter">
 /// The decimal range rule filter.
 /// </param>
 /// <param name="universeOrderFilter">
 /// The universe order filter.
 /// </param>
 /// <param name="runRuleContext">
 /// The run rule context.
 /// </param>
 /// <param name="equityMarketCacheFactory">
 /// The universe market cache factory.
 /// </param>
 /// <param name="fixedIncomeMarketCacheFactory">
 /// The universe market cache factory.
 /// </param>
 /// <param name="ruleRunMode">
 /// The rule run mode.
 /// </param>
 /// <param name="marketTradingHoursService">
 /// The market trading hours service.
 /// </param>
 /// <param name="dataRequestsSubscriber">
 /// The data requests subscriber.
 /// </param>
 /// <param name="source">
 /// The source.
 /// </param>
 /// <param name="stackLogger">
 /// The stack logger.
 /// </param>
 /// <param name="logger">
 /// The logger.
 /// </param>
 public HighVolumeVenueFilter(
     TimeWindows timeWindows,
     DecimalRangeRuleFilter decimalRangeRuleFilter,
     IUniverseOrderFilter universeOrderFilter,
     ISystemProcessOperationRunRuleContext runRuleContext,
     IUniverseEquityMarketCacheFactory equityMarketCacheFactory,
     IUniverseFixedIncomeMarketCacheFactory fixedIncomeMarketCacheFactory,
     RuleRunMode ruleRunMode,
     IMarketTradingHoursService marketTradingHoursService,
     IUniverseDataRequestsSubscriber dataRequestsSubscriber,
     DataSource source,
     ILogger <TradingHistoryStack> stackLogger,
     ILogger <HighVolumeVenueFilter> logger)
     : base(
         timeWindows.BackwardWindowSize,
         timeWindows.BackwardWindowSize,
         timeWindows.FutureWindowSize,
         Domain.Surveillance.Scheduling.Rules.UniverseFilter,
         Versioner.Version(1, 0),
         nameof(HighVolumeVenueFilter),
         runRuleContext,
         equityMarketCacheFactory,
         fixedIncomeMarketCacheFactory,
         ruleRunMode,
         logger,
         stackLogger)
 {
     this.eventExpiration        = this.TradeBackwardWindowSize + this.TradeBackwardWindowSize + TimeSpan.FromDays(3);
     this.tradingHoursService    = marketTradingHoursService ?? throw new ArgumentNullException(nameof(marketTradingHoursService));
     this.decimalRangeRuleFilter = decimalRangeRuleFilter ?? DecimalRangeRuleFilter.None();
     this.orderFilter            = universeOrderFilter ?? throw new ArgumentNullException(nameof(universeOrderFilter));
     this.dataRequestSubscriber  = dataRequestsSubscriber ?? throw new ArgumentNullException(nameof(dataRequestsSubscriber));
     this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
     this.UniverseEventsPassedFilter = new HashSet <Order>();
     this.source = source;
 }
Esempio n. 28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RampingRule"/> class.
 /// </summary>
 /// <param name="rampingParameters">
 /// The ramping parameters.
 /// </param>
 /// <param name="alertStream">
 /// The alert stream.
 /// </param>
 /// <param name="ruleContext">
 /// The rule context.
 /// </param>
 /// <param name="equityFactory">
 /// The factory.
 /// </param>
 /// <param name="fixedIncomeFactory">
 /// The factory.
 /// </param>
 /// <param name="orderFilter">
 /// The order filter.
 /// </param>
 /// <param name="runMode">
 /// The run mode.
 /// </param>
 /// <param name="rampingAnalyzer">
 /// The ramping analyzer.
 /// </param>
 /// <param name="tradingHoursService">
 /// The trading hours service.
 /// </param>
 /// <param name="dataRequestSubscriber">
 /// The data request subscriber.
 /// </param>
 /// <param name="logger">
 /// The logger.
 /// </param>
 /// <param name="tradingStackLogger">
 /// The trading stack logger.
 /// </param>
 public RampingRule(
     IRampingRuleEquitiesParameters rampingParameters,
     IUniverseAlertStream alertStream,
     ISystemProcessOperationRunRuleContext ruleContext,
     IUniverseEquityMarketCacheFactory equityFactory,
     IUniverseFixedIncomeMarketCacheFactory fixedIncomeFactory,
     IUniverseOrderFilter orderFilter,
     RuleRunMode runMode,
     IRampingAnalyser rampingAnalyzer,
     IMarketTradingHoursService tradingHoursService,
     IUniverseDataRequestsSubscriber dataRequestSubscriber,
     ILogger logger,
     ILogger <TradingHistoryStack> tradingStackLogger)
     : base(
         rampingParameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromDays(7),
         TimeSpan.FromDays(30),
         rampingParameters?.Windows?.FutureWindowSize ?? TimeSpan.Zero,
         Domain.Surveillance.Scheduling.Rules.Ramping,
         EquityRuleRampingFactory.Version,
         "Ramping Rule",
         ruleContext,
         equityFactory,
         fixedIncomeFactory,
         runMode,
         logger,
         tradingStackLogger)
 {
     this.rampingParameters     = rampingParameters ?? throw new ArgumentNullException(nameof(rampingParameters));
     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.rampingAnalyzer       = rampingAnalyzer ?? throw new ArgumentNullException(nameof(rampingAnalyzer));
     this.logger                = logger ?? throw new ArgumentNullException(nameof(logger));
     this.tradingHoursService   = tradingHoursService ?? throw new ArgumentNullException(nameof(tradingHoursService));
     this.dataRequestSubscriber = dataRequestSubscriber ?? throw new ArgumentNullException(nameof(dataRequestSubscriber));
 }
        /// <summary>
        /// The test setup.
        /// </summary>
        private void Setup()
        {
            this.tradingHoursService = A.Fake <IMarketTradingHoursService>();

            A.CallTo(() => this.tradingHoursService.GetTradingHoursForMic("XLON")).Returns(
                new TradingHours
            {
                CloseOffsetInUtc = TimeSpan.FromHours(16),
                IsValid          = true,
                Mic             = "XLON",
                OpenOffsetInUtc = TimeSpan.FromHours(8)
            });

            A.CallTo(() => this.tradingHoursService.GetTradingHoursForMic("NASDAQ")).Returns(
                new TradingHours
            {
                CloseOffsetInUtc = TimeSpan.FromHours(23),
                IsValid          = true,
                Mic             = "NASDAQ",
                OpenOffsetInUtc = TimeSpan.FromHours(15)
            });

            this.equityMarketCacheFactory = new UniverseEquityMarketCacheFactory(
                new StubRuleRunDataRequestRepository(),
                new StubRuleRunDataRequestRepository(),
                new NullLogger <UniverseEquityMarketCacheFactory>());

            this.fixedIncomeMarketCacheFactory = new UniverseFixedIncomeMarketCacheFactory(
                new StubRuleRunDataRequestRepository(),
                new StubRuleRunDataRequestRepository(),
                new NullLogger <UniverseFixedIncomeMarketCacheFactory>());

            this.universeOrderFilterService = A.Fake <IUniverseEquityOrderFilterService>();
            this.logger                = new NullLogger <HighProfitsRule>();
            this.tradingLogger         = new NullLogger <TradingHistoryStack>();
            this.ruleContext           = A.Fake <ISystemProcessOperationRunRuleContext>();
            this.dataRequestSubscriber = A.Fake <IUniverseDataRequestsSubscriber>();

            this.exchangeRateProfitCalculator   = A.Fake <IExchangeRateProfitCalculator>();
            this.marketDataCacheStrategyFactory = new EquityMarketDataCacheStrategyFactory();

            this.costCalculatorFactory = new CostCalculatorFactory(
                new CurrencyConverterService(
                    this.exchangeRateSelection.ExchangeRateRepository,
                    new NullLogger <CurrencyConverterService>()),
                new NullLogger <CostCalculator>(),
                new NullLogger <CostCurrencyConvertingCalculator>());

            this.revenueCalculatorFactory = new RevenueCalculatorFactory(
                this.tradingHoursService,
                new CurrencyConverterService(
                    this.exchangeRateSelection.ExchangeRateRepository,
                    new NullLogger <CurrencyConverterService>()),
                new NullLogger <RevenueCurrencyConvertingCalculator>(),
                new NullLogger <RevenueCalculator>());

            this.equityRuleHighProfitFactory = new EquityRuleHighProfitFactory(
                this.costCalculatorFactory,
                this.revenueCalculatorFactory,
                this.exchangeRateProfitCalculator,
                this.universeOrderFilterService,
                this.equityMarketCacheFactory,
                this.fixedIncomeMarketCacheFactory,
                this.marketDataCacheStrategyFactory,
                new CurrencyConverterService(
                    this.exchangeRateSelection.ExchangeRateRepository,
                    new NullLogger <CurrencyConverterService>()),
                this.logger,
                this.tradingLogger);

            this.judgementRepository  = A.Fake <IJudgementRepository>();
            this.ruleViolationService = A.Fake <IRuleViolationService>();

            this.judgementService = new JudgementService(
                this.judgementRepository,
                this.ruleViolationService,
                new HighProfitJudgementMapper(new NullLogger <HighProfitJudgementMapper>()),
                new FixedIncomeHighProfitJudgementMapper(new NullLogger <FixedIncomeHighProfitJudgementMapper>()),
                new FixedIncomeHighVolumeJudgementMapper(new NullLogger <FixedIncomeHighVolumeJudgementMapper>()),
                new NullLogger <JudgementService>());

            this.exchangeRateProfitCalculator   = A.Fake <IExchangeRateProfitCalculator>();
            this.marketDataCacheStrategyFactory = new EquityMarketDataCacheStrategyFactory();
        }
        public HighVolumeSteps(ScenarioContext scenarioContext, UniverseSelectionState universeSelectionState)
        {
            _scenarioContext        = scenarioContext;
            _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 = 0.02d
            };

            var exchangeRateDtoJpy = new ExchangeRateDto
            {
                DateTime         = new DateTime(2018, 01, 01),
                Name             = "USD/JPY",
                FixedCurrency    = "USD",
                VariableCurrency = "JPY",
                Rate             = 100
            };

            var exchangeRateDtoGbx = new ExchangeRateDto
            {
                DateTime         = new DateTime(2018, 01, 01),
                Name             = "GBX/GBX",
                FixedCurrency    = "GBX",
                VariableCurrency = "GBX",
                Rate             = 1
            };

            A.CallTo(() =>
                     exchangeRateApiRepository.GetAsync(A <DateTime> .Ignored, A <DateTime> .Ignored))
            .Returns(new Dictionary <DateTime, IReadOnlyCollection <ExchangeRateDto> >
            {
                { new DateTime(2018, 01, 01), new ExchangeRateDto[]
                  {
                      exchangeRateDto,
                      exchangeRateDtoJpy,
                      exchangeRateDtoGbx
                  } }
            });

            var repository = A.Fake <IMarketOpenCloseApiCachingDecorator>();

            A
            .CallTo(() => repository.GetAsync()).
            Returns(new ExchangeDto[]
            {
                new ExchangeDto
                {
                    Code              = "XLON",
                    MarketOpenTime    = TimeSpan.FromHours(8),
                    MarketCloseTime   = TimeSpan.FromHours(16),
                    IsOpenOnMonday    = true,
                    IsOpenOnTuesday   = true,
                    IsOpenOnWednesday = true,
                    IsOpenOnThursday  = true,
                    IsOpenOnFriday    = true,
                    IsOpenOnSaturday  = true,
                    IsOpenOnSunday    = true,
                },

                new ExchangeDto
                {
                    Code              = "NASDAQ",
                    MarketOpenTime    = TimeSpan.FromHours(15),
                    MarketCloseTime   = TimeSpan.FromHours(23),
                    IsOpenOnMonday    = true,
                    IsOpenOnTuesday   = true,
                    IsOpenOnWednesday = true,
                    IsOpenOnThursday  = true,
                    IsOpenOnFriday    = true,
                    IsOpenOnSaturday  = true,
                    IsOpenOnSunday    = true,
                }
            });

            _tradingHoursService = new MarketTradingHoursService(repository, new NullLogger <MarketTradingHoursService>());

            _equityMarketCacheFactory = new UniverseEquityMarketCacheFactory(
                new StubRuleRunDataRequestRepository(),
                new StubRuleRunDataRequestRepository(),
                new NullLogger <UniverseEquityMarketCacheFactory>());

            _fixedIncomeMarketCacheFactory = new UniverseFixedIncomeMarketCacheFactory(
                new StubRuleRunDataRequestRepository(),
                new StubRuleRunDataRequestRepository(),
                new NullLogger <UniverseFixedIncomeMarketCacheFactory>());

            var currencyLogger = new NullLogger <CurrencyConverterService>();

            currencyConverterService    = new CurrencyConverterService(exchangeRateApiRepository, currencyLogger);
            _universeOrderFilterService = A.Fake <IUniverseEquityOrderFilterService>();
            _logger                      = new NullLogger <HighVolumeRule>();
            _tradingLogger               = new NullLogger <TradingHistoryStack>();
            _ruleCtx                     = A.Fake <ISystemProcessOperationRunRuleContext>();
            _alertStream                 = A.Fake <IUniverseAlertStream>();
            _dataRequestSubscriber       = A.Fake <IUniverseDataRequestsSubscriber>();
            _equityRuleHighVolumeFactory = new EquityRuleHighVolumeFactory(
                _universeOrderFilterService,
                _equityMarketCacheFactory,
                _fixedIncomeMarketCacheFactory,
                _tradingHoursService,
                this.currencyConverterService,
                _logger,
                _tradingLogger);
        }