コード例 #1
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);
        }
コード例 #2
0
        public void TestTradeFill()
        {
            ptt = new PapertradeTracker();
            ptt.SendDebugEvent += new DebugDelegate(debug);
            ptt.UseBidAskFills  = false;
            fills = 0;
            pt    = new PositionTracker();
            const string SYM = "TST";

            ptt.GotFillEvent  += new FillDelegate(ptt_GotFillEvent);
            ptt.GotOrderEvent += new OrderDelegate(ptt_GotOrderEvent);
            // 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 fills
            Assert.AreEqual(100, pt[SYM].Size);
        }
コード例 #3
0
ファイル: TestOrder.cs プロジェクト: michaelwills/tradelink
        public void FillBidAskPartial()
        {
            PapertradeTracker ptt = new PapertradeTracker();
            PositionTracker   pt  = new PositionTracker();


            ptt.UseBidAskFills = true;
            ptt.GotFillEvent  += new FillDelegate(pt.GotFill);

            foreach (bool side in new bool[] { true, false })
            {
                pt.Clear();
                Order o    = new MarketOrder("IBM", side, 1000);
                int   size = o.size;
                o.id = 1;
                ptt.sendorder(o);
                Tick k = TickImpl.NewQuote("IBM", 100, 101, 400, 400, "", "");
                ptt.newTick(k); // partial fill
                ptt.newTick(k); // partial fill
                ptt.newTick(k); // partial fill, completed
                Expect(pt["IBM"].Size, Is.EqualTo(size));
            }
        }