/// <summary>
        /// The run post order event.
        /// </summary>
        /// <param name="history">
        /// The history.
        /// </param>
        protected override void RunPostOrderEvent(ITradingHistoryStack history)
        {
            var activeTrades = history.ActiveTradeHistory();

            if (!activeTrades.Any())
            {
                return;
            }

            var liveTrades = this.FilterByClientAccount(
                history.ActiveTradeHistory().Pop(),
                history.ActiveTradeHistory());

            if (!liveTrades?.Any() ?? true)
            {
                return;
            }

            var tradePosition = new TradePosition(
                this.FilterByClientAccount(history.ActiveTradeHistory().Pop(), history.ActiveTradeHistory()));

            // Net change analysis
            var averagePositionCheckTask = this.NettingTrades(liveTrades);

            averagePositionCheckTask.Wait();
            var averagePositionCheck = averagePositionCheckTask.Result;

            // Clustering trade analysis
            var clusteringPositionCheck = this.ClusteringTrades(liveTrades);

            if ((averagePositionCheck == null || !averagePositionCheck.AveragePositionRuleBreach) &&
                (clusteringPositionCheck == null || !clusteringPositionCheck.ClusteringPositionBreach))
            {
                return;
            }

            var security = liveTrades?.FirstOrDefault()?.Instrument;

            this.logger.LogInformation(
                $"incrementing alerts because of security {security?.Name} at {this.UniverseDateTime}");

            // wrong but should be a judgement anyway
            var breach = new WashTradeRuleBreach(
                this.equitiesParameters.Windows.BackwardWindowSize,
                this.OrganisationFactorValue,
                this.RuleCtx.SystemProcessOperationContext(),
                this.RuleCtx.CorrelationId(),
                this.equitiesParameters,
                tradePosition,
                security,
                averagePositionCheck,
                clusteringPositionCheck,
                null,
                null,
                this.UniverseDateTime);

            var universeAlert = new UniverseAlertEvent(Rules.WashTrade, breach, this.RuleCtx);

            this.alertStream.Add(universeAlert);
        }
Esempio n. 2
0
        /// <summary>
        /// The run post order event.
        /// </summary>
        /// <param name="history">
        /// The history.
        /// </param>
        protected override void RunPostOrderEvent(ITradingHistoryStack history)
        {
            this.logger.LogInformation($"RunPostOrderEvent called at {this.UniverseDateTime}");

            var filteredOrders = this.FilterByClientAccount(
                history.ActiveTradeHistory().Any() ? history.ActiveTradeHistory().Peek() : null,
                history.ActiveTradeHistory().ToList());

            var clusteringAnalysis     = this.ClusteringAnalysis(filteredOrders);
            var averageNettingAnalysis = this.NettingTrades(filteredOrders);

            if ((clusteringAnalysis == null || !clusteringAnalysis.ClusteringPositionBreach) &&
                (averageNettingAnalysis == null || !averageNettingAnalysis.AveragePositionRuleBreach))
            {
                return;
            }

            var security = filteredOrders?.FirstOrDefault()?.Instrument;

            // wrong but should be a judgement anyway
            var breach = new WashTradeRuleBreach(
                this.parameters.Windows.BackwardWindowSize,
                this.OrganisationFactorValue,
                this.RuleCtx.SystemProcessOperationContext(),
                this.RuleCtx.CorrelationId(),
                this.parameters,
                new TradePosition(filteredOrders),
                security,
                averageNettingAnalysis,
                clusteringAnalysis,
                null,
                null,
                this.UniverseDateTime);

            var universeAlert = new UniverseAlertEvent(Rules.FixedIncomeWashTrades, breach, this.RuleCtx);

            this.alertStream.Add(universeAlert);

            this.logger.LogInformation($"RunPostOrderEvent completed for {this.UniverseDateTime}");
        }