/// <summary>
 /// Order fill event handler. On an order fill update the resulting information is passed to this method.
 /// </summary>
 /// <param name="orderEvent">Order event details containing details of the evemts</param>
 /// <remarks>This method can be called asynchronously and so should only be used by seasoned C# experts. Ensure you use proper locks on thread-unsafe objects</remarks>
 public override void OnOrderEvent(OrderEvent orderEvent)
 {
     Log(orderEvent.ToString());
 }
Example #2
0
 public virtual void OnAssignmentOrderEvent(OrderEvent assignmentEvent)
 {
     this.Log(assignmentEvent.ToString());
     this._assignedOption = true;
 }
Example #3
0
        /// <summary>
        /// Handle order events from IB
        /// </summary>
        private void HandleOrderStatusUpdates(object sender, IB.OrderStatusEventArgs update)
        {
            try
            {
                if (update.Status == IB.OrderStatus.PreSubmitted ||
                    update.Status == IB.OrderStatus.PendingSubmit)
                {
                    return;
                }

                var status = ConvertOrderStatus(update.Status);
                if (status != OrderStatus.PartiallyFilled &&
                    status != OrderStatus.Filled &&
                    status != OrderStatus.Canceled &&
                    status != OrderStatus.Submitted &&
                    status != OrderStatus.Invalid)
                {
                    Log.Trace("InteractiveBrokersBrokerage.HandleOrderStatusUpdates(): Status: " + status);
                    return;
                }

                if (status == OrderStatus.Invalid)
                {
                    Log.Error("InteractiveBrokersBrokerage.HandleOrderStatusUpdates(): ERROR -- " + update.OrderId);
                }

                var order = _orderMapping.GetOrderByBrokerageId(update.OrderId);
                if (order == null)
                {
                    Log.Error("InteractiveBrokersBrokerage.HandleOrderStatusUpdates(): Unable to locate order with BrokerageID " + update.OrderId);
                    return;
                }

                // mark sells as negative quantities
                var fillQuantity = order.Direction == OrderDirection.Buy ? update.Filled : -update.Filled;
                var orderEvent   = new OrderEvent(order, "Interactive Brokers Fill Event")
                {
                    Status       = status,
                    FillPrice    = update.AverageFillPrice,
                    FillQuantity = fillQuantity
                };
                if (update.Remaining != 0)
                {
                    orderEvent.Message += " - " + update.Remaining + " remaining";
                }

                // if we're able to add to our fixed length, unique queue then send the event
                // otherwise it is a duplicate, so skip it
                if (_recentOrderEvents.Add(orderEvent.ToString()))
                {
                    OnOrderEvent(orderEvent);
                }
            }
            catch (InvalidOperationException err)
            {
                Log.Error("InteractiveBrokersBrokerage.HandleOrderStatusUpdates(): Unable to resolve executions for BrokerageID: " + update.OrderId + " - " + err.Message);
            }
            catch (Exception err)
            {
                Log.Error("InteractiveBrokersBrokerage.HandleOrderStatusUpdates(): " + err.Message);
            }
        }
Example #4
0
 public override void OnAssignmentOrderEvent(OrderEvent assignmentEvent)
 {
     Log(assignmentEvent.ToString());
     _assignedOption = true;
 }
 public override void OnAssignmentOrderEvent(OrderEvent assignmentEvent)
 {
     this.LogCust(assignmentEvent.ToString());
     this._assignedOption = true;
 }