/// <summary>
        /// Adds the specified order to be processed
        /// </summary>
        /// <param name="request">The order to be processed</param>
        public OrderTicket Process(OrderRequest request)
        {
            if (_algorithm.LiveMode)
            {
                Log.Trace("BrokerageTransactionHandler.Process(): " + request);
            }

            switch (request.OrderRequestType)
            {
                case OrderRequestType.Submit:
                    return AddOrder((SubmitOrderRequest) request);

                case OrderRequestType.Update:
                    return UpdateOrder((UpdateOrderRequest) request);

                case OrderRequestType.Cancel:
                    return CancelOrder((CancelOrderRequest) request);

                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
 /// <summary>
 /// Processes the order request
 /// </summary>
 /// <param name="request">The request to be processed</param>
 /// <returns>The order ticket for the request</returns>
 public OrderTicket ProcessRequest(OrderRequest request)
 {
     var submit = request as SubmitOrderRequest;
     if (submit != null)
     {
         submit.SetOrderId(GetIncrementOrderId());
     }
     return _orderProcessor.Process(request);
 }
 public OrderTicket Process(OrderRequest request)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Adds the specified order to be processed
        /// </summary>
        /// <param name="request">The order to be processed</param>
        public OrderTicket Process(OrderRequest request)
        {
            switch (request.OrderRequestType)
            {
                case OrderRequestType.Submit:
                    return AddOrder((SubmitOrderRequest) request);

                case OrderRequestType.Update:
                    return UpdateOrder((UpdateOrderRequest) request);

                case OrderRequestType.Cancel:
                    return CancelOrder((CancelOrderRequest) request);

                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
Exemple #5
0
 /// <summary>
 /// Helper method to create an error response due to a zero order quantity
 /// </summary>
 public static OrderResponse ZeroQuantity(OrderRequest request)
 {
     return(Error(request, OrderResponseErrorCode.OrderQuantityZero,
                  Invariant($"Unable to {request.OrderRequestType.ToLower()} order with id {request.OrderId} that has zero quantity.")
                  ));
 }
        /// <summary>
        /// Handles a generic order request
        /// </summary>
        /// <param name="request"><see cref="OrderRequest"/> to be handled</param>
        /// <returns><see cref="OrderResponse"/> for request</returns>
        public void HandleOrderRequest(OrderRequest request)
        {
            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();
            }

            // mark request as processed
            request.SetResponse(response, OrderRequestStatus.Processed);
        }
Exemple #7
0
 /// <summary>
 /// Helper method to create an error response due to a bad order id
 /// </summary>
 public static OrderResponse UnableToFindOrder(OrderRequest request)
 {
     return(Error(request, OrderResponseErrorCode.UnableToFindOrder,
                  Invariant($"Unable to locate order with id {request.OrderId}.")
                  ));
 }
Exemple #8
0
 /// <summary>
 /// Helper method to create an error response due to the "New" order status
 /// </summary>
 public static OrderResponse InvalidNewStatus(OrderRequest request, Order order)
 {
     return(Error(request, OrderResponseErrorCode.InvalidNewOrderStatus,
                  Invariant($"Unable to update or cancel order with id {request.OrderId} and status {order.Status} because the submit confirmation has not been received yet.")
                  ));
 }
Exemple #9
0
 /// <summary>
 /// Helper method to create an error response due to an invalid order status
 /// </summary>
 public static OrderResponse InvalidStatus(OrderRequest request, Order order)
 {
     return(Error(request, OrderResponseErrorCode.InvalidOrderStatus,
                  Invariant($"Unable to update order with id {request.OrderId} because it already has {order.Status} status.")
                  ));
 }
Exemple #10
0
 /// <summary>
 /// Helper method to create an error response from a request
 /// </summary>
 public static OrderResponse Error(OrderRequest request, OrderResponseErrorCode errorCode, string errorMessage)
 {
     return(new OrderResponse(request.OrderId, errorCode, errorMessage));
 }
Exemple #11
0
 /// <summary>
 /// Helper method to create a successful response from a request
 /// </summary>
 public static OrderResponse Success(OrderRequest request)
 {
     return(new OrderResponse(request.OrderId, OrderResponseErrorCode.None, null));
 }