Inheritance: ExecutionMessage
Example #1
0
 public ReportSummary(ExecutionReport report)
 {
     OrdStatus = report.OrdStatus;
     AvgPx = report.AvgPx;
     CumQty = report.CumQty;
     LeavesQty = report.LeavesQty;
     Commission = report.Commission;
 }
Example #2
0
 public Fill(ExecutionReport report)
 {
     DateTime = report.DateTime;
     Order = report.Order;
     Instrument = report.Instrument;
     OrderId = report.Order.Id;
     InstrumentId = report.InstrumentId;
     CurrencyId = report.CurrencyId;
     Side = report.Side;
     Qty = report.LastQty;
     Price = report.Price;
     Commission = report.Commission;
     Text = report.Text;
 }
Example #3
0
 public virtual double GetCommission(ExecutionReport report)
 {
     double val;
     switch (Type)
     {
         case CommissionType.PerShare:
             val = Commission*report.CumQty;
             break;
         case CommissionType.Percent:
             val = Commission*report.CumQty*report.AvgPx;
             break;
         case CommissionType.Absolute:
             val = Commission;
             break;
         default:
             throw new NotSupportedException($"Unknown commission type {Type}");
     }
     return Math.Max(val, MinCommission);
 }
Example #4
0
 internal void OnExecutionReport(ExecutionReport report) => OnEvent(report);
Example #5
0
        public void OnExecutionReport(ExecutionReport report)
        {
            if (orders.ContainsKey(report.Order))
            {
                double avgPrice = 0;
                bool isFilled = true;
                bool isCancelled = true;

                foreach (Order ord in orders.Keys)
                {
                    avgPrice += ord.AvgPx * orders[ord].Weight;

                    if (!ord.IsFilled)
                        isFilled = false;

                    if (!ord.IsCancelled)
                        isCancelled = false;
                }

                // If leg orders are filled.
                if (isFilled)
                {
                    // Create ExecTrade report for spread instrument.
                    ExecutionReport execution = new ExecutionReport();
                    execution.AvgPx = avgPrice;
                    execution.Commission = report.Commission;
                    execution.CumQty = report.CumQty;
                    execution.DateTime = report.DateTime;
                    execution.ExecType = ExecType.ExecTrade;
                    execution.Instrument = spreadInstrument;
                    execution.LastPx = execution.AvgPx;
                    execution.LastQty = order.Qty;
                    execution.LeavesQty = 0;
                    execution.Order = command.Order;
                    execution.OrdQty = order.Qty;
                    execution.OrdStatus = OrderStatus.Filled;
                    execution.OrdType = command.Order.Type;
                    execution.Price = command.Order.Price;
                    execution.Side = command.Order.Side;
                    execution.StopPx = command.Order.StopPx;
                    execution.Text = command.Order.Text;

                    // Send report to SellSide strategy.
                    strategy.EmitExecutionReport(execution);

                    isDone = true;
                }

                // If leg orders are cancelled.
                if (isCancelled)
                {
                    // Create ExecCancelled report for spread instrument.
                    ExecutionReport execution = new ExecutionReport();
                    execution.DateTime = report.DateTime;
                    execution.Order = command.Order;
                    execution.Instrument = spreadInstrument;
                    execution.OrdQty = order.Qty;
                    execution.ExecType = ExecType.ExecCancelled;
                    execution.OrdStatus = OrderStatus.Cancelled;
                    execution.OrdType = order.Type;
                    execution.Side = order.Side;
                    execution.CumQty = report.CumQty;
                    execution.LastQty = 0;
                    execution.LeavesQty = report.LeavesQty;
                    execution.LastPx = 0;
                    execution.AvgPx = 0;

                    // Send report to SellSide strategy.
                    strategy.EmitExecutionReport(execution);

                    isDone = true;
                }
            }
        }
Example #6
0
        public override void OnSendCommand(ExecutionCommand command)
        {
            Order order = command.Order;

            // Create ExecNew report.
            ExecutionReport report = new ExecutionReport();
            report.DateTime = framework.Clock.DateTime;
            report.Order = order;
            report.Instrument = order.Instrument;
            report.OrdQty = order.Qty;
            report.ExecType = ExecType.ExecNew;
            report.OrdStatus = OrderStatus.New;
            report.OrdType = order.Type;
            report.Side = order.Side;

            // Send report to BuySide strategy.
            EmitExecutionReport(report);

            // Create new order processor.
            new OrderProcessor(this, command);
        }
 public ExecutionReport(ExecutionReport report)
 {
     DateTime = report.DateTime;
     Instrument = report.Instrument;
     Order = report.Order;
     CurrencyId = report.CurrencyId;
     ExecType = report.ExecType;
     OrdType = report.OrdType;
     Side = report.Side;
     TimeInForce = report.TimeInForce;
     OrdStatus = report.OrdStatus;
     LastPx = report.LastPx;
     AvgPx = report.AvgPx;
     OrdQty = report.OrdQty;
     CumQty = report.CumQty;
     LastQty = report.LastQty;
     LeavesQty = report.LeavesQty;
     Price = report.Price;
     StopPx = report.StopPx;
     Commission = report.Commission;
     Text = report.Text;
 }
Example #8
0
 public override object Read(BinaryReader reader, byte version)
 {
     var r = new ExecutionReport();
     r.DateTime = new DateTime(reader.ReadInt64());
     r.OrderId = reader.ReadInt32();
     r.ClOrderId = reader.ReadString();
     r.ProviderOrderId = reader.ReadString();
     r.InstrumentId = reader.ReadInt32();
     r.CurrencyId = reader.ReadByte();
     r.ClientId = reader.ReadInt32();
     r.ExecType = (ExecType)reader.ReadByte();
     r.OrdStatus = (OrderStatus)reader.ReadByte();
     r.OrdType = (OrderType)reader.ReadByte();
     r.Side = (OrderSide)reader.ReadByte();
     r.TimeInForce = (TimeInForce)reader.ReadByte();
     r.ExpireTime = new DateTime(reader.ReadInt64());
     r.Price = reader.ReadDouble();
     r.StopPx = reader.ReadDouble();
     r.OrdQty = reader.ReadDouble();
     r.CumQty = reader.ReadDouble();
     r.LeavesQty = reader.ReadDouble();
     r.LastPx = reader.ReadDouble();
     r.LastQty = reader.ReadDouble();
     r.Commission = reader.ReadDouble();
     r.Text = reader.ReadString();
     r.ExecId = reader.ReadString();
     if (reader.ReadBoolean())
         r.Fields = (ObjectTable)this.streamerManager.Deserialize(reader);
     return r;
 }
Example #9
0
        internal void OnExecutionReport(ExecutionReport report)
        {
            report.Order     = report.Order ?? (report.OrderId == -1 ? ordersByClOrderId[report.ClOrderId] : ordersById[report.OrderId]);
            report.ClientId  = report.Order.ClientId;
            report.ClOrderId = report.Order.ClOrderId;
            var order       = report.Order;
            var orderStatus = order.Status;

            Messages.Add(report);
            order.OnExecutionReport(report);
            if (orderStatus != order.Status)
            {
                this.framework.EventServer.OnOrderStatusChanged(order, true);
            }

            switch (report.ExecType)
            {
            case ExecType.ExecNew:
                if (report.ProviderOrderId != null)
                {
                    ordersByProviderId[report.ProviderOrderId] = order;
                }
                this.framework.EventServer.OnNewOrder(order, true);
                break;

            case ExecType.ExecRejected:
                this.framework.EventServer.OnOrderRejected(order, true);
                this.framework.EventServer.OnOrderDone(order, true);
                CancelOCAOrder(order);
                break;

            case ExecType.ExecExpired:
                this.framework.EventServer.OnOrderExpired(order, true);
                this.framework.EventServer.OnOrderDone(order, true);
                CancelOCAOrder(order);
                break;

            case ExecType.ExecTrade:
                if (order.Status == OrderStatus.PartiallyFilled)
                {
                    this.framework.EventServer.OnOrderPartiallyFilled(order, true);
                }
                else
                {
                    this.framework.EventServer.OnOrderFilled(order, true);
                    this.framework.EventServer.OnOrderDone(order, true);
                    CancelOCAOrder(order);
                }
                break;

            case ExecType.ExecCancelled:
                this.framework.EventServer.OnOrderCancelled(order, true);
                this.framework.EventServer.OnOrderDone(order, true);
                CancelOCAOrder(order);
                break;

            case ExecType.ExecCancelReject:
                this.framework.EventServer.OnOrderCancelRejected(order, true);
                break;

            case ExecType.ExecReplace:
                this.framework.EventServer.OnOrderReplaced(order, true);
                break;

            case ExecType.ExecReplaceReject:
                this.framework.EventServer.OnOrderReplaceRejected(order, true);
                break;
            }
            if (IsPersistent)
            {
                Server?.Save(report, -1);
            }
        }
Example #10
0
 internal virtual void vmethod_31(ExecutionReport report)
 {
     if (this.IsInstance)
     {
         this.OnExecutionReport(report);
     }
 }
Example #11
0
 public new virtual void EmitExecutionReport(ExecutionReport report)
 {
     this.framework.EventManager.OnEvent(report);
 }
Example #12
0
 internal void OnExecutionReport(ExecutionReport report) => OnEvent(report);
Example #13
0
 protected virtual void OnExecutionReport(ExecutionReport report)
 {
     // noop
 }
Example #14
0
 private void HandleSend(Order order)
 {
     if (order.Qty == 0.0)
     {
         this.ExecOrderRejected(order, "Order amount can not be zero");
         return;
     }
     var report = new ExecutionReport
     {
         DateTime = this.framework.Clock.DateTime,
         Order = order,
         OrderId = order.Id,
         Instrument = order.Instrument,
         InstrumentId = order.InstrumentId,
         ExecType = ExecType.ExecNew,
         OrdStatus = OrderStatus.New,
         CurrencyId = order.Instrument.CurrencyId,
         OrdType = order.Type,
         Side = order.Side,
         OrdQty = order.Qty,
         Price = order.Price,
         StopPx = order.StopPx,
         TimeInForce = order.TimeInForce,
         CumQty = 0,
         LastQty = 0,
         LeavesQty = order.Qty,
         LastPx = 0,
         AvgPx = 0,
         Text = order.Text
     };
     order.LeavesQty = report.LeavesQty;
     this.summariesByOrderId[order.Id] = new ReportSummary(report);
     EmitExecutionReport(report, Queued);
     if (order.TimeInForce == TimeInForce.AUC)
     {
         this.stops.Add(order);
         if (this.stops.Count == 1)
         {
             this.framework.Clock.AddReminder(OnAuction1, this.framework.Clock.DateTime.Date.Add(Auction1));
             this.framework.Clock.AddReminder(OnAuction2, this.framework.Clock.DateTime.Date.Add(Auction2));
         }
         return;
     }
     int int_ = order.InstrumentId;
     GetOrdersBy(int_, true).Add(order);
     if (((order.Type == OrderType.Market || order.Type == OrderType.Pegged) && !FillMarketOnNext) || (order.Type == OrderType.Limit && !FillLimitOnNext) || (order.Type == OrderType.Stop && !FillStopOnNext) || (order.Type == OrderType.StopLimit && !FillStopLimitOnNext))
     {
         if (FillOnQuote)
         {
             Ask ask = this.framework.DataManager.GetAsk(int_);
             if (ask != null && FillWithAsk(order, ask))
             {
                 this.ClearOrders();
                 return;
             }
             Bid bid = this.framework.DataManager.GetBid(int_);
             if (bid != null && this.FillWithBid(order, bid))
             {
                 this.ClearOrders();
                 return;
             }
         }
         if (FillOnTrade)
         {
             var trade = this.framework.DataManager.GetTrade(int_);
             if (trade != null && this.FillWithTrade(order, trade))
             {
                 this.ClearOrders();
                 return;
             }
         }
         if (FillOnBar)
         {
             var bar = this.framework.DataManager.GetBar(int_);
             if (BarFilter.Count != 0 && !BarFilter.Contains(bar.Type, bar.Size))
             {
                 return;
             }
             if (bar != null && this.FillWithBar(order, bar))
             {
                 ClearOrders();
             }
         }
     }
 }
Example #15
0
        public void Fill(Order order, double price, int size)
        {
            if (!PartialFills)
            {
                this.orders.Add(order);
                var report = new ExecutionReport
                {
                    DateTime = this.framework.Clock.DateTime,
                    Order = order,
                    OrderId = order.Id,
                    OrdType = order.Type,
                    Side = order.Side,
                    Instrument = order.Instrument,
                    InstrumentId = order.InstrumentId,
                    OrdQty = order.Qty,
                    Price = order.Price,
                    StopPx = order.StopPx,
                    TimeInForce = order.TimeInForce,
                    ExecType = ExecType.ExecTrade,
                    OrdStatus = OrderStatus.Filled,
                    CurrencyId = order.Instrument.CurrencyId,
                    CumQty = order.LeavesQty,
                    LastQty = order.LeavesQty,
                    LeavesQty = 0.0,
                    LastPx = price,
                    Text = order.Text
                };
                report.Commission = CommissionProvider.GetCommission(report);
                report.LastPx = SlippageProvider.GetPrice(report);
                this.summariesByOrderId[order.Id] = new ReportSummary(report);
                EmitExecutionReport(report, Queued);
                return;
            }
            if (size <= 0)
            {
                Console.WriteLine("ExecutionSimulator::Fill Error - using partial fills, size can not be zero");
                return;
            }
            var report2 = new ExecutionReport
            {
                DateTime = this.framework.Clock.DateTime,
                Order = order,
                OrderId = order.Id,
                OrdType = order.Type,
                Side = order.Side,
                Instrument = order.Instrument,
                InstrumentId = order.InstrumentId,
                OrdQty = order.Qty,
                Price = order.Price,
                StopPx = order.StopPx,
                TimeInForce = order.TimeInForce,
                ExecType = ExecType.ExecTrade,
                CurrencyId = order.Instrument.CurrencyId
            };

            if (size >= order.LeavesQty)
            {
                this.orders.Add(order);
                report2.OrdStatus = OrderStatus.Filled;
                report2.CumQty = order.CumQty + order.LeavesQty;
                report2.LastQty = order.LeavesQty;
                report2.LeavesQty = 0.0;
                report2.LastPx = price;
                report2.Text = order.Text;
                order.LeavesQty = report2.LeavesQty;
            }
            else if (size < order.LeavesQty)
            {
                report2.OrdStatus = OrderStatus.PartiallyFilled;
                report2.CumQty = order.CumQty + size;
                report2.LastQty = size;
                report2.LeavesQty = order.LeavesQty - size;
                report2.LastPx = price;
                report2.Text = order.Text;
                order.LeavesQty = report2.LeavesQty;
            }
            report2.Commission = CommissionProvider.GetCommission(report2);
            report2.LastPx = SlippageProvider.GetPrice(report2);
            this.summariesByOrderId[order.Id] = new ReportSummary(report2);
            EmitExecutionReport(report2, Queued);
        }
Example #16
0
 private void HandleReplace(ExecutionCommand command)
 {
     var order = command.Order;
     if (this.summariesByOrderId[order.Id] != null && IsOrderDone(this.summariesByOrderId[order.Id].OrdStatus))
     {
         this.ExecOrderReplaceReject(order, "Order already done");
         return;
     }
     var report = new ExecutionReport
     {
         DateTime = this.framework.Clock.DateTime,
         Order = order,
         OrderId = order.Id,
         Instrument = order.Instrument,
         InstrumentId = order.InstrumentId,
         ExecType = ExecType.ExecReplace,
         OrdStatus = OrderStatus.Replaced,
         CurrencyId = order.Instrument.CurrencyId,
         OrdType = order.Type,
         Side = order.Side,
         CumQty = order.CumQty,
         LastQty = 0.0,
         LeavesQty = command.Qty - order.CumQty,
         LastPx = 0.0,
         AvgPx = 0.0
     };
     report.OrdType = order.Type;
     report.Price = command.Price;
     report.StopPx = command.StopPx;
     report.OrdQty = command.Qty;
     report.TimeInForce = order.TimeInForce;
     report.Text = order.Text;
     this.summariesByOrderId[order.Id] = new ReportSummary(report);
     EmitExecutionReport(report, Queued);
 }
Example #17
0
 private void HandleCancel(Order order)
 {
     if (this.summariesByOrderId[order.Id] != null && IsOrderDone(this.summariesByOrderId[order.Id].OrdStatus))
     {
         this.ExecOrderCancelReject(order, "Order already done");
         return;
     }
     this.ordersByInstrumentId[order.Instrument.Id].Remove(order);
     var report = new ExecutionReport
     {
         DateTime = this.framework.Clock.DateTime,
         Order = order,
         OrderId = order.Id,
         Instrument = order.Instrument,
         InstrumentId = order.InstrumentId,
         OrdQty = order.Qty,
         Price = order.Price,
         StopPx = order.StopPx,
         TimeInForce = order.TimeInForce,
         ExecType = ExecType.ExecCancelled,
         OrdStatus = OrderStatus.Cancelled,
         CurrencyId = order.Instrument.CurrencyId,
         OrdType = order.Type,
         Side = order.Side,
         CumQty = order.CumQty,
         LastQty = 0.0,
         LeavesQty = order.LeavesQty,
         LastPx = 0.0,
         AvgPx = 0.0,
         Text = order.Text
     };
     this.summariesByOrderId[order.Id] = new ReportSummary(report);
     EmitExecutionReport(report, Queued);
 }
Example #18
0
 internal void OnExecutionReport(ExecutionReport report)
 {
     if (Strategy?.Status == StrategyStatus.Running)
         Strategy.EmitExecutionReport(report);
 }
Example #19
0
        private void EmitFilled(Order order, ExecutionCommand command)
        {
            // Create execution report for BuySide strategy.

            Instrument instrument = command.Instrument;

            ExecutionReport execution = new ExecutionReport();

            execution.AvgPx = order.AvgPx;
            execution.Commission = 0;
            execution.CumQty = order.CumQty;
            execution.DateTime = framework.Clock.DateTime;
            execution.ExecType = ExecType.ExecTrade;
            execution.Instrument = instrument;
            execution.LastPx = order.AvgPx;
            execution.LastQty = command.Qty;
            execution.LeavesQty = 0;
            execution.Order = command.Order;
            execution.OrdQty = command.Qty;
            execution.OrdStatus = OrderStatus.Filled;
            execution.OrdType = command.Order.Type;
            execution.Price = command.Order.Price;
            execution.Side = command.Order.Side;
            execution.StopPx = command.Order.StopPx;
            execution.Text = command.Order.Text;

            // Emit execution report to BuySide strategy.
            EmitExecutionReport(execution);
        }
Example #20
0
        public void OnExecutionReport(ExecutionReport report)
        {
            Status = report.OrdStatus;
            if (report.ExecType == ExecType.ExecTrade)
                AvgPx = (AvgPx  * CumQty + report.LastPx * report.LastQty) / (CumQty + report.LastQty);

            CumQty = report.CumQty;
            LeavesQty = report.LeavesQty;

            if (report.ExecType == ExecType.ExecNew)
                ProviderOrderId = report.ProviderOrderId;

            if (report.ExecType == ExecType.ExecReplace)
            {
                Type = report.OrdType;
                Price = report.Price;
                StopPx = report.StopPx;
                Qty = report.OrdQty;
            }

            Reports.Add(report);
            Messages.Add(report);
        }
Example #21
0
 public void Add(ExecutionReport report)
 {
     OnExecutionReport(report, false);
 }
Example #22
0
        internal void OnExecutionReportLoaded(ExecutionReport report)
        {
            report.Order      = report.Order ?? (report.OrderId == -1 ? ordersByClOrderId[report.ClOrderId] : ordersById[report.OrderId]);
            report.Instrument = report.Order.Instrument;
            report.ClientId   = report.Order.ClientId;
            var order       = report.Order;
            var orderStatus = order.Status;

            Messages.Add(report);
            order.OnExecutionReport(report);

            if (orderStatus != order.Status)
            {
                this.framework.EventServer.OnOrderStatusChanged(order, true);
            }

            switch (report.ExecType)
            {
            case ExecType.ExecNew:
                if (report.ClOrderId != null)
                {
                    ordersByClOrderId[report.ClOrderId] = order;
                }
                this.framework.EventServer.OnNewOrder(order, true);
                return;

            case ExecType.ExecStopped:
            case ExecType.ExecPendingCancel:
            case ExecType.ExecPendingReplace:
                break;

            case ExecType.ExecRejected:
                this.framework.EventServer.OnOrderRejected(order, true);
                this.framework.EventServer.OnOrderDone(order, true);
                CancelOCAOrder(order);
                return;

            case ExecType.ExecExpired:
                this.framework.EventServer.OnOrderExpired(order, true);
                this.framework.EventServer.OnOrderDone(order, true);
                CancelOCAOrder(order);
                return;

            case ExecType.ExecTrade:
                if (order.Status == OrderStatus.PartiallyFilled)
                {
                    this.framework.EventServer.OnOrderPartiallyFilled(order, true);
                }
                else
                {
                    this.framework.EventServer.OnOrderFilled(order, true);
                    this.framework.EventServer.OnOrderDone(order, true);
                    CancelOCAOrder(order);
                }
                return;

            case ExecType.ExecCancelled:
                this.framework.EventServer.OnOrderCancelled(order, true);
                this.framework.EventServer.OnOrderDone(order, true);
                CancelOCAOrder(order);
                return;

            case ExecType.ExecCancelReject:
                this.framework.EventServer.OnOrderCancelRejected(order, true);
                return;

            case ExecType.ExecReplace:
                this.framework.EventServer.OnOrderReplaced(order, true);
                return;

            case ExecType.ExecReplaceReject:
                this.framework.EventServer.OnOrderReplaceRejected(order, true);
                break;

            default:
                return;
            }
        }
Example #23
0
 protected void Reject(ExecutionCommand command, string format, params object[] args)
 {
     var report = new ExecutionReport
     {
         DateTime = this.framework.Clock.DateTime,
         Order = command.Order,
         OrderId = command.OrderId,
         Instrument = command.Instrument,
         InstrumentId = command.InstrumentId,
         CurrencyId = command.Instrument.CurrencyId,
         OrdType = command.Order.Type,
         Side = command.Order.Side,
         OrdQty = command.Order.Qty,
         Price = command.Order.Price,
         StopPx = command.Order.StopPx,
         TimeInForce = command.Order.TimeInForce,
         AvgPx = command.Order.AvgPx,
         CumQty = command.Order.CumQty,
         LeavesQty = command.Order.LeavesQty
     };
     switch (command.Type)
     {
         case ExecutionCommandType.Send:
             report.ExecType = ExecType.ExecRejected;
             report.OrdStatus = OrderStatus.Rejected;
             break;
         case ExecutionCommandType.Cancel:
             report.ExecType = ExecType.ExecCancelReject;
             report.OrdStatus = command.Order.Status;
             break;
         case ExecutionCommandType.Replace:
             report.ExecType = ExecType.ExecReplaceReject;
             report.OrdStatus = command.Order.Status;
             break;
     }
     report.Text = format != null ? string.Format(format, args) : report.Text;
     EmitExecutionReport(report, true);
 }
Example #24
0
 public virtual void EmitExecutionReport(ExecutionReport report)
 {
     EventManager.OnEvent(report);
 }
Example #25
0
 protected internal void EmitExecutionReport(ExecutionReport report, bool queued = true)
 {
     if (queued && this.executionQueue != null)
         this.executionQueue.Enqueue(report);
     else
         this.framework.EventServer.OnExecutionReport(report);
 }
 internal void OnExecutionReport(ExecutionReport report)
 {
     report.Order.Portfolio.OnExecutionReport(report, true);
 }
Example #27
0
        private void EmitPartiallyFilled(Order order, OrderInfo orderInfo)
        {
            ExecutionCommand command = orderInfo.Command;
            Instrument instrument = command.Instrument;

            ExecutionReport execution = new ExecutionReport();

            execution.AvgPx = order.AvgPx;

            execution.Commission = 0;
            execution.CumQty = orderInfo.QtyFilled;
            execution.DateTime = Clock.DateTime;
            execution.ExecType = ExecType.ExecTrade;
            execution.Instrument = instrument;
            execution.LastPx = execution.AvgPx;
            execution.LastQty = order.Qty;
            execution.LeavesQty = command.Qty - orderInfo.QtyFilled;
            execution.Order = command.Order;
            execution.OrdQty = command.Qty;
            execution.OrdStatus = OrderStatus.PartiallyFilled;
            execution.OrdType = command.Order.Type;
            execution.Price = command.Order.Price;
            execution.Side = command.Order.Side;
            execution.StopPx = command.Order.StopPx;
            execution.Text = command.Order.Text;

            EmitExecutionReport(execution);
        }
Example #28
0
        public void CancelLegOrders()
        {
            isDone = true;

            // Create ExecCancelled report for spread instrument.
            ExecutionReport report = new ExecutionReport();
            report.DateTime = strategy.Framework.Clock.DateTime;
            report.Order = order;
            report.Instrument = order.Instrument;
            report.OrdQty = order.Qty;
            report.ExecType = ExecType.ExecCancelled;
            report.OrdStatus = OrderStatus.Cancelled;
            report.OrdType = order.Type;
            report.Side = order.Side;
            report.CumQty = order.CumQty;
            report.LastQty = 0;
            report.LeavesQty = order.LeavesQty;
            report.LastPx = 0;
            report.AvgPx = 0;

            // Send report to SellSide strategy.
            strategy.EmitExecutionReport(report);
        }
Example #29
0
        internal void OnExecutionReport(ExecutionReport report)
        {
            report.Order = report.Order ?? (report.OrderId == -1 ? ordersByClOrderId[report.ClOrderId] : ordersById[report.OrderId]);
            report.ClientId = report.Order.ClientId;
            report.ClOrderId = report.Order.ClOrderId;
            var order = report.Order;
            var orderStatus = order.Status;
            Messages.Add(report);
            order.OnExecutionReport(report);
            if (orderStatus != order.Status)
                this.framework.EventServer.OnOrderStatusChanged(order, true);

            switch (report.ExecType)
            {
                case ExecType.ExecNew:
                    if (report.ProviderOrderId != null)
                        ordersByProviderId[report.ProviderOrderId] = order;
                    this.framework.EventServer.OnNewOrder(order, true);
                    break;
                case ExecType.ExecRejected:
                    this.framework.EventServer.OnOrderRejected(order, true);
                    this.framework.EventServer.OnOrderDone(order, true);
                    CancelOCAOrder(order);
                    break;
                case ExecType.ExecExpired:
                    this.framework.EventServer.OnOrderExpired(order, true);
                    this.framework.EventServer.OnOrderDone(order, true);
                    CancelOCAOrder(order);
                    break;
                case ExecType.ExecTrade:
                    if (order.Status == OrderStatus.PartiallyFilled)
                        this.framework.EventServer.OnOrderPartiallyFilled(order, true);
                    else
                    {
                        this.framework.EventServer.OnOrderFilled(order, true);
                        this.framework.EventServer.OnOrderDone(order, true);
                        CancelOCAOrder(order);
                    }
                    break;
                case ExecType.ExecCancelled:
                    this.framework.EventServer.OnOrderCancelled(order, true);
                    this.framework.EventServer.OnOrderDone(order, true);
                    CancelOCAOrder(order);
                    break;
                case ExecType.ExecCancelReject:
                    this.framework.EventServer.OnOrderCancelRejected(order, true);
                    break;
                case ExecType.ExecReplace:
                    this.framework.EventServer.OnOrderReplaced(order, true);
                    break;
                case ExecType.ExecReplaceReject:
                    this.framework.EventServer.OnOrderReplaceRejected(order, true);
                    break;
            }
            if (IsPersistent)
                Server?.Save(report, -1);
        }
Example #30
0
        protected override void OnExecutionReport(ExecutionReport report)
        {
            System.Collections.Generic.LinkedListNode<OrderProcessor> processorNode = processors.First;

            while (processorNode != null)
            {
                OrderProcessor processor = processorNode.Value;
                processor.OnExecutionReport(report);

                if (processor.IsDone)
                    processors.Remove(processor);

                processorNode = processorNode.Next;
            }
        }
Example #31
0
        internal void OnExecutionReportLoaded(ExecutionReport report)
        {
            report.Order = report.Order ?? (report.OrderId == -1 ? ordersByClOrderId[report.ClOrderId] : ordersById[report.OrderId]);
            report.Instrument = report.Order.Instrument;
            report.ClientId = report.Order.ClientId;
            var order = report.Order;
            var orderStatus = order.Status;
            Messages.Add(report);
            order.OnExecutionReport(report);

            if (orderStatus != order.Status)
                this.framework.EventServer.OnOrderStatusChanged(order, true);

            switch (report.ExecType)
            {
                case ExecType.ExecNew:
                    if (report.ClOrderId != null)
                        ordersByClOrderId[report.ClOrderId] = order;
                    this.framework.EventServer.OnNewOrder(order, true);
                    return;
                case ExecType.ExecStopped:
                case ExecType.ExecPendingCancel:
                case ExecType.ExecPendingReplace:
                    break;
                case ExecType.ExecRejected:
                    this.framework.EventServer.OnOrderRejected(order, true);
                    this.framework.EventServer.OnOrderDone(order, true);
                    CancelOCAOrder(order);
                    return;
                case ExecType.ExecExpired:
                    this.framework.EventServer.OnOrderExpired(order, true);
                    this.framework.EventServer.OnOrderDone(order, true);
                    CancelOCAOrder(order);
                    return;
                case ExecType.ExecTrade:
                    if (order.Status == OrderStatus.PartiallyFilled)
                        this.framework.EventServer.OnOrderPartiallyFilled(order, true);
                    else
                    {
                        this.framework.EventServer.OnOrderFilled(order, true);
                        this.framework.EventServer.OnOrderDone(order, true);
                        CancelOCAOrder(order);
                    }
                    return;                        
                case ExecType.ExecCancelled:
                    this.framework.EventServer.OnOrderCancelled(order, true);
                    this.framework.EventServer.OnOrderDone(order, true);
                    CancelOCAOrder(order);
                    return;
                case ExecType.ExecCancelReject:
                    this.framework.EventServer.OnOrderCancelRejected(order, true);
                    return;
                case ExecType.ExecReplace:
                    this.framework.EventServer.OnOrderReplaced(order, true);
                    return;
                case ExecType.ExecReplaceReject:
                    this.framework.EventServer.OnOrderReplaceRejected(order, true);
                    break;
                default:
                    return;
            }
        }
Example #32
0
 protected virtual void OnExecutionReport(ExecutionReport report)
 {
     // noop
 }
Example #33
0
 internal void OnExecutionReport(ExecutionReport report)
 {
     report.Order.Portfolio.OnExecutionReport(report, true);
 }