示例#1
0
        public void SingleRuleITest()
        {
            Log.logLevel = Log.LogLevels.DETAILED;
            RuleMSX rmsx = new RuleMSX();

            string newRuleSetName = "SingleIterationRuleSet";
            string newDataSetName = "SingleIterationDataSet";
            string newRuleName    = "IsBooleanTrue";
            string actionMessage  = "ActionMessage";

            RuleSet rs = rmsx.createRuleSet(newRuleSetName);
            DataSet ds = rmsx.createDataSet(newDataSetName);

            RuleAction rai = rmsx.createAction("RuleActionIn", new GenericAction(actionMessage));

            Rule r = new Rule(newRuleName, new GenericBoolRule(true), rai);

            rs.AddRule(r);

            ds.addDataPoint("TestDataPoint", new StringDataPoint("test_data_point"));

            rs.Execute(ds);

            // We have to wait for the action to take place. Under normal circumstances there
            // would be no interation with the data from outside the evaluators/actions.
            System.Threading.Thread.Sleep(100);

            GenericAction rao = (GenericAction)rai.getExecutor();

            Assert.That(rao.getOutgoing(), Is.EqualTo(actionMessage));
        }
示例#2
0
        public void RuleSetReportingSizeCheckMultiTop()
        {
            RuleMSX rmsx = new RuleMSX();

            string newRuleSetName = "TestRuleSet";

            RuleSet rs = rmsx.createRuleSet(newRuleSetName);

            rs.AddRule(new Rule("TestRule1", new GenericBoolRule(true), rmsx.createAction("TestAction1", new GenericAction("TestAction1"))));
            Rule r2 = new Rule("TestRule2", new GenericBoolRule(false), rmsx.createAction("TestAction4", new GenericAction("TestAction4")));

            rs.AddRule(r2);
            r2.AddRule(new Rule("TestRule5", new GenericBoolRule(true), rmsx.createAction("TestAction3", new GenericAction("TestAction3"))));
            r2.AddRule(new Rule("TestRule6", new GenericBoolRule(false), rmsx.createAction("TestAction5", new GenericAction("TestAction5"))));
            rs.AddRule(new Rule("TestRule3", new GenericBoolRule(false)));
            Rule r4 = new Rule("TestRule4", new GenericBoolRule(true), rmsx.createAction("TestAction2", new GenericAction("TestAction2")));

            rs.AddRule(r4);
            r4.AddRule(new Rule("TestRule7", new GenericBoolRule(false), rmsx.createAction("TestAction6", new GenericAction("TestAction6"))));
            r4.AddRule(new Rule("TestRule8", new GenericBoolRule(true), rmsx.createAction("TestAction7", new GenericAction("TestAction7"))));

            string report = rs.report();

            System.Console.WriteLine(report);

            Assert.That(report.Length, Is.EqualTo(664));
        }
        public void RuleAddActionGetActionReturnsCorrectAction()
        {
            RuleMSX rmsx           = new RuleMSX();
            string  newRuleSetName = "NewRuleSet";
            string  newDataSetName = "NewDataSet";
            string  newRuleName    = "Rule1";
            string  actionMessage  = "ActionMessage";
            RuleSet rs             = rmsx.createRuleSet(newRuleSetName);
            DataSet ds             = rmsx.createDataSet(newDataSetName);
            Rule    r = new Rule(newRuleName, new GenericBoolRule(true));

            rs.AddRule(r);
            RuleAction rai = rmsx.createAction("RuleActionIn", new GenericAction(actionMessage));

            r.AddAction(rai);
            ActionExecutor rae = r.GetActions()[0].getExecutor();

            rae.Execute(ds);
            GenericAction ga = (GenericAction)rae;

            Assert.That(ga.getOutgoing, Is.EqualTo(actionMessage));
        }
示例#4
0
        public RuleMSXTest()
        {
            System.Console.WriteLine("RuleMSXTest starting...");
            System.Console.WriteLine("Instantiating RuleMSX...");

            LogRmsx.logLevel = LogRmsx.LogLevels.NONE;

            this.rmsx = new RuleMSX();

            // Create new RuleSet
            this.ruleSet = rmsx.createRuleSet("TestRules");

            Rule ruleIsNotExpired = new Rule("IsNotExpired", new StringInequalityRule("OrderStatus", "EXPIRED"));
            Rule ruleIsExpired    = new Rule("IsExpired", new StringEqualityRule("OrderStatus", "EXPIRED"), rmsx.createAction("SendIgnoringSignal", new SendAdditionalSignal("Ignoring Order - EXPIRED")));
            Rule ruleNeedsRouting = new Rule("NeedsRouting", new NeedsRoutingRule());
            Rule ruleIsLNExchange = new Rule("IsLNExchange", new StringEqualityRule("Exchange", "LN"), rmsx.createAction("RouteToBrokerBB", new RouteToBroker(this, "BB")));
            Rule ruleIsUSExchange = new Rule("IsUSExchange", new StringEqualityRule("Exchange", "US"));
            Rule ruleIsIBM        = new Rule("IsIBM", new StringEqualityRule("Ticker", "IBM US Equity"), rmsx.createAction("RouteToBrokerEFIX", new RouteToBroker(this, "EFIX")));

            ruleIsIBM.AddAction(rmsx.createAction("SendIBMSignal", new SendAdditionalSignal("This is IBM!!")));
            Rule ruleIsMSFT      = new Rule("IsMSFT", new StringEqualityRule("Ticker", "MSFT US Equity"), rmsx.createAction("RejectedSignal", new SendAdditionalSignal("Not Routing as would be rejected")));
            Rule ruleIsFilled500 = new Rule("IsFilled500", new IsFilled500Rule(), rmsx.createAction("Signal500filled", new SendAdditionalSignal("Order is filled to 500 or more.")));

            // Maybe add code so that rather than RouteToBroker("BB") we create a new datapoint "TargetBroker", set it's value to BB.
            // Then add a new rule that checks if there are available shares. if true, then action is route to targetbroker which depends on target broker

            //Add new rules for working/filled amount checks
            this.ruleSet.AddRule(ruleIsNotExpired);
            this.ruleSet.AddRule(ruleIsExpired);
            //this.ruleSet.AddRule(ruleIsFilled500);
            ruleIsNotExpired.AddRule(ruleNeedsRouting);
            ruleNeedsRouting.AddRule(ruleIsLNExchange);
            ruleNeedsRouting.AddRule(ruleIsUSExchange);
            ruleIsUSExchange.AddRule(ruleIsIBM);
            ruleIsUSExchange.AddRule(ruleIsMSFT);

            System.Console.WriteLine("...done.");

            System.Console.WriteLine(ruleSet.report());

            System.Console.WriteLine("Instantiating EasyMKT...");

            this.emkt = new EasyMKT();

            System.Console.WriteLine("...done.");

            // Adding subscription fields to EasyMKT
            emkt.AddField("BID");
            emkt.AddField("ASK");
            emkt.AddField("MID");
            emkt.AddField("LAST_PRICE");

            System.Console.WriteLine("Starting EasyMKT...");
            emkt.start();
            System.Console.WriteLine("EasyMKT started.");

            System.Console.WriteLine("Instantiating EasyMSX...");
            LogEmsx.logLevel = LogEmsx.LogLevels.NONE;
            try
            {
                this.emsx = new EasyMSX(EasyMSX.Environment.BETA);

                System.Console.WriteLine("EasyMSX instantiated. Adding notification handler.");

                this.emsx.orders.addNotificationHandler(this);

                System.Console.WriteLine("Starting EasyMSX");

                this.emsx.start();
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex);
            }
            System.Console.WriteLine("EasyMSX started.");
            System.Console.WriteLine("RuleMSXTest running...");
        }
示例#5
0
        public void VariableDataSetCountTest()
        {
            Log.logLevel = Log.LogLevels.NONE;

            RuleMSX rmsx = new RuleMSX();

            RuleSet ruleSet = rmsx.createRuleSet("VariableRuleSet");

            // Set min and max of target range
            int numMin = 1;
            int numMax = 1000;

            // Set value for target
            int target = 998;

            // number of datasets to run
            int numDataSets = 500;

            MultiTargetReached targetReached = new MultiTargetReached(numDataSets);
            RuleAction         reached       = rmsx.createAction("reached", targetReached);

            Accumulator count = new Accumulator(0);

            // Setup rule tree
            createNRules(rmsx, ruleSet, reached, count, numMin, numMax);


            for (int i = 0; i < numDataSets; i++)
            {
                DataSet dataSet = rmsx.createDataSet("TargetTestDataSet" + i.ToString());

                // Set datapoint for target
                dataSet.addDataPoint("target", new GenericIntDataPointSource(target));

                // Set datapoint for result
                dataSet.addDataPoint("result", new GenericIntDataPointSource(0));

                ruleSet.Execute(dataSet);
            }

            int maxMS = 40000;
            int step  = 10;

            while (maxMS > 0)
            {
                if (targetReached.fired)
                {
                    break;
                }
                System.Threading.Thread.Sleep(step);
                maxMS -= step;
            }

            if (maxMS == 0)
            {
                System.Console.WriteLine("Timeout");
            }
            ruleSet.Stop();

            System.Console.WriteLine("Execution Time (ms): " + ruleSet.GetLastCycleExecutionTime());
            System.Console.WriteLine("Number of Evaluations: " + count.value().ToString());

            //int result = (int)((GenericIntDataPointSource)dataSet.getDataPoint("result").GetSource()).GetValue();

            Assert.True(true);
        }
示例#6
0
        private void createNRules(RuleMSX rmsx, RuleContainer rc, RuleAction reached, Accumulator acm, int min, int max)
        {
            if (min == max)
            {
                // leaf node, so add rule with action
                Rule newRule = new Rule("intBetween" + min.ToString() + "and" + max.ToString(), new IsIntBetween(min, max, acm), rmsx.createAction("ShowValue", new ShowValue(min)));
                newRule.AddAction(reached);
                rc.AddRule(newRule);
            }
            else
            {
                Rule newRule = new Rule("intBetween" + min.ToString() + "and" + max.ToString(), new IsIntBetween(min, max, acm));
                rc.AddRule(newRule);

                if (max - min < 2)
                {
                    createNRules(rmsx, newRule, reached, acm, min, min);
                    createNRules(rmsx, newRule, reached, acm, max, max);
                }
                else
                {
                    int mid = ((max - min) / 2) + min;
                    createNRules(rmsx, newRule, reached, acm, min, mid);
                    createNRules(rmsx, newRule, reached, acm, mid + 1, max);
                }
            }
        }
示例#7
0
        public void VariableRuleCountTest()
        {
            /*  Rule: IntBetween(x,y)
             *
             *               {1,10}
             *              /      \
             *         {1,5}        {6,10}
             *        /    \        /    \
             *    {1,3}   {4,5}  {6,8}  {9,10}
             *    / | \   / \    / | \   / \
             *  {1}{2}{3}{4}{5}{6}{7}{8}{9}{10}
             */

            Log.logLevel = Log.LogLevels.NONE;

            RuleMSX rmsx = new RuleMSX();

            RuleSet ruleSet = rmsx.createRuleSet("VariableRuleSet");

            // Set min and max of target range
            int numMin = 1;
            int numMax = 10000;

            // Set value for target
            int target = 9999;

            TargetReached targetReached = new TargetReached();
            RuleAction    reached       = rmsx.createAction("reached", targetReached);

            Accumulator count = new Accumulator(0);

            // Setup rule tree
            createNRules(rmsx, ruleSet, reached, count, numMin, numMax);

            DataSet dataSet = rmsx.createDataSet("TargetTestDataSet");

            // Set datapoint for target
            dataSet.addDataPoint("target", new GenericIntDataPointSource(target));

            // Set datapoint for result
            dataSet.addDataPoint("result", new GenericIntDataPointSource(0));

            //System.Console.WriteLine("Report: \n\n" + ruleSet.report());

            ruleSet.Execute(dataSet);

            int maxMS = 40000;
            int step  = 10;

            while (maxMS > 0)
            {
                if (targetReached.fired)
                {
                    break;
                }
                System.Threading.Thread.Sleep(step);
                maxMS -= step;
            }

            if (maxMS == 0)
            {
                System.Console.WriteLine("Timeout");
            }

            ruleSet.Stop();

            System.Console.WriteLine("Execution Time (ms): " + ruleSet.GetLastCycleExecutionTime());
            System.Console.WriteLine("Number of Evaluations: " + count.value().ToString());

            int result = (int)((GenericIntDataPointSource)dataSet.getDataPoint("result").GetSource()).GetValue();

            Assert.True(target == result);
        }
示例#8
0
        public void CounterTest()
        {
            Log.logLevel = Log.LogLevels.BASIC;

            RuleMSX rmsx = new RuleMSX();

            RuleSet ruleSet = rmsx.createRuleSet("CounterTestRuleSet");
            DataSet dataSet = rmsx.createDataSet("CounterTestDataSet");

            dataSet.addDataPoint("counter", new GenericIntDataPointSource(0));

            int maxVal = 10000;

            RuleAction  counterSignalAndStep10   = rmsx.createAction("CounterSignalAndStep10", new CounterSignalAndStep(10));
            RuleAction  counterSignalAndStep100  = rmsx.createAction("CounterSignalAndStep100", new CounterSignalAndStep(100));
            RuleAction  counterSignalAndStep1000 = rmsx.createAction("CounterSignalAndStep1000", new CounterSignalAndStep(1000));
            RuleAction  counterSignalAndStepMax  = rmsx.createAction("CounterSignalAndStepMax", new CounterSignalAndStep(maxVal));
            EqualSignal equalSignal    = new EqualSignal();
            RuleAction  equalSignalMax = rmsx.createAction("EqualSignalMax", equalSignal);

            Rule lessThan10 = new Rule("LessThan10", new IntMinMaxEvaluator(0, 9), counterSignalAndStep10);
            Rule greaterThanOrEqualTo10LessThan100   = new Rule("GreaterThanOrEqualTo10LessThan100", new IntMinMaxEvaluator(10, 99), counterSignalAndStep100);
            Rule greaterThanOrEqualTo100LessThan1000 = new Rule("GreaterThanOrEqualTo100LessThan1000", new IntMinMaxEvaluator(100, 999), counterSignalAndStep1000);
            Rule greaterThanOrEqualTo1000LessThanMax = new Rule("GreaterThanOrEqualTo1000LessThanMax", new IntMinMaxEvaluator(1000, maxVal - 1), counterSignalAndStepMax);
            Rule equalMax = new Rule("EqualMax", new EqualEvaluator(maxVal), equalSignalMax);

            ruleSet.AddRule(lessThan10);
            ruleSet.AddRule(greaterThanOrEqualTo10LessThan100);
            ruleSet.AddRule(greaterThanOrEqualTo100LessThan1000);
            ruleSet.AddRule(greaterThanOrEqualTo1000LessThanMax);
            ruleSet.AddRule(equalMax);

            System.Console.WriteLine(ruleSet.report());

            ruleSet.Execute(dataSet);

            int maxMS = 400000;
            int step  = 10;

            while (maxMS > 0)
            {
                if (equalSignal.fired)
                {
                    System.Console.WriteLine("Target reached");
                    break;
                }
                System.Threading.Thread.Sleep(step);
                maxMS -= step;
            }

            if (maxMS == 0)
            {
                System.Console.WriteLine("Timeout");
            }

            ruleSet.Stop();

            System.Console.WriteLine("Execution Time (ms): " + ruleSet.GetLastCycleExecutionTime());

            Assert.That(equalSignal.fired, Is.EqualTo(true));
        }