/// <summary> /// Processes all synchronous events that must take place before the next time loop for the algorithm /// </summary> public override void ProcessSynchronousEvents() { base.ProcessSynchronousEvents(); _brokerage.SimulateMarket(); _brokerage.Scan(); }
/// <summary> /// Processes all synchronous events that must take place before the next time loop for the algorithm /// </summary> public override void ProcessSynchronousEvents() { // we process pending order requests our selves Run(); base.ProcessSynchronousEvents(); _brokerage.SimulateMarket(); _brokerage.Scan(); }
/// <summary> /// Processes all synchronous events that must take place before the next time loop for the algorithm /// </summary> public override void ProcessSynchronousEvents() { // we process pending order requests our selves Run(); base.ProcessSynchronousEvents(); _brokerage.SimulateMarket(); _brokerage.Scan(); // Run our delistings processing, only do this once a slice if (_algorithm.CurrentSlice != null && _algorithm.CurrentSlice.Delistings != _lastestDelistings) { _lastestDelistings = _algorithm.CurrentSlice.Delistings; _brokerage.ProcessDelistings(_algorithm.CurrentSlice.Delistings); } }
public void UpdateOrderRequestShouldFailForFilledOrder() { // Initializes the transaction handler var transactionHandler = new BrokerageTransactionHandler(); var broker = new BacktestingBrokerage(_algorithm); transactionHandler.Initialize(_algorithm, broker, new BacktestingResultHandler()); // Creates a limit order var security = _algorithm.Securities[Ticker]; var price = 1.12m; security.SetMarketPrice(new Tick(DateTime.Now, security.Symbol, price, price, price)); var orderRequest = new SubmitOrderRequest(OrderType.Market, security.Type, security.Symbol, 1000, 0, 1.11m, DateTime.Now, ""); // Mock the the order processor var orderProcessorMock = new Mock <IOrderProcessor>(); orderProcessorMock.Setup(m => m.GetOrderTicket(It.IsAny <int>())).Returns(new OrderTicket(_algorithm.Transactions, orderRequest)); _algorithm.Transactions.SetOrderProcessor(orderProcessorMock.Object); // Submit and process a limit order var orderTicket = transactionHandler.Process(orderRequest); transactionHandler.HandleOrderRequest(orderRequest); Assert.IsTrue(orderRequest.Response.IsProcessed); Assert.IsTrue(orderRequest.Response.IsSuccess); Assert.AreEqual(orderTicket.Status, OrderStatus.Submitted); broker.Scan(); Assert.AreEqual(orderTicket.Status, OrderStatus.Filled); var updateRequest = new UpdateOrderRequest(DateTime.Now, orderTicket.OrderId, new UpdateOrderFields()); transactionHandler.Process(updateRequest); Assert.AreEqual(updateRequest.Status, OrderRequestStatus.Error); Assert.IsTrue(updateRequest.Response.IsError); Assert.AreEqual(updateRequest.Response.ErrorCode, OrderResponseErrorCode.InvalidOrderStatus); Assert.AreEqual(orderTicket.Status, OrderStatus.Filled); Assert.AreEqual(_algorithm.OrderEvents.Count, 2); Assert.AreEqual(_algorithm.OrderEvents.Count(orderEvent => orderEvent.Status == OrderStatus.Submitted), 1); Assert.AreEqual(_algorithm.OrderEvents.Count(orderEvent => orderEvent.Status == OrderStatus.Filled), 1); }
public void GetOpenOrdersWorksForSubmittedFilledStatus() { // Initializes the transaction handler var transactionHandler = new BrokerageTransactionHandler(); var broker = new BacktestingBrokerage(_algorithm); transactionHandler.Initialize(_algorithm, broker, new BacktestingResultHandler()); // Creates a limit order var security = _algorithm.Securities[Ticker]; var price = 1.12m; security.SetMarketPrice(new Tick(DateTime.Now, security.Symbol, price, price, price)); var orderRequest = new SubmitOrderRequest(OrderType.Market, security.Type, security.Symbol, 1000, 0, 1.11m, DateTime.Now, ""); // Mock the the order processor var orderProcessorMock = new Mock <IOrderProcessor>(); orderProcessorMock.Setup(m => m.GetOrderTicket(It.IsAny <int>())).Returns(new OrderTicket(_algorithm.Transactions, orderRequest)); _algorithm.Transactions.SetOrderProcessor(orderProcessorMock.Object); Assert.AreEqual(transactionHandler.GetOpenOrders().Count, 0); // Submit and process a limit order var orderTicket = transactionHandler.Process(orderRequest); transactionHandler.HandleOrderRequest(orderRequest); Assert.AreEqual(orderTicket.Status, OrderStatus.Submitted); var openOrders = transactionHandler.GetOpenOrders(); Assert.AreEqual(openOrders.Count, 1); Assert.AreEqual(openOrders[0].Id, orderTicket.OrderId); broker.Scan(); Assert.AreEqual(orderTicket.Status, OrderStatus.Filled); Assert.AreEqual(transactionHandler.GetOpenOrders().Count, 0); }
/// <summary> /// Processes all synchronous events that must take place before the next time loop for the algorithm /// </summary> protected override void ProcessSynchronousEvents() { base.ProcessSynchronousEvents(); _brokerage.Scan(); }