Пример #1
0
 public void AlwaysEnter()
 {
     Always b = new Always();
     b.AllowMultipleOrders = true;
     Assert.That(b.MinSize == 100);
     int good = 0;
     int i = 0;
     Order o = new Order();
     o = b.Trade(timesales[i++], new BarList(), new Position(s), new BoxInfo());
     if (o.isValid)
         good++;
     Assert.That(b.Turns == 0);
     Assert.That(b.Adjusts == 0);
     o = b.Trade(timesales[i++], new BarList(), new Position(s), new BoxInfo());
     if (o.isValid)
         good++;
     Assert.That(b.Turns == 0);
     Assert.That(b.Adjusts == 1);
     o = b.Trade(timesales[i++], new BarList(), new Position(s), new BoxInfo());
     if (o.isValid)
         good++;
     Assert.That(b.Turns == 0);
     Assert.That(b.Adjusts == 2);
     o = b.Trade(timesales[i++], new BarList(), new Position(s), new BoxInfo());
     if (o.isValid)
         good++;
     Assert.That(b.Turns == 0);
     Assert.That(b.Adjusts == 3);
     // first trade was pre-market so we only have 3 total;
     Assert.That(good == 3);
     // no debugs were sent
     Assert.That(debugs == 0);
 }
Пример #2
0
        // make sure this box only generates orders when last one has been filled
        public void OneOrderAtTime()
        {
            Always b = new Always();

            b.AllowMultipleOrders = false;          // this is the default, but it's what we're testing
            b.MaxSize             = Int32.MaxValue; // lets not restrict our maximum position for this example
            Broker broker = new Broker();
            Tick   t;

            Assert.That(b.MinSize == 100);
            int   good = 0;
            int   i    = 0;
            Order o    = new Order();

            t = new Tick(timesales[i++]);
            broker.Execute(t);
            o = b.Trade(t, new BarList(), broker.GetOpenPosition(s), new BoxInfo());
            broker.sendOrder(o);
            if (o.isValid)
            {
                good++;
            }
            Assert.That(b.Turns == 0);
            Assert.That(b.Adjusts == 0);
            t = new Tick(timesales[i++]);
            broker.Execute(t);
            o = b.Trade(t, new BarList(), broker.GetOpenPosition(s), new BoxInfo());
            broker.sendOrder(o);
            if (o.isValid)
            {
                good++;
            }
            Assert.That(b.Turns == 0);
            Assert.That(b.Adjusts == 1);
            t = new Tick(timesales[i++]);
            broker.Execute(t);
            o = b.Trade(t, new BarList(), broker.GetOpenPosition(s), new BoxInfo());
            // lets change this to a limit order, so he doesn't get filled on just any tick
            o.price = 1;
            broker.sendOrder(o);
            if (o.isValid)
            {
                good++;
            }
            Assert.That(b.Turns == 0);
            Assert.That(b.Adjusts == 2);
            t = new Tick(timesales[i++]);
            broker.Execute(t);
            o = b.Trade(t, new BarList(), broker.GetOpenPosition(s), new BoxInfo());
            broker.sendOrder(o);
            if (o.isValid)
            {
                good++;
            }
            Assert.That(b.Turns == 0);
            Assert.That(b.Adjusts == 2);
            // first trade was pre-market 2nd order was never filled so 3rd was ignored... 2 total.
            Assert.That(good == 2);
        }
Пример #3
0
        public void AlwaysEnter()
        {
            Always b = new Always();

            b.AllowMultipleOrders = true;
            Assert.That(b.MinSize == 100);
            int   good = 0;
            int   i    = 0;
            Order o    = new Order();

            o = b.Trade(timesales[i++], new BarList(), new Position(s), new BoxInfo());
            if (o.isValid)
            {
                good++;
            }
            Assert.That(b.Turns == 0);
            Assert.That(b.Adjusts == 0);
            o = b.Trade(timesales[i++], new BarList(), new Position(s), new BoxInfo());
            if (o.isValid)
            {
                good++;
            }
            Assert.That(b.Turns == 0);
            Assert.That(b.Adjusts == 1);
            o = b.Trade(timesales[i++], new BarList(), new Position(s), new BoxInfo());
            if (o.isValid)
            {
                good++;
            }
            Assert.That(b.Turns == 0);
            Assert.That(b.Adjusts == 2);
            o = b.Trade(timesales[i++], new BarList(), new Position(s), new BoxInfo());
            if (o.isValid)
            {
                good++;
            }
            Assert.That(b.Turns == 0);
            Assert.That(b.Adjusts == 3);
            // first trade was pre-market so we only have 3 total;
            Assert.That(good == 3);
            // no debugs were sent
            Assert.That(debugs == 0);
        }
Пример #4
0
        public void MaxSizeTest()
        {
            Always b = new Always();

            b.MinSize = 100;
            b.MaxSize = 200;
            Position p = new Position(s);
            Order    o = new Order();

            Assert.That(b.MinSize == 100);
            Assert.That(b.MaxSize == 200);
            for (int i = 0; i < timesales.Length; i++)
            {
                Tick t = new Tick(timesales[i]);
                if (o.isValid && t.isTrade)
                {
                    o.Fill(t);
                    p.Adjust((Trade)o);
                    o = new Order();
                }
                Assert.That(p.Size <= b.MaxSize);
                o = b.Trade(timesales[i], new BarList(), p, new BoxInfo());
            }
            Assert.That(p.Size == 200);

            // Now we'll set maxsize to 100
            b         = new Always();
            b.MinSize = 100;
            b.MaxSize = 100;
            p         = new Position(s);
            o         = new Order();
            Assert.That(b.MinSize == 100);
            Assert.That(b.MaxSize == 100);
            for (int i = 0; i < timesales.Length; i++)
            {
                Tick t = new Tick(timesales[i]);
                if (o.isValid && t.isTrade)
                {
                    o.Fill(t);
                    p.Adjust((Trade)o);
                    o = new Order();
                }
                Assert.That(p.Size <= b.MaxSize);
                o = b.Trade(timesales[i], new BarList(), p, new BoxInfo());
            }
            Assert.That(p.Size == 100);
        }
Пример #5
0
        public void NewsTest()
        {
            // subscribe to news service that will count everytime a debug is sent
            Always b = new Always(); // send debugs from this box to our news service

            b.GotDebug           += new DebugFullDelegate(b_GotDebug);
            b.AllowMultipleOrders = true; // lets allow multiple orders for more debugging
            // this time we want to throw news events for debugging statements
            b.Debug = true;
            int good = 0;

            b.D("Starting debug test for NUnit...");
            for (int i = 0; i < timesales.Length; i++)
            {
                if (b.Trade(timesales[i], new BarList(), new Position(s), new BoxInfo()).isValid)
                {
                    good++;
                }
            }
            b.D("NUnit testing complete...");
            Assert.That(good == 3);
            // news from the box was received.
            Assert.That(debugs > 0);
        }
Пример #6
0
        public void MaxSizeTest()
        {
            Always b = new Always();
            b.MinSize = 100;
            b.MaxSize = 200;
            Position p = new Position(s);
            Order o = new Order();
            Assert.That(b.MinSize==100);
            Assert.That(b.MaxSize==200);
            for (int i = 0; i < timesales.Length; i++)
            {
                Tick t = new Tick(timesales[i]);
                if (o.isValid && t.isTrade)
                {
                    o.Fill(t);
                    p.Adjust((Trade)o);
                    o = new Order();
                }
                Assert.That(p.Size<=b.MaxSize);
                o = b.Trade(timesales[i], new BarList(), p, new BoxInfo());
            }
            Assert.That(p.Size == 200);

            // Now we'll set maxsize to 100
            b = new Always();
            b.MinSize = 100;
            b.MaxSize = 100;
            p = new Position(s);
            o = new Order();
            Assert.That(b.MinSize == 100);
            Assert.That(b.MaxSize == 100);
            for (int i = 0; i < timesales.Length; i++)
            {
                Tick t = new Tick(timesales[i]);
                if (o.isValid && t.isTrade)
                {
                    o.Fill(t);
                    p.Adjust((Trade)o);
                    o = new Order();
                }
                Assert.That(p.Size <= b.MaxSize);
                o = b.Trade(timesales[i], new BarList(), p, new BoxInfo());
            }
            Assert.That(p.Size == 100);

        }
Пример #7
0
 public void NewsTest()
 {
     // subscribe to news service that will count everytime a debug is sent
     Always b = new Always(); // send debugs from this box to our news service
     b.GotDebug += new DebugFullDelegate(b_GotDebug);
     b.AllowMultipleOrders = true; // lets allow multiple orders for more debugging
     // this time we want to throw news events for debugging statements
     b.Debug = true;
     int good = 0;
     b.D("Starting debug test for NUnit...");
     for (int i = 0; i < timesales.Length; i++)
         if (b.Trade(timesales[i], new BarList(), new Position(s), new BoxInfo()).isValid)
             good++;
     b.D("NUnit testing complete...");
     Assert.That(good == 3);
     // news from the box was received.
     Assert.That(debugs>0);
 }
Пример #8
0
 // make sure this box only generates orders when last one has been filled
 public void OneOrderAtTime() 
 {
     Always b = new Always();
     b.AllowMultipleOrders = false; // this is the default, but it's what we're testing
     b.MaxSize = Int32.MaxValue; // lets not restrict our maximum position for this example
     Broker broker = new Broker();
     Tick t;
     Assert.That(b.MinSize == 100);
     int good = 0;
     int i = 0;
     Order o = new Order();
     t = new Tick(timesales[i++]);
     broker.Execute(t);
     o = b.Trade(t, new BarList(), broker.GetOpenPosition(s), new BoxInfo());
     broker.sendOrder(o);
     if (o.isValid)
         good++;
     Assert.That(b.Turns == 0);
     Assert.That(b.Adjusts == 0);
     t = new Tick(timesales[i++]);
     broker.Execute(t);
     o = b.Trade(t, new BarList(), broker.GetOpenPosition(s), new BoxInfo());
     broker.sendOrder(o);
     if (o.isValid)
         good++;
     Assert.That(b.Turns == 0);
     Assert.That(b.Adjusts == 1);
     t = new Tick(timesales[i++]);
     broker.Execute(t);
     o = b.Trade(t, new BarList(), broker.GetOpenPosition(s), new BoxInfo());
     // lets change this to a limit order, so he doesn't get filled on just any tick
     o.price = 1;
     broker.sendOrder(o);
     if (o.isValid)
         good++;
     Assert.That(b.Turns == 0);
     Assert.That(b.Adjusts == 2);
     t = new Tick(timesales[i++]);
     broker.Execute(t);
     o = b.Trade(t, new BarList(), broker.GetOpenPosition(s), new BoxInfo());
     broker.sendOrder(o);
     if (o.isValid)
         good++;
     Assert.That(b.Turns == 0);
     Assert.That(b.Adjusts == 2);
     // first trade was pre-market 2nd order was never filled so 3rd was ignored... 2 total.
     Assert.That(good == 2);
 }