public void ShouldCreateNewOrderBookItMatchItAndRemoveIt() { var repo = new OrderRepository(); var limitAlgo = new LimitOrderMatchingAlgorithm(new DateService()); var marketAlgo = new MarketOrderMatchingAlgorithm(new DateService()); var level1 = new OrderBookBestBidAsk("ABC"); var book = new OrderBook("ABC", limitAlgo, marketAlgo, level1); var sellOrder1 = repo.NewLimitOrder("ABC", 9, 88.2d, 100, WayEnum.Sell); book.AddLimitOrder(sellOrder1); var buyOrder1 = repo.NewLimitOrder("ABC", 9, 88.0d, 50, WayEnum.Buy); book.AddLimitOrder(buyOrder1); Assert.AreEqual(88.2d, level1.BestAskPrice); Assert.AreEqual(88.0d, level1.BestBidPrice); buyOrder1.Modify(50, 88.2d); Assert.AreEqual(88.2d, level1.BestAskPrice); Assert.IsNull(level1.BestBidPrice); var retrievedBuyOrder = repo.TryGetLimitOrder(buyOrder1.ExchangeOrderId); Assert.IsNull(retrievedBuyOrder); }
public void HandleAddLimitOrder(ILimitOrder limitOrder) { string symbol = limitOrder.Symbol; if (!OrderBooks.ContainsKey(symbol)) { var bookMatchingLimitAlgo = new LimitOrderMatchingAlgorithm(dateService); bookMatchingLimitAlgo.AddExecutionsHandler(outgoingQueue.EnqueueClientExecution); var bookMatchingMarketAlgo = new MarketOrderMatchingAlgorithm(dateService); bookMatchingMarketAlgo.AddExecutionsHandler(outgoingQueue.EnqueueClientExecution); var level1 = new OrderBookBestBidAsk(symbol); level1.RegisterUpdateHandler(outgoingQueue.EnqueueLevel1Update); var book = new OrderBook(symbol, bookMatchingLimitAlgo, bookMatchingMarketAlgo, level1); OrderBooks.Add(symbol, book); } outgoingQueue.EnqueueAddedLimitOrder(limitOrder); limitOrder.RegisterDeleteNotificationHandler(OrderBooks[symbol].RemoveLimitOrder); limitOrder.RegisterFilledNotification(OrderBooks[symbol].RemoveLimitOrder); limitOrder.RegisterModifyNotificationHandler(OrderBooks[symbol].HandleLimitOrderModify); OrderBooks[symbol].AddLimitOrder(limitOrder); }