public void FindSellLevelTest_InsertsTheNewLevelIntoTheDesiredPosition_ChecksLevelsPricesAfterInsertion() { Depth depthOrderBook = new Depth("XBTUSD", 10); depthOrderBook.FindLevel(new Price(490), OrderSide.Sell, depthOrderBook.AskLevels); depthOrderBook.FindLevel(new Price(491), OrderSide.Sell, depthOrderBook.AskLevels); depthOrderBook.FindLevel(new Price(492), OrderSide.Sell, depthOrderBook.AskLevels); depthOrderBook.FindLevel(new Price(494), OrderSide.Sell, depthOrderBook.AskLevels); // Price that comes in between the currently present prices depthOrderBook.FindLevel(new Price(493), OrderSide.Sell, depthOrderBook.AskLevels); Assert.AreEqual(490, depthOrderBook.AskLevels.First().Price.Value, "Price at zero index in ascending order"); Assert.AreEqual(491, depthOrderBook.AskLevels[1].Price.Value, "Price at zero index in ascending order"); Assert.AreEqual(492, depthOrderBook.AskLevels[2].Price.Value, "Price at second index in ascending order"); Assert.AreEqual(493, depthOrderBook.AskLevels[3].Price.Value, "Price at last index in ascending order"); Assert.AreEqual(494, depthOrderBook.AskLevels[4].Price.Value, "Price at last index in ascending order"); }
public void LastAskRemovedTest_TestsIfTheLastAskIsRemovedFromTheMemorymagesListOfDepths_VerifiesusingMemoryImagesAskBook() { DepthMemoryImage depthMemoryImage = new DepthMemoryImage(); Depth depth = new Depth(CurrencyConstants.BtcUsd, 5); depth.AddOrder(new Price(491), new Volume(100), OrderSide.Buy); depth.AddOrder(new Price(498), new Volume(800), OrderSide.Buy); depth.AddOrder(new Price(493), new Volume(300), OrderSide.Buy); depth.AddOrder(new Price(496), new Volume(600), OrderSide.Buy); depth.AddOrder(new Price(491), new Volume(100), OrderSide.Sell); depth.AddOrder(new Price(498), new Volume(800), OrderSide.Sell); depth.AddOrder(new Price(493), new Volume(300), OrderSide.Sell); depth.AddOrder(new Price(496), new Volume(600), OrderSide.Sell); // Checks first and last bid prices Assert.AreEqual(498, depth.BidLevels[0].Price.Value); Assert.AreEqual(491, depth.BidLevels[3].Price.Value); // Checks first and last ask prices Assert.AreEqual(491, depth.AskLevels[0].Price.Value); Assert.AreEqual(498, depth.AskLevels[3].Price.Value); depthMemoryImage.OnDepthArrived(depth); Assert.AreEqual(1, depthMemoryImage.BidDepths.Count()); Assert.AreEqual(1, depthMemoryImage.AskDepths.Count()); // Bids in DepthMemoryImage Assert.AreEqual(800, depthMemoryImage.BidDepths.First().Value.DepthLevels[0].Volume); Assert.AreEqual(498, depthMemoryImage.BidDepths.First().Value.DepthLevels[0].Price); Assert.AreEqual(1, depthMemoryImage.BidDepths.First().Value.DepthLevels[0].OrderCount); Assert.AreEqual(600, depthMemoryImage.BidDepths.First().Value.DepthLevels[1].Volume); Assert.AreEqual(496, depthMemoryImage.BidDepths.First().Value.DepthLevels[1].Price); Assert.AreEqual(1, depthMemoryImage.BidDepths.First().Value.DepthLevels[1].OrderCount); Assert.AreEqual(300, depthMemoryImage.BidDepths.First().Value.DepthLevels[2].Volume); Assert.AreEqual(493, depthMemoryImage.BidDepths.First().Value.DepthLevels[2].Price); Assert.AreEqual(1, depthMemoryImage.BidDepths.First().Value.DepthLevels[2].OrderCount); Assert.AreEqual(100, depthMemoryImage.BidDepths.First().Value.DepthLevels[3].Volume); Assert.AreEqual(491, depthMemoryImage.BidDepths.First().Value.DepthLevels[3].Price); Assert.AreEqual(1, depthMemoryImage.BidDepths.First().Value.DepthLevels[3].OrderCount); // Asks in DepthMemoryImage Assert.AreEqual(100, depthMemoryImage.AskDepths.First().Value.DepthLevels[0].Volume); Assert.AreEqual(491, depthMemoryImage.AskDepths.First().Value.DepthLevels[0].Price); Assert.AreEqual(1, depthMemoryImage.AskDepths.First().Value.DepthLevels[0].OrderCount); Assert.AreEqual(300, depthMemoryImage.AskDepths.First().Value.DepthLevels[1].Volume); Assert.AreEqual(493, depthMemoryImage.AskDepths.First().Value.DepthLevels[1].Price); Assert.AreEqual(1, depthMemoryImage.AskDepths.First().Value.DepthLevels[1].OrderCount); Assert.AreEqual(600, depthMemoryImage.AskDepths.First().Value.DepthLevels[2].Volume); Assert.AreEqual(496, depthMemoryImage.AskDepths.First().Value.DepthLevels[2].Price); Assert.AreEqual(1, depthMemoryImage.AskDepths.First().Value.DepthLevels[2].OrderCount); Assert.AreEqual(800, depthMemoryImage.AskDepths.First().Value.DepthLevels[3].Volume); Assert.AreEqual(498, depthMemoryImage.AskDepths.First().Value.DepthLevels[3].Price); Assert.AreEqual(1, depthMemoryImage.AskDepths.First().Value.DepthLevels[3].OrderCount); DepthLevel depthLevel498 = depth.FindLevel(new Price(498), OrderSide.Sell, depth.AskLevels); depth.EraseLevel(depthLevel498, OrderSide.Sell); DepthLevel depthLevel496 = depth.FindLevel(new Price(496), OrderSide.Sell, depth.AskLevels); depth.EraseLevel(depthLevel496, OrderSide.Sell); DepthLevel depthLevel493 = depth.FindLevel(new Price(493), OrderSide.Sell, depth.AskLevels); depth.EraseLevel(depthLevel493, OrderSide.Sell); DepthLevel depthLevel491 = depth.FindLevel(new Price(491), OrderSide.Sell, depth.AskLevels); depth.EraseLevel(depthLevel491, OrderSide.Sell); // Checks first and last bid prices Assert.AreEqual(498, depth.BidLevels[0].Price.Value); Assert.AreEqual(491, depth.BidLevels[3].Price.Value); // Checks first and last ask prices Assert.AreEqual(null, depth.AskLevels[0].Price); Assert.AreEqual(null, depth.AskLevels[3].Price); depthMemoryImage.OnDepthArrived(depth); Assert.AreEqual(1, depthMemoryImage.BidDepths.Count()); Assert.AreEqual(1, depthMemoryImage.AskDepths.Count()); // Bids in DepthMemoryImage Assert.AreEqual(498, depthMemoryImage.BidDepths.First().Value.DepthLevels[0].Price); Assert.AreEqual(496, depthMemoryImage.BidDepths.First().Value.DepthLevels[1].Price); Assert.AreEqual(493, depthMemoryImage.BidDepths.First().Value.DepthLevels[2].Price); Assert.AreEqual(491, depthMemoryImage.BidDepths.First().Value.DepthLevels[3].Price); // Asks in DepthMemoryImage Assert.IsNull(depthMemoryImage.AskDepths.First().Value.DepthLevels[0]); Assert.IsNull(depthMemoryImage.AskDepths.First().Value.DepthLevels[1]); Assert.IsNull(depthMemoryImage.AskDepths.First().Value.DepthLevels[2]); Assert.IsNull(depthMemoryImage.AskDepths.First().Value.DepthLevels[3]); }