Пример #1
0
        public Tick[] MultiFireSampleData()
        {
            return(new Tick[] {
                TickImpl.NewTrade(SYM, 10, 100), // get fill for initial position
                TickImpl.NewTrade(SYM, 10, 100),
                TickImpl.NewTrade(SYM, 10, 100),
                TickImpl.NewTrade(SYM, 10, 100),
                TickImpl.NewTrade(SYM, 10, 100),
                TickImpl.NewTrade(SYM, 10.8m, 100),  // new high
                TickImpl.NewTrade(SYM, 10.75m, 100),
                TickImpl.NewTrade(SYM, 11, 100),     // new high
                TickImpl.NewTrade(SYM, 10.50m, 100), // retrace... FLAT!
                TickImpl.NewTrade(SYM, 10.50m, 1),   // not enough to fill flat order
                TickImpl.NewTrade(SYM, 10.50m, 100), // flat order should be completely filled here
                TickImpl.NewTrade(SYM, 10.50m, 100),
                TickImpl.NewTrade(SYM, 10.50m, 100), // want to make sure we are not oversold
                TickImpl.NewTrade(SYM, 10.50m, 100),
                TickImpl.NewTrade(SYM, 10.50m, 100),
                TickImpl.NewTrade(SYM, 10.50m, 100),
                TickImpl.NewTrade(SYM, 10.50m, 200),
                TickImpl.NewTrade(SYM, 10.40m, 200),
                TickImpl.NewTrade(SYM, 10.40m, 200),
                TickImpl.NewTrade(SYM, 10.40m, 200),
                TickImpl.NewTrade(SYM, 9, 100),

                TickImpl.NewTrade(SYM, 9, 100),

                TickImpl.NewTrade(SYM, 9, 100),
            });
        }
Пример #2
0
        public void Fill_RegularLiquidity()
        {
            SimBroker broker = new SimBroker();

            broker.BrokerModel = _trans;
            ForexSecurity tsec = new ForexSecurity(S);

            tsec.LotSize       = 1;
            tsec.OrderStepSize = 1;

            OrderImpl limitBuy  = new OrderImpl(tsec, Direction.Long, 1, 133m);
            OrderImpl limitSell = new OrderImpl(tsec, Direction.Short, 1, 133.5m);
            OrderImpl stopBuy   = new OrderImpl(tsec, Direction.Long, 3, 0, 135.70m);
            OrderImpl stopSell  = new OrderImpl(tsec, Direction.Short, 4, 0, 135.75m);

            PendingOrderImpl plimitBuy  = new PendingOrderImpl(limitBuy);
            PendingOrderImpl plimitSell = new PendingOrderImpl(limitSell);
            PendingOrderImpl pstopBuy   = new PendingOrderImpl(stopBuy);
            PendingOrderImpl pstopSell  = new PendingOrderImpl(stopSell);

            broker.SendOrderStatus(plimitBuy);
            broker.SendOrderStatus(plimitSell);
            broker.SendOrderStatus(pstopBuy);
            broker.SendOrderStatus(pstopSell);

            // OHLC for 6/21/2012 on SPY
            TickImpl openingTick  = TickImpl.NewTrade(S, Util.ToQLDate(DateTime.Now), Util.QL2FT(9, 30, 00, 000), 135.67m, 10670270, "NYS");
            TickImpl endMornTick  = TickImpl.NewTrade(S, Util.ToQLDate(DateTime.Now), Util.QL2FT(12, 00, 00, 000), 135.78m, 10670270, "NYS");
            TickImpl endLunchTick = TickImpl.NewTrade(S, Util.ToQLDate(DateTime.Now), Util.QL2FT(14, 15, 00, 000), 132.33m, 10670270, "NYS");
            TickImpl closingTick  = TickImpl.NewTrade(S, Util.ToQLDate(DateTime.Now), Util.QL2FT(16, 00, 00, 000), 132.44m, 10670270, "NYS");

            broker.Execute(openingTick);
            broker.Execute(endMornTick);
            broker.Execute(endLunchTick);
            broker.Execute(closingTick);

            List <Trade> trades = broker.GetTradeList();

            Assert.True(trades.Count == 4);

            foreach (Trade trade in trades)
            {
                if (trade.Xsize == 1)
                {
                    Assert.Equal(132.33m, trade.Xprice);
                }
                else if (trade.Xsize == 2)
                {
                    Assert.Equal(132.33m, trade.Xprice);
                }
                else if (trade.Xsize == 3)
                {
                    Assert.Equal(135.78m, trade.Xprice);
                }
                else if (trade.Xsize == 4)
                {
                    Assert.Equal(135.78m, trade.Xprice);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// fill bars with arbitrary price data for a symbol
        /// </summary>
        /// <param name="sym"></param>
        /// <param name="prices"></param>
        /// <param name="startdate"></param>
        /// <param name="starttime"></param>
        /// <param name="blt"></param>
        /// <param name="interval"></param>
        /// <returns></returns>
        public static bool Backfillbars(string sym, decimal[] prices, int startdate, int starttime, ref BarListTrackerImpl blt, int interval)
        {
            // ensure we have closing data
            if (prices.Length == 0)
            {
                Log.Debug(sym + " no price data provided/available, will have to wait until bars are created from market.");
                return(false);
            }
            // make desired numbers of ticks
            DateTime      n   = Util.ToDateTime(startdate, starttime);
            bool          ok  = true;
            List <string> bfd = new List <string>();

            for (int i = prices.Length - 1; i >= 0; i--)
            {
                // get time now - exitlen*60
                var  ndt = n.Subtract(new TimeSpan(0, i * interval, 0));
                int  nt  = Util.ToQLTime(ndt);
                int  nd  = Util.ToQLDate(ndt);
                Tick k   = TickImpl.NewTrade(sym, nd, nt, prices[i], 100, string.Empty);
                ok &= k.IsValid && k.IsTrade;
                bfd.Add(nd + nt.ToString() + "=" + prices[i]);
                if (i <= 2)
                {
                    Log.Debug(nd + " " + nt);
                }
                blt.NewTick(k);
            }
            if (ok)
            {
                Log.Debug("{0} bars backfilled using: {1} bars", sym, bfd.Count);
            }
            return(ok);
        }
Пример #4
0
        public void StaticFactories()
        {
            // factory inputs
            const string  s = "TST";
            const decimal p = 13m;
            const int     z = 400;

            // produce a new ask tick
            TickImpl t = TickImpl.NewAsk(s, p, z);

            Assert.That(t.hasAsk && !t.hasBid, t.ToString());
            Assert.That(t.ask == p, t.ask.ToString());
            Assert.That(t.AskSize == z, t.AskSize.ToString());
            Assert.That(t.os == (int)(z / 100), t.os.ToString());
            Assert.That(t.symbol == s);

            // produce bid tick
            t = TickImpl.NewBid(s, p, z);
            Assert.That(t.hasBid && !t.hasAsk, t.ToString());
            Assert.That(t.bid == p, t.bid.ToString());
            Assert.That(t.BidSize == z, t.BidSize.ToString());
            Assert.That(t.bs == (int)(z / 100), t.bs.ToString());
            Assert.That(t.symbol == s);

            // produce a trade tick
            t = TickImpl.NewTrade(s, p, z);
            Assert.That(t.isTrade && !t.isQuote, t.ToString());
            Assert.That(t.trade == p, t.trade.ToString());
            Assert.That(t.TradeSize == z, t.TradeSize.ToString());
            Assert.That(t.ts == (int)(z / 100), t.ts.ToString());
            Assert.That(t.symbol == s);
        }
Пример #5
0
        public void StaticFactories()
        {
            // factory inputs
            const string  s = "TST";
            const decimal p = 13m;
            const int     z = 400;

            // produce a new ask tick
            TickImpl t = TickImpl.NewAsk(s, p, z);

            Assert.True(t.HasAsk && !t.HasBid, t.ToString());
            Assert.True(t.Ask == p, t.Ask.ToString());
            Assert.True(t.AskSize == z, t.AskSize.ToString());
            Assert.True(t.OfferSize == z, t.OfferSize.ToString());
            Assert.True(t.Symbol == s);

            // produce bid tick
            t = TickImpl.NewBid(s, p, z);
            Assert.True(t.HasBid && !t.HasAsk, t.ToString());
            Assert.True(t.Bid == p, t.Bid.ToString());
            Assert.True(t.BidSize == z, t.BidSize.ToString());
            Assert.True(t.BidSize == z, t.BidSize.ToString());
            Assert.True(t.Symbol == s);

            // produce a trade tick
            t = TickImpl.NewTrade(s, p, z);
            Assert.True(t.IsTrade && !t.IsQuote, t.ToString());
            Assert.True(t.Trade == p, t.Trade.ToString());
            Assert.True(t.TradeSize == z, t.TradeSize.ToString());
            Assert.True(t.Ts == z, t.Ts.ToString());
            Assert.True(t.Symbol == s);
        }
Пример #6
0
        public void FixSentOnUnknown()
        {
            // reset everything
            id = 1;
            o  = new OrderImpl();
            ot = new OrderTracker();
            ot.SendDebugEvent      += new DebugDelegate(ot_SendDebugEvent);
            ot.VerboseDebugging     = true;
            ot.FixSentSizeOnUnknown = true;

            // verify no size/pending/cancel
            Assert.AreEqual(0, ot.Sent(id), "sent but not sent");
            Assert.IsFalse(ot.isCompleted(id), "completed but not sent");
            Assert.IsFalse(ot.isCanceled(id), "wrongly canceled");
            Assert.IsFalse(ot.isPending(id), "wrongly pending");
            Assert.IsFalse(ot.isTracked(id), "wrongly tracked");
            // prepare a buy order
            o = new BuyLimit(sym, 100, 100, id++);
            // fill it
            Assert.IsTrue(o.Fill(TickImpl.NewTrade(sym, 100, 100)), "order did not fill");
            ot.GotFill((Trade)o);
            // order will be invalid since it was sent previously (or unknown)
            Assert.False(ot.SentOrder(id - 1).isValid, "valid order was found, none was sent though");
            // verify size/pending/cancel
            Assert.AreEqual(100, ot.Sent(id - 1), "not sent buy");
            Assert.AreEqual(100, ot.Filled(id - 1), "incorrect fill size buy");
            Assert.IsTrue(ot.isCompleted(id - 1), "wrongly not filled");
            Assert.IsFalse(ot.isCanceled(id - 1), "wrongly canceled");
            Assert.IsFalse(ot.isPending(id - 1), "wrongly pending");
            Assert.IsTrue(ot.isTracked(id - 1), "not tracked");
        }
Пример #7
0
        public void Serialization()
        {
            const string  t    = "TST";
            const decimal p    = 10m;
            const int     s    = 300;
            const int     date = 20080702;
            const int     time = 93503;
            TickImpl      pre  = TickImpl.NewTrade(t, p, s);

            pre.time  = time;
            pre.date  = date;
            pre.bid   = p;
            pre.ask   = p;
            pre.os    = s;
            pre.bs    = s;
            pre.ex    = t;
            pre.be    = t;
            pre.oe    = t;
            pre.depth = 5;
            string serialize = TickImpl.Serialize(pre);
            Tick   post      = TickImpl.Deserialize(serialize);

            Assert.That(post.time == pre.time, post.time.ToString());
            Assert.That(post.date == pre.date);
            Assert.That(post.bs == pre.bs);
            Assert.That(post.bid == pre.bid);
            Assert.That(post.ask == pre.ask);
            Assert.That(post.os == pre.os);
            Assert.That(post.ex == pre.ex);
            Assert.That(post.be == pre.be);
            Assert.That(post.oe == pre.oe);
            Assert.That(post.depth == pre.depth);
        }
Пример #8
0
        public void DayFill()
        {
            SimBroker broker = new SimBroker();

            broker.BrokerModel = _trans;
            ForexSecurity tsec = new ForexSecurity(S);

            tsec.LotSize       = 1;
            tsec.OrderStepSize = 1;

            OrderImpl        day  = new OrderImpl(tsec, Direction.Long, 200);
            PendingOrderImpl pday = new PendingOrderImpl(day);

            broker.SendOrderStatus(pday);

            TickImpl openingTick  = TickImpl.NewTrade(S, Util.ToQLDate(DateTime.Now), Util.QL2FT(9, 30, 00, 000), 9, 10000, "NYS");
            TickImpl endMornTick  = TickImpl.NewTrade(S, Util.ToQLDate(DateTime.Now), Util.QL2FT(12, 00, 00, 000), 9, 10000, "NYS");
            TickImpl endLunchTick = TickImpl.NewTrade(S, Util.ToQLDate(DateTime.Now), Util.QL2FT(14, 15, 00, 000), 9, 10000, "NYS");
            TickImpl closingTick  = TickImpl.NewTrade(S, Util.ToQLDate(DateTime.Now), Util.QL2FT(16, 00, 00, 000), 9, 10000, "NYS");

            int c;

            c = broker.Execute(openingTick); Assert.Equal(1, c); // should execute on first received tick
            c = broker.Execute(endMornTick); Assert.Equal(0, c);
            c = broker.Execute(endLunchTick); Assert.Equal(0, c);
            c = broker.Execute(closingTick); Assert.Equal(0, c);
        }
Пример #9
0
        public void BasicStopAndLimit()
        {
            long id = 1;

            sho = new REGSHO_ShortTracker();
            sho.SendDebugEvent  += new DebugDelegate(rt.d);
            sho.VerboseDebugging = true;
            Order o = new OrderImpl();

            // take a position
            o         = new BuyLimit(sym, 100, 21.18m, id++);
            o.Account = ACCT;
            Assert.IsFalse(sho.isOrderShort(o), "entry buy never a short.");
            sho.GotOrder(o);
            Assert.IsTrue(o.Fill(TickImpl.NewTrade(sym, 21.14m, 100)), "unable to fill order");
            Trade t = (Trade)o;

            Assert.IsTrue(t.isValid && t.isFilled, "not a valid trade");
            sho.GotFill(t);


            // accept two exits
            o         = new SellStop(sym, 100, 21.09m, id++);
            o.Account = ACCT;
            Assert.IsFalse(sho.isOrderShort(o), "first exit was wrongly a short");
            sho.GotOrder(o);
            o         = new SellLimit(sym, 100, 21.19m, id++);
            o.Account = ACCT;
            Assert.IsTrue(sho.isOrderShort(o), "second exit was wrongly a sell");
            sho.GotOrder(o);
        }
Пример #10
0
        public void MOCs()
        {
            SimBroker broker = new SimBroker();

            broker.BrokerModel = _trans;
            ForexSecurity tsec = new ForexSecurity(S);

            tsec.LotSize       = 1;
            tsec.OrderStepSize = 1;

            OrderImpl moc = new OrderImpl(tsec, Direction.Long, 200);

            moc.ValidInstruct = OrderInstructionType.MOC;
            PendingOrderImpl pmoc = new PendingOrderImpl(moc);

            Assert.True(moc.ValidInstruct == OrderInstructionType.MOC, "unexpected order instruction: " + moc.ValidInstruct);
            Assert.Equal(0, broker.SendOrderStatus(pmoc));

            TickImpl openingTick  = TickImpl.NewTrade(S, Util.ToQLDate(DateTime.Now), Util.QL2FT(9, 30, 00, 000), 9, 10000, "NYS");
            TickImpl endMornTick  = TickImpl.NewTrade(S, Util.ToQLDate(DateTime.Now), Util.QL2FT(12, 00, 00, 000), 9, 10000, "NYS");
            TickImpl endLunchTick = TickImpl.NewTrade(S, Util.ToQLDate(DateTime.Now), Util.QL2FT(14, 15, 00, 000), 9, 10000, "NYS");
            TickImpl closingTick  = TickImpl.NewTrade(S, Util.ToQLDate(DateTime.Now), Util.QL2FT(16, 00, 00, 000), 9, 10000, "NYS");

            int c = 0;

            c = broker.Execute(openingTick); Assert.Equal(0, c);
            c = broker.Execute(endMornTick); Assert.Equal(0, c);
            c = broker.Execute(endLunchTick); Assert.Equal(0, c);
            c = broker.Execute(closingTick); Assert.Equal(1, c); // should execute on the first tick at/after 16:00:00
        }
Пример #11
0
        public void IOC()
        {
            // reset everything
            reset();
            // we'll use quotes to enforce tighter tifs
            tks.IOCMode();
            Assert.IsTrue(tks.IgnoreQuotes, "ignore quotes should be true when ioc mode is enabled");
            // verify we haven't done anything
            Assert.IsFalse(lasto.isValid, "order was sent prior to doing anything");
            Assert.AreEqual(0, lastcancel, "cancel sent prior to doing anything");

            // send order with tif
            tks.SendOrderTIF(new BuyLimit(sym, 100, p), 1);
            // verify received
            Assert.IsTrue(lasto.isValid, "order not sent");
            // send some ticks
            tks.newTick(TickImpl.NewBid(sym, p, 100));
            tks.newTick(TickImpl.NewBid(sym, p, 100));
            tks.newTick(TickImpl.NewBid(sym, p, 100));
            tks.newTick(TickImpl.NewBid(sym, p, 100));
            tks.newTick(TickImpl.NewAsk(sym, p, 100));
            // verify no cancel
            Assert.AreEqual(0, lastcancel, "cancel was sent prior to tif expiration");
            tks.newTick(TickImpl.NewTrade(sym, p, 100));
            // verify cancel
            Assert.AreNotEqual(0, lastcancel, "cancel was NOT sent after tif expiration");
        }
Пример #12
0
        public void Serialization()
        {
            const string  t    = "TST";
            const decimal p    = 10m;
            const int     s    = 300;
            const int     date = 20080702;
            const int     time = 93503;
            TickImpl      pre  = TickImpl.NewTrade(t, p, s);

            pre.Time        = time;
            pre.Date        = date;
            pre.Bid         = p;
            pre.Ask         = p;
            pre.OfferSize   = s;
            pre.BidSize     = s;
            pre.Exchange    = t;
            pre.BidExchange = t;
            pre.AskExchange = t;
            pre.Depth       = 5;
            string serialize = TickImpl.Serialize(pre);
            Tick   post      = TickImpl.Deserialize(serialize);

            Assert.True(post.Time == pre.Time, post.Time.ToString());
            Assert.True(post.Date == pre.Date);
            Assert.True(post.BidSize == pre.BidSize);
            Assert.True(post.Bid == pre.Bid);
            Assert.True(post.Ask == pre.Ask);
            Assert.True(post.AskSize == pre.OfferSize);
            Assert.True(post.Exchange == pre.Exchange);
            Assert.True(post.BidExchange == pre.BidExchange);
            Assert.True(post.AskExchange == pre.AskExchange);
            Assert.True(post.Depth == pre.Depth);
        }
Пример #13
0
        public override void TradePrint(TradeInfo oInfo)
        {
            Tick k = TickImpl.NewTrade(oInfo.Symbol, (decimal)oInfo.Price, oInfo.Size);

            k.ex   = oInfo.Exchange;
            k.date = Util.ToTLDate();
            k.time = Util.ToTLTime();
            tl.newTick(k);
        }
Пример #14
0
        public void Basics()
        {
            const string sym = "TST";
            const int    d   = 20080509;
            const int    t   = 93500;
            const string x   = "NYSE";

            TickImpl[] ticklist = new TickImpl[] {
                TickImpl.NewTrade(sym, d, t, 10, 100, x),
                TickImpl.NewTrade(sym, d, t + 100, 10, 100, x),
                TickImpl.NewTrade(sym, d, t + 200, 10, 100, x),
                TickImpl.NewTrade(sym, d, t + 300, 10, 100, x),
                TickImpl.NewTrade(sym, d, t + 400, 15, 100, x),  // blade up
                TickImpl.NewTrade(sym, d, t + 500, 16, 100, x),  // new bar (blades reset)
                TickImpl.NewTrade(sym, d, t + 600, 16, 100, x),
                TickImpl.NewTrade(sym, d, t + 700, 10, 100, x),  // blade down
                TickImpl.NewTrade(sym, d, t + 700, 10, 100, x),  // still a blade down (same bar)
                TickImpl.NewTrade(sym, d, t + 800, 15, 100, x),
                TickImpl.NewTrade(sym, d, t + 1500, 15, 800, x), // volume spike
                TickImpl.NewTrade(sym, d, t + 2000, 15, 100, x),
                TickImpl.NewTrade(sym, d, t + 2500, 15, 100, x),
            };

            BarListImpl bl = new BarListImpl(BarInterval.FiveMin, sym);
            Blade       b  = new Blade();

            Assert.That(b.BladePercentage != 0);
            b = new Blade(.2m); // 20 percent move is a blade
            int up = 0, down = 0, newbar = 0, bigvol = 0;

            foreach (TickImpl k in ticklist)
            {
                bl.newTick(k);
                b.newBar(bl);
                if (bl.NewBar)
                {
                    newbar++;
                }
                if (b.isBladeUP)
                {
                    up++;
                }
                if (b.isBladeDOWN)
                {
                    down++;
                }
                if (b.isBigVolume)
                {
                    bigvol++;
                }
            }

            Assert.AreEqual(1, up);
            Assert.AreEqual(2, down);
            Assert.AreEqual(5, newbar);
            Assert.AreEqual(1, bigvol);
        }
Пример #15
0
 public Tick[] SampleData()
 {
     return(new Tick[] {
         TickImpl.NewTrade(SYM, 10, 100),
         TickImpl.NewTrade(SYM, 10, 100),
         TickImpl.NewTrade(SYM, 10, 100),
         TickImpl.NewTrade(SYM, 11, 100),     // new high
         TickImpl.NewTrade(SYM, 10.50m, 100), // retrace
     });
 }
Пример #16
0
        public void PartialFill()
        {
            // reset everything
            id = 1;
            o  = new OrderImpl();
            ot = new OrderTracker();
            ot.SendDebugEvent  += new DebugDelegate(ot_SendDebugEvent);
            ot.VerboseDebugging = true;

            // verify no size/pending/cancel
            Assert.AreEqual(0, ot.Sent(id), "sent but not sent");
            Assert.IsFalse(ot.isCompleted(id), "completed but not sent");
            Assert.IsFalse(ot.isCanceled(id), "wrongly canceled");
            Assert.IsFalse(ot.isPending(id), "wrongly pending");
            Assert.IsFalse(ot.isTracked(id), "wrongly tracked");
            // send a buy order
            o = new BuyLimit(sym, 200, 100, id++);
            ot.GotOrder(o);
            // fill it
            Assert.IsTrue(o.Fill(TickImpl.NewTrade(sym, 100, 100)), "order did not fill");
            ot.GotFill((Trade)o);
            // verify order is there
            Assert.IsTrue(ot.SentOrder(id - 1).isValid, "no valid order");
            // verify size/pending/cancel
            Assert.AreEqual(200, ot.Sent(id - 1), "not sent buy");
            Assert.AreEqual(100, ot.Filled(id - 1), "incorrect fill size buy");
            Assert.IsFalse(ot.isCompleted(id - 1), "wrongly completed");
            Assert.IsFalse(ot.isCanceled(id - 1), "wrongly canceled");
            Assert.IsTrue(ot.isPending(id - 1), "wrongly pending");
            Assert.IsTrue(ot.isTracked(id - 1), "not tracked");

            // do sell order

            // verify no size/pending/cancel
            Assert.AreEqual(0, ot.Sent(id), "sent but not sent");
            Assert.IsFalse(ot.isCompleted(id), "completed but not sent");
            Assert.IsFalse(ot.isCanceled(id), "wrongly canceled");
            Assert.IsFalse(ot.isPending(id), "wrongly pending");
            Assert.IsFalse(ot.isTracked(id), "wrongly tracked");
            // send sell order
            o = new SellLimit(sym, 200, 100, id++);
            ot.GotOrder(o);
            // fill it
            Assert.IsTrue(o.Fill(TickImpl.NewTrade(sym, 100, 100)), "order did not fill");
            ot.GotFill((Trade)o);
            // verify order is there
            Assert.IsTrue(ot.SentOrder(id - 1).isValid, "no valid order");
            // verify size/pending/cancel
            Assert.AreEqual(-100, ot.Filled(id - 1), "incorrect fill size sell");
            Assert.AreEqual(-200, ot.Sent(id - 1), "not sent sell");
            Assert.IsFalse(ot.isCompleted(id - 1), "wrongly completed");
            Assert.IsFalse(ot.isCanceled(id - 1), "wrongly canceled");
            Assert.IsTrue(ot.isPending(id - 1), "wrongly pending");
            Assert.IsTrue(ot.isTracked(id - 1), "not tracked");
        }
Пример #17
0
        public void TikTypes()
        {
            // get symbol
            string sym = Research.RandomSymbol.GetSymbol((int)DateTime.Now.Ticks);

            // prepare data
            List <Tick> data = new List <Tick>();

            // bid
            data.Add(TickImpl.NewBid(sym, 10, 100));

            // ask
            data.Add(TickImpl.NewAsk(sym, 11, 200));

            // full quote
            data.Add(TickImpl.NewQuote(sym, Date, 93000, 10, 11, 300, 300, "NYSE", "ARCA"));

            // trade
            data.Add(TickImpl.NewTrade(sym, Date, 93100, 10, 400, "NYSE"));

            // full tick
            Tick full = TickImpl.Copy((TickImpl)data[2], (TickImpl)data[3]);

            data.Add(full);

            // write and read the data
            Writeandread(data.ToArray(), Date, false);

            //verify the count
            Assert.Equal(data.Count, _readdata.Count);

            // verify the data
            bool          equal = true;
            StringBuilder sb    = new StringBuilder(string.Empty);

            for (int i = 0; i < data.Count; i++)
            {
                bool start = equal;
                equal &= data[i].Bid == _readdata[i].Bid;
                equal &= data[i].BidSize == _readdata[i].BidSize;
                equal &= data[i].BidSource == _readdata[i].BidSource;
                equal &= data[i].Ask == _readdata[i].Ask;
                equal &= data[i].AskSize == _readdata[i].AskSize;
                equal &= data[i].AskSource == _readdata[i].AskSource;
                equal &= data[i].Trade == _readdata[i].Trade;
                equal &= data[i].Size == _readdata[i].Size;
                equal &= data[i].Source == _readdata[i].Source;
                equal &= data[i].Depth == _readdata[i].Depth;
                if (equal != start)
                {
                    sb.Append(i + " ");
                }
            }
            Assert.True(equal, "bad ticks: " + sb + data[0] + _readdata[0]);
        }
        public void TestBidAsk()
        {
            ptt   = new PapertradeTracker();
            pt    = new PositionTracker();
            fills = 0;
            const string SYM = "TST";

            ptt.SendDebugEvent += new DebugDelegate(debug);
            ptt.GotFillEvent   += new FillDelegate(ptt_GotFillEvent);
            ptt.GotOrderEvent  += new OrderDelegate(ptt_GotOrderEvent);
            // enable bid ask fills
            ptt.UseBidAskFills = true;
            // send an order
            ptt.sendorder(new BuyMarket(SYM, 1000));
            // verify it did not fill
            Assert.AreEqual(0, pt[SYM].Size);
            // send a tick
            ptt.newTick(TickImpl.NewTrade(SYM, 10, 100));
            // verify it did not fill
            Assert.AreEqual(0, pt[SYM].Size);
            // send bid
            ptt.newTick(TickImpl.NewBid(SYM, 10, 100));
            // verify it did not fill
            Assert.AreEqual(0, pt[SYM].Size);
            // send ask
            ptt.newTick(TickImpl.NewAsk(SYM, 12, 100));
            // verify it fills
            Assert.AreEqual(100, pt[SYM].Size);
            Assert.AreEqual(1, fills);
            // fill rest of the order
            ptt.newTick(TickImpl.NewAsk(SYM, 12, 100));
            ptt.newTick(TickImpl.NewAsk(SYM, 12, 100));
            ptt.newTick(TickImpl.NewAsk(SYM, 12, 100));
            ptt.newTick(TickImpl.NewAsk(SYM, 12, 100));
            ptt.newTick(TickImpl.NewAsk(SYM, 12, 100));
            ptt.newTick(TickImpl.NewAsk(SYM, 12, 100));
            ptt.newTick(TickImpl.NewAsk(SYM, 12, 100));
            ptt.newTick(TickImpl.NewAsk(SYM, 12, 100));
            ptt.newTick(TickImpl.NewAsk(SYM, 12, 100));
            Assert.AreEqual(10, fills);
            Assert.AreEqual(1000, pt[SYM].Size);
            // send a bunch more ticks and ensure nothing else is filled
            ptt.newTick(TickImpl.NewAsk(SYM, 12, 100));
            ptt.newTick(TickImpl.NewAsk(SYM, 12, 100));
            ptt.newTick(TickImpl.NewAsk(SYM, 12, 100));
            ptt.newTick(TickImpl.NewAsk(SYM, 12, 100));
            ptt.newTick(TickImpl.NewAsk(SYM, 12, 100));
            ptt.newTick(TickImpl.NewAsk(SYM, 12, 100));
            ptt.newTick(TickImpl.NewAsk(SYM, 12, 100));
            Assert.AreEqual(0, ptt.QueuedOrders.Length);
            Assert.AreEqual(10, fills);
            Assert.AreEqual(1000, pt[SYM].Size);
        }
Пример #19
0
        public void Basics()
        {
            Broker broker = new Broker();

            broker.GotFill  += new FillDelegate(broker_GotFill);
            broker.GotOrder += new OrderDelegate(broker_GotOrder);
            OrderImpl o     = new OrderImpl();
            int       error = broker.SendOrderStatus(o);

            Assert.AreNotEqual((int)MessageTypes.OK, error);
            Assert.That(orders == 0);
            Assert.That(fills == 0);
            o = new BuyMarket(s, 100);
            broker.SendOrderStatus(o);
            Assert.That(orders == 1);
            Assert.That(fills == 0);
            Assert.That(broker.Execute(TickImpl.NewTrade(s, 10, 200)) == 1);
            Assert.That(fills == 1);

            // test that a limit order is not filled outside the market
            o = new BuyLimit(s, 100, 9);
            broker.SendOrderStatus(o);
            Assert.AreEqual(0, broker.Execute(TickImpl.NewTrade(s, 10, 100)));
            Assert.That(fills == 1); // redudant but for counting

            // test that limit order is filled inside the market
            Assert.AreEqual(1, broker.Execute(TickImpl.NewTrade(s, 8, 100)));
            Assert.That(fills == 2);

            OrderImpl x = new OrderImpl();

            // test that a market order is filled when opposite book exists
            o = new SellLimit(s, 100, 11);
            x = new BuyMarket(s, 100);
            const string t2 = "trader2";

            x.Account = t2;
            broker.SendOrderStatus(o);
            broker.SendOrderStatus(x);
            Assert.AreEqual(3, fills);

            // test that a market order is not filled when no book exists
            // on opposite side

            // clear existing orders
            broker.CancelOrders();
            o         = new SellMarket(s, 100);
            o.Account = t2;
            broker.SendOrderStatus(o);
            Assert.AreEqual(3, fills);
        }
Пример #20
0
        public void Fill_HighLiquidity()
        {
            Broker broker = new Broker();

            broker.UseHighLiquidityFillsEOD = true;
            const string s         = "SPY";
            OrderImpl    limitBuy  = new LimitOrder(s, true, 1, 133m);
            OrderImpl    limitSell = new LimitOrder(s, false, 2, 133.5m);
            OrderImpl    stopBuy   = new StopOrder(s, true, 3, 135.70m);
            OrderImpl    stopSell  = new StopOrder(s, false, 4, 135.75m);

            broker.SendOrderStatus(limitBuy);
            broker.SendOrderStatus(limitSell);
            broker.SendOrderStatus(stopBuy);
            broker.SendOrderStatus(stopSell);

            // OHLC for 6/21/2012 on SPY
            TickImpl openingTick  = TickImpl.NewTrade(s, Util.ToTLDate(DateTime.Now), Util.TL2FT(9, 30, 00), 135.67m, 10670270, "NYS");
            TickImpl endMornTick  = TickImpl.NewTrade(s, Util.ToTLDate(DateTime.Now), Util.TL2FT(12, 00, 00), 135.78m, 10670270, "NYS");
            TickImpl endLunchTick = TickImpl.NewTrade(s, Util.ToTLDate(DateTime.Now), Util.TL2FT(14, 15, 00), 132.33m, 10670270, "NYS");
            TickImpl closingTick  = TickImpl.NewTrade(s, Util.ToTLDate(DateTime.Now), Util.TL2FT(16, 00, 00), 132.44m, 10670270, "NYS");

            broker.Execute(openingTick);
            broker.Execute(endMornTick);
            broker.Execute(endLunchTick);
            broker.Execute(closingTick);

            List <Trade> trades = broker.GetTradeList();

            Assert.IsTrue(trades.Count == 4);

            foreach (Trade trade in trades)
            {
                if (trade.xsize == 1)
                {
                    Assert.AreEqual(133m, trade.xprice);
                }
                else if (trade.xsize == 2)
                {
                    Assert.AreEqual(133.5m, trade.xprice);
                }
                else if (trade.xsize == 3)
                {
                    Assert.AreEqual(135.7m, trade.xprice);
                }
                else if (trade.xsize == 4)
                {
                    Assert.AreEqual(135.75m, trade.xprice);
                }
            }
        }
Пример #21
0
        public void FillBidAsk()
        {
            string s = security.Name;
            // market should fill on trade but not on quote
            OrderImpl o = new OrderImpl(security, Direction.Long, 100);

            Assert.True(o.FillBidAsk(TickImpl.NewAsk(s, 9, 100), trans) == StatusType.ORDER_FILLED);
            Assert.True(o.FillBidAsk(TickImpl.NewTrade(s, 9, 100), trans) == StatusType.OFF_QUOTES);
            Assert.True(o.FillBidAsk(TickImpl.NewBid(s, 8, 100), trans) == StatusType.OFF_QUOTES);

            // buy limit

            // limit should fill if order price is inside market
            o = new OrderImpl(security, Direction.Long, 100, 10m);
            Assert.True(o.FillBidAsk(TickImpl.NewAsk(s, 9, 100), trans) == StatusType.ORDER_FILLED);
            // shouldn't fill outside market
            o = new OrderImpl(security, Direction.Long, 100, 10m);
            Assert.True(o.FillBidAsk(TickImpl.NewTrade(s, 11, 100), trans) == StatusType.OFF_QUOTES);
            Assert.True(o.FillBidAsk(TickImpl.NewAsk(s, 11, 100), trans) == StatusType.OK);
            Assert.True(o.FillBidAsk(TickImpl.NewBid(s, 10, 100), trans) == StatusType.OFF_QUOTES);

            // sell limit

            // limit should fill if order price is inside market
            o = new OrderImpl(security, Direction.Short, 100, 10m);
            Assert.True(o.FillBidAsk(TickImpl.NewBid(s, 11, 100), trans) == StatusType.ORDER_FILLED);
            // shouldn't fill outside market
            o = new OrderImpl(security, Direction.Short, 100, 10m);
            Assert.True(o.FillBidAsk(TickImpl.NewTrade(s, 9, 100), trans) == StatusType.OFF_QUOTES);

            // buy stop

            o = new OrderImpl(security, Direction.Long, 100, 0, 10m);
            Assert.True(o.Type == OrderType.Stop);
            Assert.True(o.FillBidAsk(TickImpl.NewAsk(s, 11, 100), trans) == StatusType.ORDER_FILLED);
            // shouldn't fill outside market
            o = new OrderImpl(security, Direction.Long, 100, 0, 10m);
            Assert.True(o.FillBidAsk(TickImpl.NewTrade(s, 9, 100), trans) == StatusType.OFF_QUOTES);

            // sell stop

            o = new OrderImpl(security, Direction.Short, 100, 0, 10m);
            Assert.True(o.FillBidAsk(TickImpl.NewBid(s, 9, 100), trans) == StatusType.ORDER_FILLED);
            // shouldn't fill outside market
            o = new OrderImpl(security, Direction.Short, 100, 0, 10m);
            Assert.True(o.FillBidAsk(TickImpl.NewTrade(s, 11, 100), trans) == StatusType.OFF_QUOTES);

            // always fail filling an invalid tick
            o = new OrderImpl(security, Direction.Long, 100);
            Assert.True(o.FillBidAsk(TickImpl.NewTrade(s, 0, 0), trans) == StatusType.OFF_QUOTES);
        }
Пример #22
0
        public void FillBidAsk()
        {
            const string s = "TST";
            // market should fill on trade but not on quote
            OrderImpl o = new BuyMarket(s, 100);

            Assert.That(o.FillBidAsk(TickImpl.NewAsk(s, 9, 100)));
            Assert.That(!o.FillBidAsk(TickImpl.NewTrade(s, 9, 100)));
            Assert.That(!o.FillBidAsk(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.FillBidAsk(TickImpl.NewAsk(s, 9, 100)));
            // shouldn't fill outside market
            o = new BuyLimit(s, 100, 10m);
            Assert.That(!o.FillBidAsk(TickImpl.NewTrade(s, 11, 100)));
            Assert.That(!o.FillBidAsk(TickImpl.NewAsk(s, 11, 100)));
            Assert.That(!o.FillBidAsk(TickImpl.NewBid(s, 10, 100)));

            // sell limit

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

            // buy stop

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

            // sell stop

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

            // always fail filling an invalid tick
            o = new BuyMarket(s, 100);
            Assert.IsFalse(o.FillBidAsk(TickImpl.NewTrade(s, 0, 0)));
        }
Пример #23
0
        public void FillThenStopAndLimitOversell()
        {
            long id = 1;

            sho = new REGSHO_ShortTracker();
            sho.SendDebugEvent  += new DebugDelegate(rt.d);
            sho.VerboseDebugging = true;
            lastids.Clear();
            Order o = new OrderImpl();

            // send some initial orders
            so(new SellLimit(sym, 100, 25.83m, id++));
            so(new SellStop(sym, 100, 25.83m, id++));
            o = new SellStop(sym, 200, 25.83m, id++);
            so(o);
            // cancel first two orders
            sho.GotCancel(lastids[0]);
            sho.GotCancel(lastids[1]);
            // fill last order
            Assert.IsTrue(o.Fill(TickImpl.NewTrade(sym, 25.80m, 200)), "missing initial fill");
            sho.GotFill((Trade)o);
            // check pending size
            Assert.AreEqual(0, pendingsize(sym), "had pending size after cancels and fills");
            // flat position
            sho.GotPosition(new PositionImpl(sym, 0, 0, 0, ACCT));



            // take a position
            o         = new BuyLimit(sym, 100, 25.83m, id++);
            o.Account = ACCT;
            Assert.IsFalse(sho.isOrderShort(o), "entry buy never a short.");
            sho.GotOrder(o);
            Assert.IsTrue(o.Fill(TickImpl.NewTrade(sym, 25.80m, 100)), "unable to fill order");
            Trade t = (Trade)o;

            Assert.IsTrue(t.isValid && t.isFilled, "not a valid trade");
            sho.GotFill(t);


            // accept two exits
            o         = new SellStop(sym, 100, 21.09m, id++);
            o.Account = ACCT;
            Assert.IsFalse(sho.isOrderShort(o), "first exit was wrongly a short");
            sho.GotOrder(o);
            o         = new SellLimit(sym, 100, 21.19m, id++);
            o.Account = ACCT;
            Assert.IsTrue(sho.isOrderShort(o), "second exit was wrongly a sell");
            sho.GotOrder(o);
        }
Пример #24
0
        public void DataProvider()
        {
            TickImpl t = TickImpl.NewTrade(s, 10, 700);
            // feature to pass-through ticks to any subscriber
            // this can be connected to tradelink library to allow filtered subscribptions
            // and interapplication communication
            Broker broker = new Broker();

            broker.GotTick += new TickDelegate(broker_GotTick);
            Assert.That((receivedtickDP == null) && (gottickDP == 0));
            broker.Execute(t); // should fire a gotTick
            Assert.That(gottickDP != 0);
            Assert.That((receivedtickDP != null) && (receivedtickDP.trade == t.trade));
        }
Пример #25
0
        public void TikTypes()
        {
            // get symbol
            string SYM = TradeLink.Research.RandomSymbol.GetSymbol((int)DateTime.Now.Ticks);

            // prepare data
            System.Collections.Generic.List <Tick> data = new List <Tick>();
            // bid
            data.Add(TickImpl.NewBid(SYM, 10, 100));
            // ask
            data.Add(TickImpl.NewAsk(SYM, 11, 200));
            // full quote
            data.Add(TickImpl.NewQuote(SYM, DATE, 93000, 10, 11, 300, 300, "NYSE", "ARCA"));
            // trade
            data.Add(TickImpl.NewTrade(SYM, DATE, 93100, 10, 400, "NYSE"));
            // full tick
            Tick full = TickImpl.Copy((TickImpl)data[2], (TickImpl)data[3]);

            data.Add(full);

            // write and read the data
            writeandread(data.ToArray(), DATE, false);

            //verify the count
            Assert.AreEqual(data.Count, readdata.Count);

            // verify the data
            bool equal = true;

            System.Text.StringBuilder sb = new StringBuilder(string.Empty);
            for (int i = 0; i < data.Count; i++)
            {
                bool start = equal;
                equal &= data[i].bid == readdata[i].bid;
                equal &= data[i].bs == readdata[i].bs;
                equal &= data[i].be == readdata[i].be;
                equal &= data[i].ask == readdata[i].ask;
                equal &= data[i].os == readdata[i].os;
                equal &= data[i].oe == readdata[i].oe;
                equal &= data[i].trade == readdata[i].trade;
                equal &= data[i].size == readdata[i].size;
                equal &= data[i].ex == readdata[i].ex;
                equal &= data[i].depth == readdata[i].depth;
                if (equal != start)
                {
                    sb.Append(i + " ");
                }
            }
            Assert.IsTrue(equal, "bad ticks: " + sb.ToString() + data[0].ToString() + readdata[0].ToString());
        }
Пример #26
0
        public void OpGs()
        {
            SimBroker broker = new SimBroker();

            broker.BrokerModel = _trans;
            const string  s    = "NYS";
            ForexSecurity tsec = new ForexSecurity(s);

            tsec.LotSize       = 1;
            tsec.OrderStepSize = 1;

            // build and send an OPG order
            OrderImpl        opg  = new OrderImpl(tsec, Direction.Long, 200, 10);
            PendingOrderImpl popg = new PendingOrderImpl(opg);

            Assert.Equal(0, broker.SendOrderStatus(popg));

            // build a tick on another exchange
            TickImpl it = TickImpl.NewTrade(s, 9, 100);

            it.Exchange = "ISLD";

            // fill order (should fail)
            int c = broker.Execute(it);

            Assert.Equal(0, c);

            // build opening price for desired exchange
            TickImpl nt = TickImpl.NewTrade(s, 9, 10000);

            nt.Exchange = "NYS";
            // fill order (should work)

            c = broker.Execute(nt);

            Assert.Equal(1, c);

            // add another OPG, make sure it's not filled with another tick

            TickImpl next = TickImpl.NewTrade(s, 9, 2000);

            next.Exchange = "NYS";

            OrderImpl        late  = new OrderImpl(tsec, Direction.Long, 200, 10);
            PendingOrderImpl plate = new PendingOrderImpl(late);

            broker.SendOrderStatus(plate);
            c = broker.Execute(next);
            Assert.Equal(0, c);
        }
Пример #27
0
        public void MultipleMessages()
        {
            // get some data
            Tick k1 = TickImpl.NewTrade(sym, p, size);

            // encode it
            byte[] data1 = Message.sendmessage(MessageTypes.TICKNOTIFY, TickImpl.Serialize(k1));
            // get some data
            Tick k2 = TickImpl.NewTrade(sym, p * 2, size * 2);

            // encode it
            byte[] data2 = Message.sendmessage(MessageTypes.TICKNOTIFY, TickImpl.Serialize(k2));
            // get some data
            Tick k3 = TickImpl.NewTrade(sym, p * 3, size * 3);

            // encode it
            byte[] data3 = Message.sendmessage(MessageTypes.TICKNOTIFY, TickImpl.Serialize(k3));
            // prepare a continuous bitstream to hold all data
            byte[] streamlike = new byte[data1.Length + data2.Length + data3.Length];
            // roll all data into stream
            Array.Copy(data1, 0, streamlike, 0, data1.Length);
            Array.Copy(data2, 0, streamlike, data1.Length, data2.Length);
            Array.Copy(data3, 0, streamlike, data1.Length + data2.Length, data3.Length);
            // decode all messages from stream
            int offset = 0;

            Message[] msgs = Message.gotmessages(ref streamlike, ref offset);
            // ensure we got correct amount/type
            Assert.AreEqual(3, msgs.Length);
            Assert.AreEqual(MessageTypes.TICKNOTIFY, msgs[0].Type);
            Assert.AreEqual(MessageTypes.TICKNOTIFY, msgs[1].Type);
            Assert.AreEqual(MessageTypes.TICKNOTIFY, msgs[2].Type);
            // decode to ticks
            Tick c1 = TickImpl.Deserialize(msgs[0].Content);
            Tick c2 = TickImpl.Deserialize(msgs[1].Content);
            Tick c3 = TickImpl.Deserialize(msgs[2].Content);

            // verify ticks
            Assert.AreEqual(k1.symbol, c1.symbol, TickImpl.Serialize(k1) + "=>" + TickImpl.Serialize(c1));
            Assert.AreEqual(k1.trade, c1.trade, TickImpl.Serialize(k1) + "=>" + TickImpl.Serialize(c1));
            Assert.AreEqual(k1.size, c1.size, TickImpl.Serialize(k1) + "=>" + TickImpl.Serialize(c1));
            Assert.AreEqual(k2.symbol, c2.symbol, TickImpl.Serialize(k2) + "=>" + TickImpl.Serialize(c2));
            Assert.AreEqual(k2.trade, c2.trade, TickImpl.Serialize(k2) + "=>" + TickImpl.Serialize(c2));
            Assert.AreEqual(k2.size, c2.size, TickImpl.Serialize(k2) + "=>" + TickImpl.Serialize(c2));
            Assert.AreEqual(k3.symbol, c3.symbol, TickImpl.Serialize(k3) + "=>" + TickImpl.Serialize(c3));
            Assert.AreEqual(k3.trade, c3.trade, TickImpl.Serialize(k3) + "=>" + TickImpl.Serialize(c3));
            Assert.AreEqual(k3.size, c3.size, TickImpl.Serialize(k3) + "=>" + TickImpl.Serialize(c3));
            Assert.AreEqual(0, offset);
        }
Пример #28
0
        public void ResendTest2()
        {
            // reset "book" to start from scratch
            reset();

            // SETOFFSET("IBM", 0.03, 0, 1, 0);
            const string  sym   = "IBM";
            const decimal pdist = .03m;
            const decimal pct   = 1;

            ot[sym] = new OffsetInfo(pdist, 0, pct, 0, false, 1);
            Assert.AreEqual(pdist, ot[sym].ProfitDist);
            Assert.AreEqual(pct, ot[sym].ProfitPercent);
            // entry fill
            // 094508: fill: 20100423,94532,IBM,SELL,10,128.85, 0
            fill(new TradeImpl(sym, 128.85m, -10));
            Assert.AreEqual(-10, ot.PositionTracker[sym].Size);
            // profit
            // 094508: sent new profit: 634076112353906253  BUY10 [email protected] [] 634076112353906253
            Assert.AreEqual(1, profits.Count);
            Order profit = profits[0];

            Assert.AreEqual(128.82m, profit.price);
            Assert.AreEqual(10, profit.size);
            // fill profit
            // 094609: fill: 20100423,94632,IBM,BUY,10,128.82, 634076112353906253
            // 094609: IBM hit profit: 634076112353906253
            Assert.IsTrue(profit.Fill(TickImpl.NewTrade(sym, 128.82m, 10)));
            Trade profitfill = (Trade)profit;

            fill(profitfill);

            // we're now flat
            // 094609: IBM now flat.
            Assert.IsTrue(ot.PositionTracker[sym].isFlat);
            // tick
            ot.newTick(TickImpl.NewTrade(sym, 128.82m, 100));
            Assert.AreEqual(0, profits.Count);
            // re-enter
            //094722: fill: 20100423,94746,IBM,SELL,10,128.86, 100947
            fill(new TradeImpl(sym, 128.86m, -10));
            Assert.AreEqual(-10, ot.PositionTracker[sym].Size);
            // we should now have a profit offset
            Assert.AreEqual(1, profits.Count);
            profit = profits[0];
            Assert.AreEqual(128.83m, profit.price);
            Assert.AreEqual(10, profit.size);
        }
Пример #29
0
        public void EncodeDecode()
        {
            // get some data
            Tick k = TickImpl.NewTrade(sym, p, size);

            // encode it
            byte[] data = Message.sendmessage(MessageTypes.TICKNOTIFY, TickImpl.Serialize(k));
            // decode it
            Message m = Message.gotmessage(data);
            Tick    c = TickImpl.Deserialize(m.Content);

            // verify
            Assert.AreEqual(k.symbol, c.symbol, TickImpl.Serialize(k) + "=>" + TickImpl.Serialize(c));
            Assert.AreEqual(k.trade, c.trade, TickImpl.Serialize(k) + "=>" + TickImpl.Serialize(c));
            Assert.AreEqual(k.size, c.size, TickImpl.Serialize(k) + "=>" + TickImpl.Serialize(c));
        }
Пример #30
0
        public void Basics()
        {
            ForexSecurity tsec = new ForexSecurity(S);

            tsec.LotSize       = 1;
            tsec.PipValue      = 1;
            tsec.PipSize       = 1;
            tsec.OrderStepSize = 1;

            SimAccount account = new SimAccount("TEST", "testing", 1000M, 100);

            account.Securities.AddSecurity(tsec);

            SimBroker broker = new SimBroker(account, _trans);

            broker.BrokerModel = _trans;
            broker.GotFill    += broker_GotFill;
            broker.GotOrder   += broker_GotOrder;
            OrderImpl        o  = new OrderImpl();
            PendingOrderImpl po = new PendingOrderImpl(o);
            int error           = broker.SendOrderStatus(po);

            Assert.NotEqual((int)StatusType.OK, error);
            Assert.True(_orders == 0);
            Assert.True(_fills == 0);

            o  = new OrderImpl(tsec, Direction.Long, 100);
            po = new PendingOrderImpl(o);

            broker.SendOrderStatus(po);
            Assert.True(_orders == 1);
            Assert.True(_fills == 0);
            Assert.True(broker.Execute(TickImpl.NewTrade(S, 10, 200)) == 1);
            Assert.True(_fills == 1);

            // test that a limit order is not filled outside the market
            o  = new OrderImpl(tsec, Direction.Long, 100, 9);
            po = new PendingOrderImpl(o);

            broker.SendOrderStatus(po);
            Assert.Equal(0, broker.Execute(TickImpl.NewTrade(S, 10, 100)));
            Assert.True(_fills == 1); // redundant but for counting

            // test that limit order is filled inside the market
            Assert.Equal(1, broker.Execute(TickImpl.NewTrade(S, 8, 100)));
            Assert.True(_fills == 2);
        }