예제 #1
0
        /// <summary>
        /// The schedule rule runs.
        /// </summary>
        /// <param name="execution">
        /// The execution.
        /// </param>
        /// <param name="identifiableRules">
        /// The identifiable rules.
        /// </param>
        /// <param name="rule">
        /// The rule.
        /// </param>
        /// <param name="ruleContext">
        /// The rule context.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        private async Task ScheduleRuleRuns(
            ScheduledExecution execution,
            IReadOnlyCollection <IIdentifiableRule> identifiableRules,
            RuleIdentifier rule,
            ISystemProcessOperationDistributeRuleContext ruleContext)
        {
            if (identifiableRules == null || !identifiableRules.Any())
            {
                this.logger.LogWarning($"did not have any identifiable rules for rule {rule.Rule}");
                return;
            }

            if (rule.Ids == null ||
                !rule.Ids.Any())
            {
                foreach (var ruleSet in identifiableRules)
                {
                    var ruleInstance = new RuleIdentifier {
                        Rule = rule.Rule, Ids = new[] { ruleSet.Id }
                    };
                    await this.ScheduleRule(ruleInstance, execution, ruleSet.WindowSize, ruleContext.Id);
                }
            }
            else
            {
                foreach (var id in rule.Ids)
                {
                    var identifiableRule =
                        identifiableRules?.FirstOrDefault(_ =>
                                                          string.Equals(_.Id, id, StringComparison.InvariantCultureIgnoreCase));

                    if (identifiableRule == null)
                    {
                        this.logger.LogError(
                            $"asked to schedule an execution for rule {rule.Rule.GetDescription()} with id of {id} which was not found when querying the rule parameter API on the client service.");

                        ruleContext.EventError(
                            $"asked to schedule an execution for rule {rule.Rule.GetDescription()} with id of {id} which was not found when querying the rule parameter API on the client service.");

                        continue;
                    }

                    var ruleInstance = new RuleIdentifier {
                        Rule = rule.Rule, Ids = new[] { id }
                    };

                    await this.ScheduleRule(ruleInstance, execution, identifiableRule.WindowSize, ruleContext.Id);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// The schedule rule.
        /// </summary>
        /// <param name="execution">
        /// The execution.
        /// </param>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        /// <param name="ruleContext">
        /// The rule context.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        private async Task ScheduleRule(
            ScheduledExecution execution,
            RuleParameterDto parameters,
            ISystemProcessOperationDistributeRuleContext ruleContext)
        {
            foreach (var rule in execution.Rules.Where(ru => ru != null))
            {
                switch (rule.Rule)
                {
                case Rules.CancelledOrders:
                    var cancelledOrderRuleRuns =
                        parameters.CancelledOrders?.Select(co => co as IIdentifiableRule)?.ToList();
                    await this.ScheduleRuleRuns(execution, cancelledOrderRuleRuns, rule, ruleContext);

                    break;

                case Rules.HighProfits:
                    var highProfitRuleRuns =
                        parameters.HighProfits?.Select(co => co as IIdentifiableRule)?.ToList();
                    await this.ScheduleRuleRuns(execution, highProfitRuleRuns, rule, ruleContext);

                    break;

                case Rules.HighVolume:
                    var highVolumeRuleRuns =
                        parameters.HighVolumes?.Select(co => co as IIdentifiableRule)?.ToList();
                    await this.ScheduleRuleRuns(execution, highVolumeRuleRuns, rule, ruleContext);

                    break;

                case Rules.MarkingTheClose:
                    var markingTheCloseRuleRuns =
                        parameters.MarkingTheCloses?.Select(co => co as IIdentifiableRule)?.ToList();
                    await this.ScheduleRuleRuns(execution, markingTheCloseRuleRuns, rule, ruleContext);

                    break;

                case Rules.WashTrade:
                    var washTradeRuleRuns = parameters.WashTrades?.Select(co => co as IIdentifiableRule)?.ToList();
                    await this.ScheduleRuleRuns(execution, washTradeRuleRuns, rule, ruleContext);

                    break;

                case Rules.UniverseFilter:
                    break;

                case Rules.Spoofing:
                    var spoofingRuleRuns = parameters.Spoofings?.Select(co => co as IIdentifiableRule)?.ToList();
                    await this.ScheduleRuleRuns(execution, spoofingRuleRuns, rule, ruleContext);

                    break;

                case Rules.PlacingOrderWithNoIntentToExecute:
                    var placingOrderRuleRuns =
                        parameters.PlacingOrders?.Select(_ => _ as IIdentifiableRule)?.ToList();
                    await this.ScheduleRuleRuns(execution, placingOrderRuleRuns, rule, ruleContext);

                    break;

                case Rules.Layering:
                    // var layeringRuleRuns = parameters.Layerings?.Select(co => co as IIdentifiableRule)?.ToList();
                    // await ScheduleRuleRuns(execution, layeringRuleRuns, rule, ruleCtx);
                    break;

                case Rules.FixedIncomeHighProfits:
                    var fixedIncomeHighProfits = parameters.FixedIncomeHighProfits
                                                 ?.Select(co => co as IIdentifiableRule)?.ToList();
                    await this.ScheduleRuleRuns(execution, fixedIncomeHighProfits, rule, ruleContext);

                    break;

                case Rules.FixedIncomeHighVolumeIssuance:
                    var fixedIncomeHighVolumeIssuance = parameters.FixedIncomeHighVolumeIssuance
                                                        ?.Select(co => co as IIdentifiableRule)?.ToList();
                    await this.ScheduleRuleRuns(execution, fixedIncomeHighVolumeIssuance, rule, ruleContext);

                    break;

                case Rules.FixedIncomeWashTrades:
                    var fixedIncomeWashTrade = parameters.FixedIncomeWashTrades
                                               ?.Select(co => co as IIdentifiableRule)?.ToList();
                    await this.ScheduleRuleRuns(execution, fixedIncomeWashTrade, rule, ruleContext);

                    break;

                case Rules.Ramping:
                    var ramping = parameters.Rampings?.Select(co => co as IIdentifiableRule)?.ToList();
                    await this.ScheduleRuleRuns(execution, ramping, rule, ruleContext);

                    break;

                default:
                    this.logger.LogError(
                        $"{rule.Rule} was scheduled but not recognised by the Schedule Rule method in distributed rule.");
                    ruleContext.EventError(
                        $"{rule.Rule} was scheduled but not recognised by the Schedule Rule method in distributed rule.");
                    break;
                }
            }
        }