示例#1
0
        public void OrdersAreSortedOnLastUpdateTimeIfPriceEqual(string order1,
                                                                string order2,
                                                                bool o1IsEarlier)
        {
            const int id1       = 1;
            const int id2       = 2;
            var       earlyDate = new DateTime(2013, 01, 01, 10, 0, 0);
            var       lateDate  = new DateTime(2013, 01, 01, 10, 0, 1);
            var       o1        = FakeOrder.CreateOrderFromString(id1, order1);
            var       o2        = FakeOrder.CreateOrderFromString(id2, order2);

            o1.LastUpdateTime = o1IsEarlier ? earlyDate : lateDate;
            o2.LastUpdateTime = o1IsEarlier ? lateDate : earlyDate;
            Assert.AreEqual(o1.Price, o2.Price, "Orders must have same price for this test");

            var orders = new[] { o1, o2 };
            var sorted = new SortedSet <IOrder>(orders, new OrderStack.StandardOrderComparer());

            Assert.AreEqual(2, sorted.Count, "Sorting has changed the number of orders!");
            if (o1IsEarlier)
            {
                Assert.AreEqual(id1, sorted.ElementAt(0).ID, "Order 1 should be first in the list");
                Assert.AreEqual(id2, sorted.ElementAt(1).ID, "Order 2 should be second in the list");
            }
            else
            {
                Assert.AreEqual(id2, sorted.ElementAt(0).ID, "Order 2 should be first in the list");
                Assert.AreEqual(id1, sorted.ElementAt(1).ID, "Order 1 should be second in the list");
            }
        }
示例#2
0
        public void AttemptingToSortABidAndAnAskThrows()
        {
            var o1 = FakeOrder.CreateOrderFromString(1, "Limit;TEST;Bid;20@10");
            var o2 = FakeOrder.CreateOrderFromString(2, "Limit;TEST;Ask;20@10");

            Assert.Throws <InvalidOperationException>(
                () => new SortedSet <IOrder>(new[] { o1, o2 }, new OrderStack.StandardOrderComparer()));
        }
示例#3
0
        public void AttemptingToSortANullOrderThrows(bool order1Null, bool order2Null)
        {
            var o1 = order1Null ? null : FakeOrder.CreateOrderFromString(1, "Limit;TEST;Bid;20@10");
            var o2 = order2Null ? null : FakeOrder.CreateOrderFromString(2, "Limit;TEST;Bid;20@11");

            Assert.Throws <InvalidOperationException>(
                () => new SortedSet <IOrder>(new[] { o1, o2 }, new OrderStack.StandardOrderComparer()));
        }
        // TODO Test market order matching if we ever support them
        // Price, priority vs limit orders etc

        private static Tuple <SortedSet <IOrder>, SortedSet <IOrder> > BuildStack(
            IEnumerable <string> orderStrings)
        {
            long id     = 0;
            var  orders = orderStrings.Select(s => FakeOrder.CreateOrderFromString(++id, s)).ToArray();
            var  bids   = orders.Where(o => o.MarketSide == MarketSide.Bid);
            var  asks   = orders.Where(o => o.MarketSide == MarketSide.Ask);

            return(Tuple.Create(DefaultSort(bids), DefaultSort(asks)));
        }
示例#5
0
        public void OrdersAreSortedByIDIfAllElseIsEqual(string order1,
                                                        string order2)
        {
            const int id1    = 1;
            const int id2    = 2;
            var       orders = new List <FakeOrder>
            {
                FakeOrder.CreateOrderFromString(id1, order1),
                FakeOrder.CreateOrderFromString(id2, order2)
            };
            var t = DateTime.UtcNow;

            orders.ForEach(o => o.LastUpdateTime = t);
            var sorted = new SortedSet <IOrder>(orders, new OrderStack.StandardOrderComparer());

            Assert.AreEqual(2, sorted.Count, "Sorting has changed the number of orders!");
            Assert.AreEqual(id1, sorted.ElementAt(0).ID, "Order 1 should be first in the list");
            Assert.AreEqual(id2, sorted.ElementAt(1).ID, "Order 2 should be second in the list");
        }
        public void TwoTradesMatchingProducesTwoMatchNotifications()
        {
            var matcher         = new StandardOrderMatcher();
            var orderRepository = new StandardOrderRepository(matcher);
            var matchRecorder   = new MatchRecorder();

            orderRepository.OrdersMatched += matchRecorder.OnMatch;

            var ask = FakeOrder.CreateOrderFromString(1, "Limit;TEST;Ask;10@10");
            var bid = FakeOrder.CreateOrderFromString(1, "Limit;TEST;Bid;10@10");

            AddOrderToRepository(ask, orderRepository);
            AddOrderToRepository(bid, orderRepository);

            orderRepository.MatchOrders(bid.Contract);

            Assert.AreEqual(1, matchRecorder.Matches.Count);
            var matches = matchRecorder.Matches[0];

            Assert.AreEqual(2, matches.OrderMatches.Count());
        }
示例#7
0
        public void TwoAsksAreSortedByAscendingPrice(string a1, string a2, bool ask1Better)
        {
            // Note that quantity, last update time, ID don't come into it yet
            const int id1  = 1;
            const int id2  = 2;
            var       asks = new[]
            {
                FakeOrder.CreateOrderFromString(id1, a1),
                FakeOrder.CreateOrderFromString(id2, a2)
            };
            var sorted = new SortedSet <IOrder>(asks, new OrderStack.StandardOrderComparer());

            Assert.AreEqual(2, sorted.Count, "Sorting has changed the number of orders!");
            if (ask1Better)
            {
                Assert.AreEqual(id1, sorted.ElementAt(0).ID, "Ask 1 should be first in the list");
                Assert.AreEqual(id2, sorted.ElementAt(1).ID, "Ask 2 should be second in the list");
            }
            else
            {
                Assert.AreEqual(id2, sorted.ElementAt(0).ID, "Ask 2 should be first in the list");
                Assert.AreEqual(id1, sorted.ElementAt(1).ID, "Ask 1 should be second in the list");
            }
        }
示例#8
0
 private FakeOrder DefaultOrder(long orderID)
 {
     return(FakeOrder.CreateOrderFromString(orderID, "Limit;TEST;Bid;10@100"));
 }