public void First_ReturnsFirstOrder_2() { QuantityTrackingPriceLevel quantityTrackingPriceLevel = new QuantityTrackingPriceLevel(100); Order order1 = new Order() { IsBuy = true, OrderId = 1, Price = 100, Sequnce = 1, OpenQuantity = 1000 }; quantityTrackingPriceLevel.AddOrder(order1); Assert.Equal(1000, quantityTrackingPriceLevel.Quantity); Assert.Equal(1, quantityTrackingPriceLevel.OrderCount); Order order2 = new Order() { IsBuy = true, OrderId = 2, Price = 100, Sequnce = 2, OpenQuantity = 1000 }; quantityTrackingPriceLevel.AddOrder(order2); Order order3 = new Order() { IsBuy = true, OrderId = 3, Price = 100, Sequnce = 3, OpenQuantity = 1000 }; quantityTrackingPriceLevel.AddOrder(order3); Assert.Equal(order1, quantityTrackingPriceLevel.First); }
public void Fill_RemovesOrder_IfOpenQuantityIs0() { QuantityTrackingPriceLevel quantityTrackingPriceLevel = new QuantityTrackingPriceLevel(100); Order order1 = new Order() { IsBuy = true, OrderId = 1, Price = 100, OpenQuantity = 1000, Sequnce = 1 }; quantityTrackingPriceLevel.AddOrder(order1); Assert.Equal(1000, quantityTrackingPriceLevel.Quantity); Assert.Equal(1, quantityTrackingPriceLevel.OrderCount); Order order2 = new Order() { IsBuy = true, OrderId = 2, Price = 100, OpenQuantity = 1000, Sequnce = 2 }; quantityTrackingPriceLevel.AddOrder(order2); Assert.Equal(2000, quantityTrackingPriceLevel.Quantity); Assert.Equal(2, quantityTrackingPriceLevel.OrderCount); quantityTrackingPriceLevel.Fill(order1, 1000); Assert.Equal(1000, quantityTrackingPriceLevel.Quantity); Assert.Equal(1, quantityTrackingPriceLevel.OrderCount); Assert.Contains(order2, quantityTrackingPriceLevel); }
public void Fill_ThrowsException_IfOpenQuantityIsLessThanFillQuantity() { QuantityTrackingPriceLevel quantityTrackingPriceLevel = new QuantityTrackingPriceLevel(100); Order order1 = new Order() { IsBuy = true, OrderId = 1, Price = 100, Sequnce = 1, OpenQuantity = 1000 }; quantityTrackingPriceLevel.AddOrder(order1); Assert.Equal(1000, quantityTrackingPriceLevel.Quantity); Assert.Equal(1, quantityTrackingPriceLevel.OrderCount); Order order2 = new Order() { IsBuy = true, OrderId = 2, Price = 100, Sequnce = 2, OpenQuantity = 1000 }; quantityTrackingPriceLevel.AddOrder(order2); Assert.Equal(2000, quantityTrackingPriceLevel.Quantity); Assert.Equal(2, quantityTrackingPriceLevel.OrderCount); Exception ex = Assert.Throws <Exception>(() => quantityTrackingPriceLevel.Fill(order1, 1100)); Assert.Equal("Order quantity is less then requested fill quanity", ex.Message); Assert.Equal(2000, quantityTrackingPriceLevel.Quantity); Assert.Equal(2, quantityTrackingPriceLevel.OrderCount); }
public void Fill_DoesNotRemoveOrder_IfOpenQuantityIsNot0() { QuantityTrackingPriceLevel quantityTrackingPriceLevel = new QuantityTrackingPriceLevel(100); Order order1 = new Order() { IsBuy = true, OrderId = 1, OpenQuantity = 1000, Price = 100, Sequnce = 1 }; quantityTrackingPriceLevel.AddOrder(order1); Assert.Equal(1000, quantityTrackingPriceLevel.Quantity); Assert.Equal(1, quantityTrackingPriceLevel.OrderCount); Order order2 = new Order() { IsBuy = true, OrderId = 2, OpenQuantity = 1000, Price = 100, Sequnce = 2 }; quantityTrackingPriceLevel.AddOrder(order2); Assert.Equal(2000, quantityTrackingPriceLevel.Quantity); Assert.Equal(2, quantityTrackingPriceLevel.OrderCount); quantityTrackingPriceLevel.Fill(order1, 900); Assert.Equal(1100, quantityTrackingPriceLevel.Quantity); Assert.Equal(2, quantityTrackingPriceLevel.OrderCount); Assert.Contains(order1, quantityTrackingPriceLevel); Assert.Contains(order2, quantityTrackingPriceLevel); Assert.True(100 == order1.OpenQuantity, "Quantity should be 100"); }
public void AddOrder_AddsOrder() { QuantityTrackingPriceLevel quantityTrackingPriceLevel = new QuantityTrackingPriceLevel(100); Order order1 = new Order() { IsBuy = true, OrderId = 1, Price = 100, Sequnce = 1, OpenQuantity = 1000 }; quantityTrackingPriceLevel.AddOrder(order1); Assert.Equal((Quantity)1000, quantityTrackingPriceLevel.Quantity); Assert.Equal(1, quantityTrackingPriceLevel.OrderCount); Order order2 = new Order() { IsBuy = true, OrderId = 2, Price = 100, Sequnce = 2, OpenQuantity = 1000 }; quantityTrackingPriceLevel.AddOrder(order2); Assert.Equal((Quantity)2000, quantityTrackingPriceLevel.Quantity); Assert.Equal(2, quantityTrackingPriceLevel.OrderCount); Assert.Contains(order1, quantityTrackingPriceLevel); Assert.Contains(order2, quantityTrackingPriceLevel); }
public void RemoveOrder_RemovesOrder() { QuantityTrackingPriceLevel quantityTrackingPriceLevel = new QuantityTrackingPriceLevel(100); Order order1 = new Order() { IsBuy = true, OrderId = 1, Price = 100, Sequnce = 1, OpenQuantity = 1000 }; quantityTrackingPriceLevel.AddOrder(order1); Assert.Equal(1000, quantityTrackingPriceLevel.Quantity); Assert.Equal(1, quantityTrackingPriceLevel.OrderCount); Order order2 = new Order() { IsBuy = true, OrderId = 2, Price = 100, Sequnce = 2, OpenQuantity = 1000 }; quantityTrackingPriceLevel.AddOrder(order2); Assert.Equal(2000, quantityTrackingPriceLevel.Quantity); Assert.Equal(2, quantityTrackingPriceLevel.OrderCount); Order order3 = new Order() { IsBuy = true, OrderId = 3, Price = 100, Sequnce = 3, OpenQuantity = 1000 }; quantityTrackingPriceLevel.AddOrder(order3); Assert.Equal(3000, quantityTrackingPriceLevel.Quantity); Assert.Equal(3, quantityTrackingPriceLevel.OrderCount); Order order4 = new Order() { IsBuy = true, OrderId = 4, Price = 100, Sequnce = 4, OpenQuantity = 1000 }; quantityTrackingPriceLevel.AddOrder(order4); Assert.Equal(4000, quantityTrackingPriceLevel.Quantity); Assert.Equal(4, quantityTrackingPriceLevel.OrderCount); quantityTrackingPriceLevel.RemoveOrder(order3); Assert.Equal(3000, quantityTrackingPriceLevel.Quantity); Assert.Equal(3, quantityTrackingPriceLevel.OrderCount); Assert.Contains(order1, quantityTrackingPriceLevel); Assert.Contains(order2, quantityTrackingPriceLevel); Assert.Contains(order4, quantityTrackingPriceLevel); }
public void SortedDictionarySortsDescendingQuantityTrackingPriceLevel() { PriceComparerDescendingZeroFirst comparer = new PriceComparerDescendingZeroFirst(); SortedDictionary <Price, QuantityTrackingPriceLevel> sortedDictionary = new SortedDictionary <Price, QuantityTrackingPriceLevel>(comparer); Price price1 = new Price(1); QuantityTrackingPriceLevel level1 = new QuantityTrackingPriceLevel(price1); sortedDictionary.Add(price1, level1); Price price4 = new Price(4); QuantityTrackingPriceLevel level4 = new QuantityTrackingPriceLevel(price4); sortedDictionary.Add(price4, level4); Price price3 = new Price(3); QuantityTrackingPriceLevel level3 = new QuantityTrackingPriceLevel(price3); sortedDictionary.Add(price3, level3); Price price2 = new Price(2); QuantityTrackingPriceLevel level2 = new QuantityTrackingPriceLevel(price2); sortedDictionary.Add(price2, level2); Price price0 = new Price(0); QuantityTrackingPriceLevel level0 = new QuantityTrackingPriceLevel(price0); sortedDictionary.Add(price0, level0); Price price5 = new Price(5); QuantityTrackingPriceLevel level5 = new QuantityTrackingPriceLevel(price5); sortedDictionary.Add(price5, level5); List <QuantityTrackingPriceLevel> expectedPriceLevelSortOrder = new List <QuantityTrackingPriceLevel>() { level0, level5, level4, level3, level2, level1 }; AssertHelper.SequentiallyEqual(expectedPriceLevelSortOrder, sortedDictionary.Values.ToList()); List <Price> expectedPriceSortOrder = new List <Price>() { price0, price5, price4, price3, price2, price1 }; AssertHelper.SequentiallyEqual(expectedPriceSortOrder, sortedDictionary.Keys.ToList()); }