public void limit_buy_order_filled_by_2_sell_orders() { Commodity gold = new Commodity("Gold (grams)"); Player playerA = new Player(1, "A"); Player playerB = new Player(2, "B"); Player playerC = new Player(3, "C"); IExchange exchange = new Exchange(new BestPriceMatchingStrategy(), new OrderQueue("USD"), new OrderQueue("USD"), 1, "WALTSGOLD", "Walt's Gold Exchange"); //order executed on match IOrder buyOrder = exchange.AddOrder(OrderBuilder.BuildBuyOrder(null, new DateTime(2013, 8, 1, 14, 22, 21), playerA, gold, 10, new Money("USD", 50))); Thread.Sleep(250); Assert.AreEqual(OrderStatus.Created, buyOrder.Status); IOrder sellOrder1 = exchange.AddOrder(OrderBuilder.BuildSellOrder(null, new DateTime(2013, 8, 1, 14, 22, 57), playerB, gold, 4, new Money("USD", 50))); Thread.Sleep(250); Assert.AreEqual(OrderStatus.Filled, sellOrder1.Status); Assert.AreEqual(OrderStatus.PartiallyFilled, buyOrder.Status); Assert.AreEqual(4, buyOrder.FilledSize); IOrder sellOrder2 = exchange.AddOrder(OrderBuilder.BuildSellOrder(null, new DateTime(2013, 8, 1, 14, 23, 05), playerC, gold, 6, new Money("USD", 50))); Thread.Sleep(250); Assert.AreEqual(OrderStatus.Filled, sellOrder2.Status); Assert.AreEqual(OrderStatus.Filled, buyOrder.Status); Assert.AreEqual(10, buyOrder.FilledSize); }
public void simple_sell_buy_order_sequence_with_2_limit_orders() { Commodity van = new Commodity("Camper Van"); Player playerA = new Player(1, "A"); Player playerB = new Player(2, "B"); IExchange exchange = new Exchange(new BestPriceMatchingStrategy(), new OrderQueue("USD"), new OrderQueue("USD"), 1, "WALTSRV", "Walt's RV Exchange", false); IOrder sellOrder = exchange.AddOrder(OrderBuilder.BuildSellOrder(null, new DateTime(2013, 8, 1, 14, 22, 21), playerA, van, 1, new Money("USD", 5000))); Assert.AreEqual(OrderStatus.Created, sellOrder.Status); IOrder buyOrder = exchange.AddOrder(OrderBuilder.BuildBuyOrder(null, new DateTime(2013, 8, 1, 14, 22, 57), playerB, van, 1, new Money("USD", 5000))); Assert.AreEqual(OrderStatus.Filled, sellOrder.Status); Assert.AreEqual(OrderStatus.Filled, buyOrder.Status); }
public void simple_sell_order_cancel_on_limit_order() { Commodity van = new Commodity("Camper Van"); Player playerA = new Player(1, "A"); IExchange exchange = new Exchange(new BestPriceMatchingStrategy(), new OrderQueue("USD"), new OrderQueue("USD"), 1, "WALTSRV", "Walt's RV Exchange", false); IOrder sellOrder = exchange.AddOrder(OrderBuilder.BuildSellOrder(null, new DateTime(2013, 8, 1, 14, 22, 21), playerA, van, 1, new Money("USD", 5000))); Assert.AreEqual(OrderStatus.Created, sellOrder.Status); bool cancelled = exchange.CancelOrder(sellOrder); Assert.IsTrue(cancelled); Assert.AreEqual(OrderStatus.Cancelled, sellOrder.Status); }