private CancelledOrderRule BuildRule(CancelledOrderRuleEquitiesParameters parameters = null)
        {
            if (parameters == null)
            {
                parameters = new CancelledOrderRuleEquitiesParameters(
                    "id",
                    TimeSpan.FromMinutes(30),
                    0.5m,
                    null,
                    10,
                    10,
                    null,
                    false,
                    true);
            }

            var orderRule = new CancelledOrderRule(
                parameters,
                this._ruleCtx,
                this._alertStream,
                this._orderFilter,
                this.BuildEquityFactory(),
                this.BuildFixedIncomeFactory(),
                RuleRunMode.ValidationRun,
                this._logger,
                this._tradingHistoryLogger);

            return(orderRule);
        }
        public void OnNext_SendsExpectedMessage_ForTradeCountRuleBreach_WithNoMax()
        {
            var cancelledOrdersByTradeSize = new List <Order>
            {
                this.OrderFactory(OrderStatus.Cancelled),
                this.OrderFactory(OrderStatus.Cancelled),
                this.OrderFactory(OrderStatus.Cancelled),
                this.OrderFactory(OrderStatus.Cancelled),
                this.OrderFactory(OrderStatus.Filled),
                this.OrderFactory(OrderStatus.Filled),
                this.OrderFactory(OrderStatus.Filled),
                this.OrderFactory(OrderStatus.Filled),
                this.OrderFactory(OrderStatus.Filled),
                this.OrderFactory(OrderStatus.Filled),
                this.OrderFactory(OrderStatus.Filled),
                this.OrderFactory(OrderStatus.Filled),
                this.OrderFactory(OrderStatus.Filled),
                this.OrderFactory(OrderStatus.Filled),
                this.OrderFactory(OrderStatus.Filled),
                this.OrderFactory(OrderStatus.Filled),
                this.OrderFactory(OrderStatus.Filled),
                this.OrderFactory(OrderStatus.Filled),
                this.OrderFactory(OrderStatus.Filled),
                this.OrderFactory(OrderStatus.Filled)
            };

            var parameters = new CancelledOrderRuleEquitiesParameters(
                "id",
                TimeSpan.FromMinutes(30),
                null,
                0.3m,
                3,
                null,
                null,
                false,
                true);

            var orderRule = new CancelledOrderRule(
                parameters,
                this._ruleCtx,
                this._alertStream,
                this._orderFilter,
                this.BuildEquityFactory(),
                this.BuildFixedIncomeFactory(),
                RuleRunMode.ValidationRun,
                this._logger,
                this._tradingHistoryLogger);

            var universeEvents =
                cancelledOrdersByTradeSize.Select(x => new UniverseEvent(UniverseStateEvent.Order, DateTime.UtcNow, x));

            foreach (var order in universeEvents)
            {
                orderRule.OnNext(order);
            }

            A.CallTo(() => this._alertStream.Add(A <IUniverseAlertEvent> .Ignored))
            .MustHaveHappenedANumberOfTimesMatching(x => x == 11);
        }
        public void OnNext_DoesNotSendsMessage_ForNoTradeCountRuleBreach()
        {
            var trade = this.OrderFactory(OrderStatus.Cancelled);

            trade.OrderFilledVolume = trade.OrderFilledVolume * 100;

            var cancelledOrdersByTradeSize = new List <Order>
            {
                trade,
                this.OrderFactory(OrderStatus.Filled),
                this.OrderFactory(OrderStatus.Filled),
                this.OrderFactory(OrderStatus.Filled),
                this.OrderFactory(OrderStatus.Filled),
                this.OrderFactory(OrderStatus.Filled),
                this.OrderFactory(OrderStatus.Filled),
                this.OrderFactory(OrderStatus.Filled),
                this.OrderFactory(OrderStatus.Filled),
                this.OrderFactory(OrderStatus.Filled)
            };

            var parameters = new CancelledOrderRuleEquitiesParameters(
                "id",
                TimeSpan.FromMinutes(30),
                null,
                0.70m,
                3,
                10,
                null,
                false,
                true);

            var orderRule = new CancelledOrderRule(
                parameters,
                this._ruleCtx,
                this._alertStream,
                this._orderFilter,
                this.BuildEquityFactory(),
                this.BuildFixedIncomeFactory(),
                RuleRunMode.ValidationRun,
                this._logger,
                this._tradingHistoryLogger);

            var universeEvents =
                cancelledOrdersByTradeSize.Select(x => new UniverseEvent(UniverseStateEvent.Order, DateTime.UtcNow, x));

            foreach (var order in universeEvents)
            {
                orderRule.OnNext(order);
            }

            A.CallTo(() => this._alertStream.Add(A <IUniverseAlertEvent> .Ignored)).MustNotHaveHappened();
        }