예제 #1
0
        public void DoubleBasicWithFlat()
        {
            long id = 1;
            sho = new REGSHO_ShortTracker();
            sho.SendDebugEvent += new DebugDelegate(sho_SendDebugEvent);
            sho.VerboseDebugging = true;
            Order o = new OrderImpl();

            // take a position
            sho.GotPosition(new PositionImpl(sym, 89.7m, 100));

            // accept two exits
            o = new SellStop(sym, 100, 89.65m, id++);
            long stop1 = o.id;
            Assert.IsFalse(sho.isOrderShort(o), "entry1: first sell was incorrectly short");
            sho.GotOrder(o);
            o = new SellLimit(sym, 100, 89.75m, id++);
            long profit1 = o.id;
            Assert.IsTrue(sho.isOrderShort(o), "entry1: second sell was incorrectly sell");
            sho.GotOrder(o);


            // flat
            o = new SellStop(sym, 100, 89.65m, stop1);
            o.Fill(TickImpl.NewTrade(sym,89.62m,100));
            sho.GotFill((Trade)o);
            sho.GotCancel(profit1);

            // do again
            // take a position
            o = new BuyMarket(sym,100);
            o.id = id++;
            o.Fill(TickImpl.NewTrade(sym, 89.64m, 100));
            sho.GotFill((Trade)o);

            // accept two exits
            o = new SellStop(sym, 100, 89.65m, id++);
            Assert.IsFalse(sho.isOrderShort(o), "entry2: first sell was incorrectly short");
            sho.GotOrder(o);
            o = new SellLimit(sym, 100, 89.75m, id++);
            Assert.IsTrue(sho.isOrderShort(o), "entry2: second sell was incorrectly NOT short");
            sho.GotOrder(o);



        }
예제 #2
0
        public void Test()
        {
            // reset measurements
            reset();

            // create tests
            long id = 1;
            Order o = new BuyMarket(sym, 2*size);
            o.id = id++;
            // start measuring
            lt.sendorder(o);
            // ack
            lt.GotOrder(o);
            // ensure we got a measurement
            Assert.IsTrue(gotmeasurement(),mez);
            // reset measurements
            reset();

            // fill
            o.Fill(TickImpl.NewTrade(sym, 100, size));
            Trade t = (Trade)o;
            lt.GotFill(t);
            // ensure we got a measurement
            Assert.IsTrue(gotmeasurement(),mez);
            // reset measurements
            reset();

            // cancel
            lt.sendcancel(o.id);
            System.Threading.Thread.Sleep(50);
            // ack cancel
            lt.GotCancel(o.id);
            // ensure we got a measurement
            Assert.IsTrue(gotmeasurement(),mez);

        }
예제 #3
0
        public void Fill()
        {
            const string s = "TST";
            // market should fill on trade but not on quote
            OrderImpl o = new BuyMarket(s, 100);
            Assert.That(o.Fill(TickImpl.NewTrade(s, 9, 100)));
            Assert.That(!o.Fill(TickImpl.NewBid(s, 8, 100)));

            // buy limit

            // limit should fill if order price is inside market
            o = new BuyLimit(s, 100, 10m);
            Assert.That(o.Fill(TickImpl.NewTrade(s, 9, 100)));
            // shouldn't fill outside market
            o = new BuyLimit(s, 100, 10m);
            Assert.That(!o.Fill(TickImpl.NewTrade(s, 11, 100)));

            // sell limit

            // limit should fill if order price is inside market
            o = new SellLimit(s, 100, 10m);
            Assert.That(o.Fill(TickImpl.NewTrade(s, 11, 100)));
            // shouldn't fill outside market
            o = new SellLimit(s, 100, 10m);
            Assert.That(!o.Fill(TickImpl.NewTrade(s, 9, 100)));

            // buy stop

            o = new BuyStop(s, 100, 10m);
            Assert.That(o.Fill(TickImpl.NewTrade(s, 11, 100)));
            // shouldn't fill outside market
            o = new BuyStop(s, 100, 10m);
            Assert.That(!o.Fill(TickImpl.NewTrade(s, 9, 100)));

            // sell stop

            o = new SellStop(s, 100, 10m);
            Assert.That(o.Fill(TickImpl.NewTrade(s, 9, 100)));
            // shouldn't fill outside market
            o = new SellStop(s, 100, 10m);
            Assert.That(!o.Fill(TickImpl.NewTrade(s, 11, 100)));

            // always fail filling an invalid tick
            o = new BuyMarket(s, 100);
            Assert.IsFalse(o.Fill(TickImpl.NewTrade(s, 0, 0)));

            // always fail filling invalid order
            o = new BuyLimit(s, 100, 10);
            OrderImpl x = new OrderImpl();
            Assert.IsFalse(o.Fill(x));

            // always fail filling an order that doesn't cross market
            x = new BuyMarket(s, 100);
            Assert.IsFalse(o.Fill(x));

            const string t2 = "trader2";
            // suceed on crossing market
            x = new SellMarket(s,100);
            x.Account = t2;
            Assert.IsTrue(o.Fill(x));

            // fail when accounts are the same
            x = new SellMarket(s, 100);
            x.Account = o.Account;
            Assert.IsFalse(o.Fill(x));


            // fail on match outside of market
            x = new SellLimit(s, 100, 11);
            x.Account = t2;
            Assert.IsFalse(o.Fill(x));

            // succeed on limit cross
            o = new BuyLimit(s, 100, 10);
            x = new SellLimit(s, 100, 10);
            x.Account = t2;
            Assert.IsTrue(o.Fill(x));

            // make sure we can stop cross
            o = new SellStop(s, 100, 10);
            x = new BuyMarket(s, 100);
            x.Account = t2;
            Assert.IsTrue(o.Fill(x));

        }