Exemple #1
0
        /// <summary>
        /// Create pending order based on order ticket
        /// </summary>
        /// <param name="ticket"></param>
        /// <returns></returns>
        public PendingOrder CreateOrder(OrderTicket ticket)
        {
            //Get correct ticket information
            if (ticket.Type != OrderTicketType.Submit)
            {
                return(null);
            }

            //Get new order ticket
            if (!(ticket is SubmitOrderTicket norderticket))
            {
                ticket.SetResponse(OrderTicketResponse.Error(ticket.OrderId, OrderTicketResponseErrorCode.ProcessingError, "Incorrect ticket type received"));
                return(null);
            }

            //Check order type based on input
            Order order;

            switch (norderticket.OrderType)
            {
            case OrderType.Limit:
                order = new LimitOrder(norderticket.Security, norderticket.FundId, norderticket.Quantity, norderticket.LimitPrice,
                                       norderticket.CreatedUtc, norderticket.ExchangeName, norderticket.Comment)
                {
                    InternalId = _portfolio.OrderTicketHandler.GetNextInternalOrderId()
                };
                break;

            case OrderType.Market:
                order = new MarketOrder(norderticket.Security, norderticket.FundId, norderticket.Quantity,
                                        norderticket.CreatedUtc, norderticket.ExchangeName, norderticket.Comment)
                {
                    InternalId = _portfolio.OrderTicketHandler.GetNextInternalOrderId()
                };
                break;

            case OrderType.StopMarket:
                order = new StopMarketOrder(norderticket.Security, norderticket.FundId, norderticket.Quantity,
                                            norderticket.StopPrice, norderticket.CreatedUtc, norderticket.ExchangeName, norderticket.Comment)
                {
                    InternalId = _portfolio.OrderTicketHandler.GetNextInternalOrderId()
                };
                break;

            case OrderType.StopLimit:
                order = new StopLimitOrder(norderticket.Security, norderticket.FundId, norderticket.Quantity, norderticket.LimitPrice,
                                           norderticket.StopPrice, norderticket.CreatedUtc, norderticket.ExchangeName, norderticket.Comment)
                {
                    InternalId = _portfolio.OrderTicketHandler.GetNextInternalOrderId()
                };
                break;

            case OrderType.MarketOnOpen:
                order = new MarketOnOpenOrder(norderticket.Security, norderticket.FundId, norderticket.Quantity, norderticket.CreatedUtc, norderticket.ExchangeName, norderticket.Comment)
                {
                    InternalId = _portfolio.OrderTicketHandler.GetNextInternalOrderId()
                };
                break;

            case OrderType.MarketOnClose:
                order = new MarketOnCloseOrder(norderticket.Security, norderticket.FundId, norderticket.Quantity, norderticket.CreatedUtc, norderticket.ExchangeName, norderticket.Comment)
                {
                    InternalId = _portfolio.OrderTicketHandler.GetNextInternalOrderId()
                };
                break;

            default:
                ticket.SetResponse(OrderTicketResponse.Error(ticket.OrderId, OrderTicketResponseErrorCode.ProcessingError, $"Unknown order type {norderticket.OrderType} supplied"));
                return(null);
            }

            //Check if order type is supported
            bool issupported;

            try
            {
                issupported = _brokerModel.IsOrderTypeSupported(order.Type);
            }
            catch (Exception exc)
            {
                _log.Error(exc, $"Could not execute brokermodel function IsOrderTypeSupported due to exception");
                throw exc;
            }

            //Create pending order
            return(new PendingOrder(_portfolio, ticket.FundId, order, norderticket.Comment,
                                    norderticket.Security.LastTickEventUtc, issupported));
        }
Exemple #2
0
 /// <summary>
 /// Set the response for this order ticket
 /// TODO: needs to be internal and protected
 /// </summary>
 /// <param name="response">The response.</param>
 /// <param name="state">The state.</param>
 public void SetResponse(OrderTicketResponse response, OrderTicketState state = OrderTicketState.Error)
 {
     Response = response;
     State    = state;
 }