コード例 #1
0
        /// <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);
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
        /// <summary>
        /// The subscribe to universe.
        /// </summary>
        /// <param name="execution">
        /// The execution.
        /// </param>
        /// <param name="operationContext">
        /// The operation context.
        /// </param>
        /// <param name="dataRequestSubscriber">
        /// The data request subscriber.
        /// </param>
        /// <param name="highProfitParameters">
        /// The high profit parameters.
        /// </param>
        /// <param name="judgementService">
        /// The judgement service.
        /// </param>
        /// <returns>
        /// The <see cref="IUniverseRule"/>.
        /// </returns>
        private IReadOnlyCollection <IUniverseRule> SubscribeToUniverse(
            ScheduledExecution execution,
            ISystemProcessOperationContext operationContext,
            IUniverseDataRequestsSubscriber dataRequestSubscriber,
            IReadOnlyCollection <IHighProfitsRuleFixedIncomeParameters> highProfitParameters,
            IJudgementService judgementService)
        {
            var subscriptions = new List <IUniverseRule>();

            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            if (highProfitParameters != null && highProfitParameters.Any())
            {
                foreach (var param in highProfitParameters)
                {
                    var paramSubscriptions = this.SubscribeToParameters(
                        execution,
                        operationContext,
                        dataRequestSubscriber,
                        param,
                        judgementService);
                    subscriptions.Add(paramSubscriptions);
                }
            }
            else
            {
                var errorMessage =
                    $"tried to schedule a {nameof(FixedIncomeHighProfitsRule)} rule execution with no parameters set";
                this.logger.LogError(errorMessage);
                operationContext.EventError(errorMessage);
            }

            return(subscriptions);
        }
        /// <summary>
        /// The subscribe to universe.
        /// </summary>
        /// <param name="execution">
        /// The execution.
        /// </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="highProfitParameters">
        /// The high profit parameters.
        /// </param>
        /// <returns>
        /// The <see cref="IUniverseRule"/>.
        /// </returns>
        private IReadOnlyCollection <IUniverseRule> SubscribeToUniverse(
            ScheduledExecution execution,
            ISystemProcessOperationContext operationContext,
            IUniverseDataRequestsSubscriber dataRequestSubscriber,
            IJudgementService judgementService,
            IReadOnlyCollection <IHighProfitsRuleEquitiesParameters> highProfitParameters)
        {
            var subscriptions = new List <IUniverseRule>();

            if (highProfitParameters != null && highProfitParameters.Any())
            {
                foreach (var param in highProfitParameters)
                {
                    var cloneableRule = this.SubscribeParameters(
                        execution,
                        operationContext,
                        dataRequestSubscriber,
                        judgementService,
                        param);

                    subscriptions.Add(cloneableRule);
                }
            }
            else
            {
                const string ErrorMessage = "tried to schedule a high profit rule execution with no parameters set";
                this.logger.LogError(ErrorMessage);
                operationContext.EventError(ErrorMessage);
            }

            return(subscriptions);
        }
        /// <summary>
        /// The subscribe parameters.
        /// </summary>
        /// <param name="execution">
        /// The execution.
        /// </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="parameter">
        /// The parameter.
        /// </param>
        /// <returns>
        /// The <see cref="IUniverseRule"/>.
        /// </returns>
        private IUniverseRule SubscribeParameters(
            ScheduledExecution execution,
            ISystemProcessOperationContext operationContext,
            IUniverseDataRequestsSubscriber dataRequestSubscriber,
            IJudgementService judgementService,
            IHighProfitsRuleEquitiesParameters parameter)
        {
            var ruleCtxStream = operationContext.CreateAndStartRuleRunContext(
                Rules.HighProfits.GetDescription(),
                EquityRuleHighProfitFactory.Version,
                parameter.Id,
                (int)Rules.HighProfits,
                execution.IsBackTest,
                execution.TimeSeriesInitiation.DateTime,
                execution.TimeSeriesTermination.DateTime,
                execution.CorrelationId,
                execution.IsForceRerun);

            var ruleCtxMarketClosure = operationContext.CreateAndStartRuleRunContext(
                Rules.HighProfits.GetDescription(),
                EquityRuleHighProfitFactory.Version,
                parameter.Id,
                (int)Rules.HighProfits,
                execution.IsBackTest,
                execution.TimeSeriesInitiation.DateTime,
                execution.TimeSeriesTermination.DateTime,
                execution.CorrelationId,
                execution.IsForceRerun);

            var highProfitsRule = this.equityRuleHighProfitFactory.Build(
                parameter,
                ruleCtxStream,
                ruleCtxMarketClosure,
                dataRequestSubscriber,
                judgementService,
                execution);

            var highProfitsRuleOrgFactor = this.brokerServiceFactory.Build(
                highProfitsRule,
                parameter.Factors,
                parameter.AggregateNonFactorableIntoOwnCategory);

            var runMode = execution.IsForceRerun ? RuleRunMode.ForceRun : RuleRunMode.ValidationRun;
            var decoratedHighProfits = this.DecorateWithFilter(
                operationContext,
                parameter,
                highProfitsRuleOrgFactor,
                dataRequestSubscriber,
                ruleCtxMarketClosure,
                runMode);

            return(decoratedHighProfits);
        }
        public IHighProfitRule Build(
            IHighProfitsRuleEquitiesParameters equitiesParameters,
            ISystemProcessOperationRunRuleContext ruleCtxStream,
            ISystemProcessOperationRunRuleContext ruleCtxMarket,
            IUniverseDataRequestsSubscriber dataRequestSubscriber,
            IJudgementService judgementService,
            ScheduledExecution scheduledExecution)
        {
            var runMode = scheduledExecution.IsForceRerun ? RuleRunMode.ForceRun : RuleRunMode.ValidationRun;

            var stream = new HighProfitStreamRule(
                equitiesParameters,
                ruleCtxStream,
                this._costCalculatorFactory,
                this._revenueCalculatorFactory,
                this._exchangeRateProfitCalculator,
                this._orderFilterService,
                this._equityMarketCacheFactory,
                this._fixedIncomeMarketCacheFactory,
                this._cacheStrategyFactory,
                dataRequestSubscriber,
                judgementService,
                this._currencyConversionService,
                runMode,
                this._logger,
                this._tradingHistoryLogger);

            var marketClosure = new HighProfitMarketClosureRule(
                equitiesParameters,
                ruleCtxMarket,
                this._costCalculatorFactory,
                this._revenueCalculatorFactory,
                this._exchangeRateProfitCalculator,
                this._orderFilterService,
                this._equityMarketCacheFactory,
                this._fixedIncomeMarketCacheFactory,
                this._cacheStrategyFactory,
                dataRequestSubscriber,
                judgementService,
                this._currencyConversionService,
                runMode,
                this._logger,
                this._tradingHistoryLogger);

            return(new HighProfitsRule(equitiesParameters, stream, marketClosure, this._logger));
        }
コード例 #8
0
ファイル: GameService.cs プロジェクト: brian880120/gomoku-tek
 public GameService(
     GameContext context,
     ISocketService socket,
     IJudgementService judgement,
     IAlphaBetaAlgorithm alphaBetaAlgorithm,
     IEngine engine,
     IDataAdapter adapter,
     IConfigurationRoot config)
 {
     _context            = context;
     _socket             = socket;
     _judgement          = judgement;
     _alphaBetaAlgorithm = alphaBetaAlgorithm;
     _engine             = engine;
     _adapter            = adapter;
     _config             = config;
 }
コード例 #9
0
        /// <summary>
        /// The subscribe to parameters.
        /// </summary>
        /// <param name="execution">
        /// The execution.
        /// </param>
        /// <param name="operationContext">
        /// The operation context.
        /// </param>
        /// <param name="universeDataRequestsSubscriber">
        /// The universe data requests subscriber.
        /// </param>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        /// <param name="judgementService">
        /// The judgement service.
        /// </param>
        /// <returns>
        /// The <see cref="IUniverseRule"/>.
        /// </returns>
        private IUniverseRule SubscribeToParameters(
            ScheduledExecution execution,
            ISystemProcessOperationContext operationContext,
            IUniverseDataRequestsSubscriber universeDataRequestsSubscriber,
            IHighProfitsRuleFixedIncomeParameters parameters,
            IJudgementService judgementService)
        {
            var ruleCtx = operationContext.CreateAndStartRuleRunContext(
                Rules.FixedIncomeHighProfits.GetDescription(),
                FixedIncomeHighProfitFactory.Version,
                parameters.Id,
                (int)Rules.FixedIncomeHighProfits,
                execution.IsBackTest,
                execution.TimeSeriesInitiation.DateTime,
                execution.TimeSeriesTermination.DateTime,
                execution.CorrelationId,
                execution.IsForceRerun);

            var runMode = execution.IsForceRerun ? RuleRunMode.ForceRun : RuleRunMode.ValidationRun;

            var highProfits =
                this.fixedIncomeRuleHighProfitsFactory.BuildRule(
                    parameters,
                    ruleCtx,
                    judgementService,
                    universeDataRequestsSubscriber,
                    runMode,
                    execution);

            var highProfitsOrgFactors = this.brokerServiceFactory.Build(
                highProfits,
                parameters.Factors,
                parameters.AggregateNonFactorableIntoOwnCategory);

            var highProfitsFiltered = this.DecorateWithFilters(
                operationContext,
                parameters,
                highProfitsOrgFactors,
                universeDataRequestsSubscriber,
                ruleCtx,
                runMode);

            return(highProfitsFiltered);
        }
コード例 #10
0
        public void Setup()
        {
            this._orderFilterService            = A.Fake <IUniverseEquityOrderFilterService>();
            this._costCalculatorFactory         = A.Fake <ICostCalculatorFactory>();
            this._revenueCalculatorFactory      = A.Fake <IRevenueCalculatorFactory>();
            this._exchangeRateProfitCalculator  = A.Fake <IExchangeRateProfitCalculator>();
            this._equityMarketCacheFactory      = A.Fake <IUniverseEquityMarketCacheFactory>();
            this._fixedIncomeMarketCacheFactory = A.Fake <IUniverseFixedIncomeMarketCacheFactory>();
            this._cacheStrategyFactory          = A.Fake <IEquityMarketDataCacheStrategyFactory>();
            this._judgementService         = A.Fake <IJudgementService>();
            this._logger                   = new NullLogger <HighProfitsRule>();
            this._tradingHistoryLogger     = new NullLogger <TradingHistoryStack>();
            this._currencyConverterService = A.Fake <ICurrencyConverterService>();

            this._equitiesParameters    = A.Fake <IHighProfitsRuleEquitiesParameters>();
            this._ruleCtxStream         = A.Fake <ISystemProcessOperationRunRuleContext>();
            this._ruleCtxMarket         = A.Fake <ISystemProcessOperationRunRuleContext>();
            this._dataRequestSubscriber = A.Fake <IUniverseDataRequestsSubscriber>();
            this._scheduledExecution    = new ScheduledExecution();
        }
コード例 #11
0
        /// <summary>
        /// The subscribe rules.
        /// </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>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public async Task <IUniverseRuleSubscriptionSummary> SubscribeRules(
            ScheduledExecution execution,
            IUniversePlayer player,
            IUniverseAlertStream alertStream,
            IUniverseDataRequestsSubscriber dataRequestSubscriber,
            IJudgementService judgementService,
            ISystemProcessOperationContext operationContext,
            RuleParameterDto ruleParameters)
        {
            if (execution == null || player == null)
            {
                this.logger.LogInformation("received null execution or player. Returning");

                return(new UniverseRuleSubscriptionSummary(null, null));
            }

            var subscriptions = this.BuildSubscriptions(
                execution,
                player,
                alertStream,
                dataRequestSubscriber,
                judgementService,
                operationContext,
                ruleParameters,
                this.highVolumeEquitySubscriber.CollateSubscriptions,
                this.washTradeEquitySubscriber.CollateSubscriptions,
                this.highProfitEquitySubscriber.CollateSubscriptions,
                this.cancelledOrderEquitySubscriber.CollateSubscriptions,
                this.markingTheCloseEquitySubscriber.CollateSubscriptions,
                this.spoofingEquitySubscriber.CollateSubscriptions,
                this.rampingEquitySubscriber.CollateSubscriptions,
                this.placingOrdersEquitySubscriber.CollateSubscriptions,
                this.washTradeFixedIncomeSubscriber.CollateSubscriptions,
                this.highVolumeFixedIncomeSubscriber.CollateSubscriptions,
                this.highProfitFixedIncomeSubscriber.CollateSubscriptions);

            foreach (var subscription in subscriptions)
            {
                if (subscription == null)
                {
                    continue;
                }

                this.logger.LogInformation($"Subscribe Rules subscribing a {subscription.Rule.GetDescription()}");
                player.Subscribe(subscription);
            }

            var ids = this.idExtractor.ExtractIds(ruleParameters);

            if (ids == null || !ids.Any())
            {
                this.logger.LogError("did not have any ids successfully extracted from the rule parameters");

                return(new UniverseRuleSubscriptionSummary(null, null));
            }

            var jointIds = ids.Aggregate((a, b) => $"{a} {b}");

            this.logger.LogInformation($"subscriber processed for the following ids {jointIds}");

            return(await Task.FromResult(new UniverseRuleSubscriptionSummary(ids, subscriptions)));
        }