コード例 #1
0
        /// <summary>
        /// Handles the order ticket event.
        /// </summary>
        /// <param name="orderticketevent">The orderticketevent.</param>
        private void HandleOrderTicketEvent(OrderTicketEvent orderticketevent)
        {
            //Retrieve the order
            if (!(GetOrderById(orderticketevent.OrderId) is OrderImpl order))
            {
                _log.Error($"Unable to retrieve order with id {orderticketevent.OrderId} could not proceed");
                return;
            }

            //Set new order status
            order.State = orderticketevent.OrderState;

            //Get pending order instance
            if (!OrderTracker.TryGetOrder(orderticketevent.OrderId, out PendingOrder pendingorder))
            {
                _log.Error($"Unable to retrieve pending order with id {orderticketevent.OrderId} could not proceed");
                return;
            }

            //Check if we need to apply fill
            if ((order.State == OrderState.Filled || order.State == OrderState.PartialFilled))
            {
                pendingorder.AddFill(orderticketevent.Fill);
            }

            //Check if we need to fire an event
            if (orderticketevent.OrderState != OrderState.None)
            {
                //Create new event
                try
                {
                    Portfolio.OnOrderTicketEvent(pendingorder, orderticketevent);
                }
                catch (Exception exc)
                {
                    Portfolio.Log(LogLevel.Error, $"Could not process orderticket event: {exc.Message}");
                    _log.Error(exc);
                }
            }
        }