/// <summary> /// Thread entry for executing all current order tickets /// TODO: who kicks off execute? /// </summary> public void Execute() { try { foreach (var ticket in _orderTicketQueue.GetConsumingEnumerable(_cancellationTokenSource.Token)) { OrderTicketResponse response; switch (ticket.Type) { case OrderTicketType.Submit: response = SubmitOrder(ticket as SubmitOrderTicket); break; case OrderTicketType.Cancel: response = CancelOrder(ticket as CancelOrderTicket); break; case OrderTicketType.Update: response = UpdateOrder(ticket as UpdateOrderTicket); break; default: throw new ArgumentOutOfRangeException($"Unknown order ticket type {ticket.Type}"); } //set response ticket.SetResponse(response, OrderTicketState.Processed); } } catch (Exception exc) { _log.Error(exc); Portfolio.ExceptionHandler.HandleException(exc); } }
public void GetConsumingEnumerableReturnsItemsInOrder() { var collection = new BusyBlockingCollection<int>(); collection.Add(1); collection.Add(2); collection.Add(3); collection.CompleteAdding(); CollectionAssert.AreEquivalent(new[]{1,2,3}, collection.GetConsumingEnumerable()); }
public void GetConsumingEnumerableReturnsItemsInOrder() { var collection = new BusyBlockingCollection <int>(); collection.Add(1); collection.Add(2); collection.Add(3); collection.CompleteAdding(); CollectionAssert.AreEquivalent(new[] { 1, 2, 3 }, collection.GetConsumingEnumerable()); }
public void WaitForProcessingCompletedDuringGetConsumingEnumerable() { var collection = new BusyBlockingCollection<int>(); collection.Add(1); collection.Add(2); collection.Add(3); collection.CompleteAdding(); Assert.IsFalse(collection.WaitHandle.WaitOne(0)); foreach (var item in collection.GetConsumingEnumerable()) { Assert.IsFalse(collection.WaitHandle.WaitOne(0)); } Assert.IsTrue(collection.WaitHandle.WaitOne(0)); }
public void WaitForProcessingCompletedDuringGetConsumingEnumerable() { var collection = new BusyBlockingCollection <int>(); collection.Add(1); collection.Add(2); collection.Add(3); collection.CompleteAdding(); Assert.IsFalse(collection.WaitHandle.WaitOne(0)); foreach (var item in collection.GetConsumingEnumerable()) { Assert.IsFalse(collection.WaitHandle.WaitOne(0)); } Assert.IsTrue(collection.WaitHandle.WaitOne(0)); }
/// <summary> /// Primary thread entry point to launch the transaction thread. /// </summary> public void Run() { try { foreach (var request in _orderRequestQueue.GetConsumingEnumerable(_cancellationTokenSource.Token)) { OrderResponse response; switch (request.OrderRequestType) { case OrderRequestType.Submit: response = HandleSubmitOrderRequest((SubmitOrderRequest)request); break; case OrderRequestType.Update: response = HandleUpdateOrderRequest((UpdateOrderRequest)request); break; case OrderRequestType.Cancel: response = HandleCancelOrderRequest((CancelOrderRequest)request); break; default: throw new ArgumentOutOfRangeException(); } // we've finally finished processing the request, mark as processed request.SetResponse(response, OrderRequestStatus.Processed); ProcessAsynchronousEvents(); } } catch (Exception err) { // unexpected error, we need to close down shop Log.Error(err); // quit the algorithm due to error _algorithm.RunTimeError = err; } Log.Trace("BrokerageTransactionHandler.Run(): Ending Thread..."); IsActive = false; }
/// <summary> /// Primary thread entry point to launch the transaction thread. /// </summary> public void Run() { try { foreach (var request in _orderRequestQueue.GetConsumingEnumerable(_cancellationTokenSource.Token)) { HandleOrderRequest(request); ProcessAsynchronousEvents(); } } catch (Exception err) { // unexpected error, we need to close down shop Log.Error(err); // quit the algorithm due to error _algorithm.RunTimeError = err; } Log.Trace("BrokerageTransactionHandler.Run(): Ending Thread..."); IsActive = false; }