Esempio n. 1
0
        public void TestTradeCallbacks()
        {
            var order0 = new SimpleOrder(false, 3250, 100);
            var order1 = new SimpleOrder(true, 3250, 800);
            var order2 = new SimpleOrder(false, 3230, 0);
            var order3 = new SimpleOrder(false, 3240, 200);
            var order4 = new SimpleOrder(true, 3250, 600);

            var listener   = new TradeCbListener();
            var order_book = new OrderBook();

            order_book.SetTradeListener(listener);
            // Add order, should be accepted
            order_book.Add(order0);
            Assert.Equal(0, listener.quantities_.Count);
            listener.Reset();
            // Add matching order, should result in a trade
            order_book.Add(order1);
            Assert.Equal(1, listener.quantities_.Count);
            Assert.Equal(1, listener.costs_.Count);
            Assert.Equal((Quantity)100, listener.quantities_[0]);
            Assert.Equal(100 * 3250, listener.costs_[0]);
            listener.Reset();
            // Add invalid order, should be rejected
            order_book.Add(order2);
            Assert.Equal(0, listener.quantities_.Count);
            listener.Reset();
            // Cancel only valid order, should be cancelled
            order_book.Cancel(order1);
            Assert.Equal(0, listener.quantities_.Count);
            listener.Reset();
            // Cancel filled order, should be rejected
            order_book.Cancel(order0);
            Assert.Equal(0, listener.quantities_.Count);
            listener.Reset();
            // Add a new order and replace it, should be replaced
            order_book.Add(order3);
            order_book.Replace(order3, 0, 3250);
            Assert.Equal(0, listener.quantities_.Count);
            listener.Reset();
            // Add matching order, should be accepted, followed by a fill
            order_book.Add(order4);
            Assert.Equal(1, listener.quantities_.Count);
            Assert.Equal(1, listener.costs_.Count);
            listener.Reset();
            // Replace matched order, with too large of a size decrease, replace
            // should be rejected
            order_book.Replace(order3, -500, 0);
            Assert.Equal(0, listener.quantities_.Count);
        }
        public void TestOrderCallbacks()
        {
            var order0 = new SimpleOrder(false, 3250, 100);
            var order1 = new SimpleOrder(true, 3250, 800);
            var order2 = new SimpleOrder(false, 3230, 0);
            var order3 = new SimpleOrder(false, 3240, 200);
            var order4 = new SimpleOrder(true, 3250, 600);

            var listener   = new OrderCbListener();
            var order_book = new OrderBook();

            order_book.SetOrderListener(listener);
            // Add order, should be accepted
            order_book.Add(order0);
            Assert.AreEqual(1, listener.accepts_.Count);
            listener.Reset();
            // Add matching order, should be accepted, followed by a fill
            order_book.Add(order1);
            Assert.AreEqual(1, listener.accepts_.Count);
            Assert.AreEqual(1, listener.fills_.Count);
            listener.Reset();
            // Add invalid order, should be rejected
            order_book.Add(order2);
            Assert.AreEqual(1, listener.rejects_.Count);
            listener.Reset();
            // Cancel only valid order, should be cancelled
            order_book.Cancel(order1);
            Assert.AreEqual(1, listener.cancels_.Count);
            listener.Reset();
            // Cancel filled order, should be rejected
            order_book.Cancel(order0);
            Assert.AreEqual(1, listener.cancel_rejects_.Count);
            listener.Reset();
            // Add a new order and replace it, should be replaced
            order_book.Add(order3);
            order_book.Replace(order3, 0, 3250);
            Assert.AreEqual(1, listener.accepts_.Count);
            Assert.AreEqual(1, listener.replaces_.Count);
            listener.Reset();
            // Add matching order, should be accepted, followed by a fill
            order_book.Add(order4);
            Assert.AreEqual(1, listener.accepts_.Count);
            Assert.AreEqual(1, listener.fills_.Count);
            listener.Reset();
            // Replace matched order, with too large of a size decrease, replace
            // should be rejected
            order_book.Replace(order3, -500, 0);
            Assert.AreEqual(0, listener.replaces_.Count);
            Assert.AreEqual(1, listener.replace_rejects_.Count);
        }
Esempio n. 3
0
 internal static bool CancelAndVerify(OrderBook orderBook, IOrder order, OrderState expectedState)
 {
     orderBook.Cancel(order);
     return((order as SimpleOrder)?.State == expectedState);
 }