Пример #1
0
        /// <summary>
        /// Triggers any orders in the queue. Any orders that were submitted previously
        /// but not re-submitted since the last call of this method will be canceled.
        /// </summary>
        /// <param name="bar">The latest Bar instance. The price data from this Bar is
        /// used to see if any orders have been triggered.</param>
        public void TriggerOrders(Bar bar)
        {
            foreach (var order in untriggeredOrders)
            {
                if (order.Order is IOrderPriced)
                {
                    var price = order.ConditionPrice;
                    if (price <= 0)
                    {
                        price = order.Price;
                    }

                    switch (order.OrderAction)
                    {
                    case EOrderAction.Buy:
                    case EOrderAction.BuyToCover:
                        if (price >= bar.Low)
                        {
                            OnOrderTriggered(order);
                        }
                        break;

                    case EOrderAction.Sell:
                    case EOrderAction.SellShort:
                        if (price <= bar.High)
                        {
                            OnOrderTriggered(order);
                        }
                        break;

                    default:
                        throw new ArgumentException("Unknown OrderAction");
                    }
                }
                else
                {
                    throw new ArgumentException("Unknown order type");
                }
            }

            // Any orders that are in previousSubmittedOrders but not in untriggeredOrders
            // were not resubmitted, and so should be canceled
            foreach (var order in previousSubmittedOrders)
            {
                if (!untriggeredOrders.Contains(order))
                {
                    OrderCanceled.SafeTrigger(order);
                }
            }

            previousSubmittedOrders = untriggeredOrders;
            untriggeredOrders       = untriggeredOrders.Clear();
        }
Пример #2
0
 private void OnOrderCanceled(OrderInfo order)
 {
     OrderCanceled.SafeTrigger(order);
 }