Example #1
0
        public void GetDataSetByNameReturnsCorrectDataSet()
        {
            RuleMSX rmsx           = new RuleMSX();
            string  newDataSetName = "NewDataSet";

            rmsx.CreateDataSet(newDataSetName);
            DataSet ds = rmsx.GetDataSet(newDataSetName);

            Assert.That(ds.GetName(), Is.EqualTo(newDataSetName));
        }
Example #2
0
        public void GetDataSetWithIncorrectNameReturnsNull()
        {
            RuleMSX rmsx           = new RuleMSX();
            string  newDataSetName = "NewDataSet";

            rmsx.CreateDataSet(newDataSetName);
            DataSet ds = rmsx.GetDataSet("SomeOtherName");

            Assert.IsNull(ds);
        }
Example #3
0
        public void GetRuleSetWithIncorrectNameReturnsNull()
        {
            RuleMSX rmsx           = new RuleMSX();
            string  newRuleSetName = "NewRuleSet";

            rmsx.CreateRuleSet(newRuleSetName);
            RuleSet rs = rmsx.GetRuleSet("SomeOtherName");

            Assert.IsNull(rs);
        }
Example #4
0
        public void DataSetDataPointAddReturnsNewDataPoint()
        {
            RuleMSX   rmsx             = new RuleMSX();
            string    newDataSetName   = "NewDataSet";
            string    newDataPointName = "NewDataPointName";
            DataSet   ds  = rmsx.CreateDataSet(newDataSetName);
            DataPoint dpo = ds.AddDataPoint(newDataPointName);

            Assert.That(dpo.GetName(), Is.EqualTo(newDataPointName));
        }
Example #5
0
        public void RuleSetAddRuleGetRuleShouldReturnNewRule()
        {
            RuleMSX rmsx           = new RuleMSX();
            string  newRuleSetName = "NewRuleSet";
            string  newRuleName    = "Rule1";
            RuleSet rs             = rmsx.CreateRuleSet(newRuleSetName);

            rs.AddRule(newRuleName);
            Assert.That(rs.GetRule(newRuleName).GetName(), Is.EqualTo(newRuleName));
        }
Example #6
0
        public void GetRuleSetByNameReturnsCorrectRuleSet()
        {
            RuleMSX rmsx           = new RuleMSX();
            string  newRuleSetName = "NewRuleSet";

            rmsx.CreateRuleSet(newRuleSetName);
            RuleSet rs = rmsx.GetRuleSet(newRuleSetName);

            Assert.That(rs.GetName(), Is.EqualTo(newRuleSetName));
        }
        public void GetDataSetsReturnsDataSetCollection()
        {
            RuleMSX rmsx           = new RuleMSX();
            string  newDataSetName = "NewDataSet";

            rmsx.createDataSet(newDataSetName);
            List <DataSet> dsl = rmsx.getDataSets();
            DataSet        ds  = dsl[0];

            Assert.That(ds.getName(), Is.EqualTo(newDataSetName));
        }
        public void GetRuleSetsReturnsRuleSetCollection()
        {
            RuleMSX rmsx           = new RuleMSX();
            string  newRuleSetName = "NewRuleSet";

            rmsx.createRuleSet(newRuleSetName);
            List <RuleSet> rsl = rmsx.getRuleSets();
            RuleSet        rs  = rsl[0];

            Assert.That(rs.getName(), Is.EqualTo(newRuleSetName));
        }
Example #9
0
        public void GetRulesReturnsCorrectListOfRules()
        {
            RuleMSX     rmsx           = new RuleMSX();
            string      newRuleSetName = "NewRuleSet";
            string      newRuleName    = "NewRuleName";
            RuleSet     rs             = rmsx.CreateRuleSet(newRuleSetName);
            Rule        ri             = rs.AddRule(newRuleName);
            List <Rule> rl             = rs.GetRules();
            Rule        ro             = rl[0];

            Assert.That(ro.GetName(), Is.EqualTo(newRuleName));
        }
        public void GetDataPointsReturnsCorrectDictOfPoints()
        {
            RuleMSX   rmsx             = new RuleMSX();
            string    newDataSetName   = "NewDataSet";
            string    newDataPointName = "NewDataPointName";
            DataSet   ds  = rmsx.createDataSet(newDataSetName);
            DataPoint dpi = ds.addDataPoint(newDataPointName);
            Dictionary <string, DataPoint> dpd = ds.getDataPoints();
            DataPoint dpo;

            dpd.TryGetValue(newDataPointName, out dpo);
            Assert.That(dpo.GetName(), Is.EqualTo(newDataPointName));
        }
        public void RuleGetEvaluatorReturnsCorrectEvaluator()
        {
            RuleMSX rmsx           = new RuleMSX();
            string  newRuleSetName = "NewRuleSet";
            string  newDataSetName = "NewDataSet";
            string  newRuleName    = "Rule1";
            RuleSet rs             = rmsx.createRuleSet(newRuleSetName);
            Rule    r  = new Rule(newRuleName, new GenericBoolRule(true));
            DataSet ds = rmsx.createDataSet(newDataSetName);

            rs.AddRule(r);
            Assert.That(r.GetEvaluator().Evaluate(ds), Is.EqualTo(true));
        }
        public void SetDataPointSourceAtDataPointCreateCheckSource()
        {
            RuleMSX         rmsx               = new RuleMSX();
            string          newDataSetName     = "NewDataSet";
            string          newDataPointName   = "NewDataPointName";
            string          testDataPointValue = "TestDataPointValue";
            DataSet         ds   = rmsx.createDataSet(newDataSetName);
            DataPointSource srci = new TestDataPointSource(testDataPointValue);
            DataPoint       dpo  = ds.addDataPoint(newDataPointName, srci);
            DataPointSource srco = dpo.GetSource();

            Assert.That(srco.GetValue().ToString(), Is.EqualTo(testDataPointValue));
        }
        public void RuleMSXStopShouldReturnTrueWithActiveRuleSet()
        {
            RuleMSX rmsx           = new RuleMSX();
            string  newRuleSetName = "NewRuleSet";
            string  newDataSetName = "NewDataSet";
            string  newRuleName    = "Rule1";
            RuleSet rs             = rmsx.createRuleSet(newRuleSetName);
            Rule    r  = new Rule(newRuleName, new GenericBoolRule(true));
            DataSet ds = rmsx.createDataSet(newDataSetName);

            rs.AddRule(r);
            rs.Execute(ds);
            Assert.That(rmsx.Stop(), Is.EqualTo(true));
        }
        public void DataPointSourceSetStaleNoError()
        {
            // Call to SetStale() on DataPointSource should return no error
            RuleMSX         rmsx               = new RuleMSX();
            string          newDataSetName     = "NewDataSet";
            string          newDataPointName   = "NewDataPointName";
            string          testDataPointValue = "TestDataPointValue";
            DataSet         ds   = rmsx.createDataSet(newDataSetName);
            DataPoint       dpo  = ds.addDataPoint(newDataPointName);
            DataPointSource srci = new TestDataPointSource(testDataPointValue);

            dpo.SetDataPointSource(srci);
            Assert.DoesNotThrow(() => srci.SetStale());
        }
Example #15
0
        public void SetDataPointSourceGetSourceReturnCorrect()
        {
            RuleMSX         rmsx               = new RuleMSX();
            string          newDataSetName     = "NewDataSet";
            string          newDataPointName   = "NewDataPointName";
            string          testDataPointValue = "TestDataPointValue";
            DataSet         ds   = rmsx.CreateDataSet(newDataSetName);
            DataPoint       dpo  = ds.AddDataPoint(newDataPointName);
            DataPointSource srci = new TestDataPointSource(testDataPointValue);

            dpo.SetDataPointSource(srci);
            DataPointSource srco = dpo.GetSource();

            Assert.That(srco.GetValue().ToString(), Is.EqualTo(testDataPointValue));
        }
        public void RuleMSXStopShouldReturnTrueWithUnexecutedRuleSet()
        {
            RuleMSX rmsx           = new RuleMSX();
            string  newRuleSetName = "NewRuleSet";
            string  newDataSetName = "NewDataSet";
            string  newRuleName    = "Rule1";
            RuleSet rs             = rmsx.createRuleSet(newRuleSetName);
            Rule    r  = new Rule(newRuleName, new GenericBoolRule(true));
            DataSet ds = rmsx.createDataSet(newDataSetName);

            rs.AddRule(r);
            // We are deliberately not executing the ruleset...
            //rs.Execute(ds);
            Assert.That(rmsx.Stop(), Is.EqualTo(true));
        }
        public void CreateDataSetAndDumpCheckSize()
        {
            RuleMSX rmsx           = new RuleMSX();
            string  newDataSetName = "NewDataSet";
            DataSet ds             = rmsx.createDataSet(newDataSetName);

            ds.addDataPoint("DataPoint1").SetDataPointSource(new TestDataPointSource("dp1"));
            ds.addDataPoint("DataPoint2").SetDataPointSource(new TestDataPointSource("dp2"));
            ds.addDataPoint("DataPoint3").SetDataPointSource(new TestDataPointSource("dp3"));
            ds.addDataPoint("DataPoint4").SetDataPointSource(new TestDataPointSource("dp4"));
            ds.addDataPoint("DataPoint5").SetDataPointSource(new TestDataPointSource("dp5"));
            string report = ds.report();

            System.Console.WriteLine(report);
            Assert.That(report.Length, Is.EqualTo(123));
        }
Example #18
0
        private void Run()
        {
            log("IOIEMSXRMSXDemo - Auto-routing IOI orders");

            log("Initializing RuleMSX...");
            this.rmsx         = new RuleMSX();
            LogRmsx.logLevel  = LogRmsx.LogLevels.DETAILED;
            LogRmsx.logPrefix = "(RuleMSX...)";

            log("RuleMSX initialized.");

            log("Initializing EasyIOI...");
            this.eioi = new EasyIOI();
            log("EasyIOI initialized.");

            LogIOI.logPrefix = "(EasyIOI...)";
            LogIOI.logLevel  = com.bloomberg.ioiapi.samples.Log.LogLevels.DETAILED;

            log("Initializing EasyMSX...");
            this.emsx = new EasyMSX();
            log("EasyMSX initialized.");

            LogEMSX.logPrefix = "(EasyMSX...)";
            LogEMSX.logLevel  = com.bloomberg.emsx.samples.Log.LogLevels.NONE;

            log("Create ruleset...");
            BuildRules();
            log("Ruleset ready.");

            this.emsx.orders.addNotificationHandler(this);
            this.emsx.routes.addNotificationHandler(this);

            log("Starting EasyMSX");
            this.emsx.start();
            log("EasyMSX started");

            this.eioi.iois.addNotificationHandler(this);

            log("Starting EasyIOI");
            this.eioi.start();
            log("EasyIOI started");
        }
Example #19
0
        public void RuleSetReportingSizeCheckSingleRule()
        {
            RuleMSX rmsx = new RuleMSX();

            string newRuleSetName = "TestRuleSet";
            string newDataSetName = "TestDataSet";
            string newRuleName    = "IsBooleanTrue";

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

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

            rs.AddRule(r);

            string report = rs.report();

            System.Console.WriteLine(report);

            Assert.That(report.Length, Is.EqualTo(126));
        }
        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));
        }
Example #21
0
        private void Run()
        {
            log("Initializing RuleMSX...");
            this.rmsx         = new RuleMSX();
            LogRmsx.logLevel  = LogRmsx.LogLevels.DETAILED;
            LogRmsx.logPrefix = "(RuleMSX..........)";

            log("RuleMSX initialized.");

            log("Initializing EasyMSX...");
            this.emsx = new EasyMSX();
            log("EasyMSX initialized.");

            log("Create ruleset...");
            BuildRules();
            log("Ruleset ready.");

            this.emsx.routes.addNotificationHandler(this);

            log("Starting EasyMSX");
            this.emsx.start();
            log("EasyMSX started");
        }
        public void RuleMSXStopShouldReturnTrueWithNoRuleSets()
        {
            RuleMSX rmsx = new RuleMSX();

            Assert.That(rmsx.Stop(), Is.EqualTo(true));
        }
Example #23
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));
        }
Example #24
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);
        }
Example #25
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);
        }
Example #26
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...");
        }