public void ShouldRemoveTriggerWhenTriggerIsExecuted() { var orderBookBestBidAsk = new OrderBookBestBidAsk("ABC"); var book = new OrderBook("ABC", limitOrderMatchingAlgorithmMock, marketOrderMatchingAlgorithmMock, orderBookBestBidAsk); var trigger = new BestPriceTrigger("ABC", 10, WayEnum.Buy); var stopOrder = new StopLimitOrder("abc", 10, 90, 90, WayEnum.Buy, 2, trigger); trigger.SetTriggerAction(() => { stopOrder.Delete(); }); book.AddStopLimitOrder(stopOrder); Assert.AreEqual(trigger, book.BuySideStopLimitOrders[0].Trigger); orderBookBestBidAsk.Set(11,12, 100, 100); trigger.TryExecute(orderBookBestBidAsk); Assert.AreEqual(0, book.BuySideStopLimitOrders.Count); }
public IStopLimitOrder NewStopLimitOrder(string symbol, int clientId, double triggerPrice, double limitPrice, int quantity, WayEnum way) { if (!ClientStopLimitOrders.ContainsKey(clientId)) ClientStopLimitOrders.Add(clientId, new EditableList<IStopLimitOrder>()); var trigger = new BestPriceTrigger(symbol, triggerPrice, way); var toReturn = new StopLimitOrder(symbol, quantity, limitPrice, triggerPrice, way, clientId, trigger ); toReturn.SetExchangeOrderId(globalItemCounter); StopLimitOrders.Add(globalItemCounter, toReturn); ClientStopLimitOrders[clientId].Add(toReturn); toReturn.RegisterOrderRepositoryDeleteHandler(HandleDeletedStopLimitOrder); globalItemCounter++; return toReturn; }
public void ShouldNotMatchSellStopLimitOrderLowerThanMarket() { var executions = new List<INewExecution>(); var orderBookBestBidAsk = new OrderBookBestBidAsk("ABC"); var matchAlgo = new LimitOrderMatchingAlgorithm(new DateService()); matchAlgo.AddExecutionsHandler(executions.Add); var book = new OrderBook("ABC", matchAlgo, marketOrderMatchingAlgorithmMock, orderBookBestBidAsk); var sellOrder1 = new LimitOrder("ABC", 10, 1161.8d, WayEnum.Sell, 9); book.AddLimitOrder(sellOrder1); var buyOrder1 = new LimitOrder("ABC", 10, 1161.7d, WayEnum.Buy, 9); book.AddLimitOrder(buyOrder1); var trigger = new BestPriceTrigger("ABC", 1160, WayEnum.Sell); trigger.SetTriggerAction(() => { Console.WriteLine("Boom!"); int i = 0; }); var sellStopLimit = new StopLimitOrder("ABC", 1, 1160,1160, WayEnum.Sell, 5, trigger); book.AddStopLimitOrder(sellStopLimit); Assert.AreEqual(0, executions.Count); }