Inheritance: ExecutionMessage
        public override void Send(ExecutionCommand command)
        {
            var strategy = this.childrenByInstrument[command.Order.Instrument.Id].First.Data as SellSideInstrumentStrategy;

            switch (command.Type)
            {
            case ExecutionCommandType.Send:
                strategy.OnSendCommand(command);
                return;

            case ExecutionCommandType.Cancel:
                strategy.OnCancelCommand(command);
                return;

            case ExecutionCommandType.Replace:
                strategy.OnReplaceCommand(command);
                return;

            default:
                return;
            }
        }
Example #2
0
        public void Cancel(Order order)
        {
            if (order.IsNotSent)
                throw new ArgumentException($"Can not cancel order that is not sent {order}");

            var command = new ExecutionCommand(ExecutionCommandType.Cancel, order)
            {
                DateTime = this.framework.Clock.DateTime,
                OrderId = order.Id,
                ClOrderId = order.ClOrderId,
                ProviderOrderId = order.ProviderOrderId,
                ProviderId = order.ProviderId,
                RouteId = order.RouteId,
                PortfolioId = order.PortfolioId
            };
            command.DateTime = order.DateTime;
            command.Instrument = order.Instrument;
            command.InstrumentId = order.InstrumentId;
            command.Provider = order.Provider;
            command.Portfolio = order.Portfolio;
            command.Side = order.Side;
            command.OrdType = order.Type;
            command.TimeInForce = order.TimeInForce;
            command.Price = order.Price;
            command.StopPx = order.StopPx;
            command.Qty = order.Qty;
            command.OCA = order.OCA;
            command.Text = order.Text;
            command.Account = order.Account;
            command.ClientID = order.ClientID;
            command.ClientId = order.ClientId;
            Messages.Add(command);
            order.OnExecutionCommand(command);
            this.framework.EventServer.OnExecutionCommand(command);
            if (IsPersistent)
                Server?.Save(command, -1);
            order.Provider.Send(command);
        }
        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);
        }
 private void method_7(ExecutionCommand executionCommand_0)
 {
 }
 public virtual void OnReplaceCommand(ExecutionCommand command)
 {
     // noop
 }
Example #6
0
 internal void OnExecutionCommand(ExecutionCommand command) => OnEvent(command);
 public ExecutionCommand(ExecutionCommand command)
     : this()
 {
     Type = command.Type;
     Id = command.Id;
     ProviderId = command.ProviderId;
     RouteId = command.RouteId;
     AlgoId = command.AlgoId;
     PortfolioId = command.PortfolioId;
     InstrumentId = command.InstrumentId;
     TransactTime = command.TransactTime;
     DateTime = command.DateTime;
     Instrument = command.Instrument;
     Provider = command.Provider;
     Portfolio = command.Portfolio;
     Side = command.Side;
     OrdType = command.OrdType;
     TimeInForce = command.TimeInForce;
     ExpireTime = command.ExpireTime;
     Price = command.Price;
     StopPx = command.StopPx;
     Qty = command.Qty;
     OCA = command.OCA;
     Text = command.Text;
     Account = command.Account;
     ClientID = command.ClientID;
     Fields = new ObjectTable(command.Fields);
 }
Example #8
0
        public override void Send(ExecutionCommand command)
        {
            if (IsDisconnected)
                Connect();

            switch (command.Type)
            {
                case ExecutionCommandType.Send:
                    HandleSend(command.Order);
                    return;
                case ExecutionCommandType.Cancel:
                    HandleCancel(command.Order);
                    return;
                case ExecutionCommandType.Replace:
                    HandleReplace(command);
                    return;
                default:
                    return;
            }
        }
Example #9
0
 public virtual void OnSendCommand(ExecutionCommand command)
 {
 }
Example #10
0
 public virtual void OnReplaceCommand(ExecutionCommand command)
 {
 }
Example #11
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 #12
0
        public override void OnSendCommand(ExecutionCommand command)
        {
            Order order;

            OrderInfo orderInfo = new OrderInfo(command);

            for (int i = 0; i < command.Qty; i++)
            {
                if (command.Side == OrderSide.Buy)
                {
                    order = BuyOrder(command.Instrument, 1, "VWAP Buy");
                }
                else
                {
                    order = SellOrder(command.Instrument, 1, "VWAP Sell");
                }

                orderTable[order] = orderInfo;

                Send(order);
            }
        }
Example #13
0
 public void OnExecutionCommand(ExecutionCommand command)
 {
     Commands.Add(command);
     Messages.Add(command);
 }
Example #14
0
 public virtual void Send(ExecutionCommand command)
 {
     Console.WriteLine("Provider::Send is not implemented in the base class");
 }
Example #15
0
 public Order(ExecutionCommand command)
 {
     if (command.Type != ExecutionCommandType.Send)
         throw new Exception($"Order::Order Can not create order from execution command of type different than Send : {command.Type}");
     Id = command.OrderId;
     ClOrderId= command.ClOrderId;
     AlgoId = command.AlgoId;
     ProviderOrderId = command.ProviderOrderId;
     ProviderId = command.ProviderId;
     RouteId = command.RouteId;
     PortfolioId = command.PortfolioId;
     StrategyId = command.StrategyId;
     InstrumentId = command.InstrumentId;
     TransactTime = command.TransactTime;
     DateTime = command.DateTime;
     Side = command.Side;
     Type = command.OrdType;
     TimeInForce = command.TimeInForce;
     ExpireTime = command.ExpireTime;
     Price = command.Price;
     StopPx = command.StopPx;
     Qty = command.Qty;
     Text = command.Text;
     Account = command.Account;
     ClientID = command.ClientID;
     ClientId = command.ClientId;
 }
Example #16
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 #17
0
        public override void OnSendCommand(ExecutionCommand command)
        {
            // Logic for send command.
            if (command.Type == ExecutionCommandType.Send)
            {
                Order order;

                // Create and send order to current futures contract.
                switch (command.Order.Type)
                {
                    case OrderType.Market:
                        if (command.Side == OrderSide.Buy)
                            order = BuyOrder(currentFuturesContract, command.Qty, command.Text);
                        else
                            order = SellOrder(currentFuturesContract, command.Qty, command.Text);

                        orderTable[order] = command;
                        Send(order);
                        break;

                    case OrderType.Limit:
                        if (command.Side == OrderSide.Buy)
                            order = BuyLimitOrder(currentFuturesContract, command.Qty, command.Price, command.Text);
                        else
                            order = SellLimitOrder(currentFuturesContract, command.Qty, command.Price, command.Text);

                        orderTable[order] = command;
                        Send(order);
                        break;

                    default:
                        break;
                }
            }
        }
Example #18
0
 public virtual RiskReport OnExecutionCommand(ExecutionCommand command)
 {
     return null;
 }
Example #19
0
 public OrderInfo(ExecutionCommand command)
 {
     Command = command;
 }
Example #20
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 #21
0
        public void Send(Order order)
        {
            if (!order.IsNotSent)
                throw new ArgumentException($"Can not send order that has been already sent {order}");

            this.framework.EventServer.OnSendOrder(order);
            if (order.Id == -1)
                Register(order);

            if (order.IsOCA)
            {
                List<Order> list;
                this.ordersByOCAList.TryGetValue(order.OCA, out list);
                this.ordersByOCAList[order.OCA] = list = list ?? new List<Order>();
                list.Add(order);
            }

            Orders.Add(order);
            this.ordersById[order.Id] = order;

            if (this.framework.Mode == FrameworkMode.Realtime)
                this.ordersByClOrderId[order.ClOrderId] = order;

            order.DateTime = this.framework.Clock.DateTime;
            order.Status = OrderStatus.PendingNew;
            var command = new ExecutionCommand(ExecutionCommandType.Send, order)
            {
                DateTime = order.DateTime,
                Id = order.Id,
                OrderId = order.Id,
                ClOrderId = order.ClOrderId,
                ProviderOrderId = order.ProviderOrderId,
                ProviderId = order.ProviderId,
                RouteId = order.RouteId,
                PortfolioId = order.PortfolioId,
                TransactTime = order.TransactTime,
                Instrument = order.Instrument,
                InstrumentId = order.InstrumentId,
                Provider = order.Provider,
                Portfolio = order.Portfolio,
                Side = order.Side,
                OrdType = order.Type,
                TimeInForce = order.TimeInForce,
                Price = order.Price,
                StopPx = order.StopPx,
                Qty = order.Qty,
                OCA = order.OCA,
                Text = order.Text,
                Account = order.Account,
                ClientID = order.ClientID,
                ClientId = order.ClientId
            };
            Messages.Add(command);
            order.OnExecutionCommand(command);
            this.framework.EventServer.OnExecutionCommand(command);
            this.framework.EventServer.OnPendingNewOrder(order, true);
            if (IsPersistent)
                Server?.Save(command, -1);
            order.Provider.Send(command);
        }
Example #22
0
 public virtual void OnCancelCommand(ExecutionCommand command)
 {
 }
Example #23
0
        public void Replace(Order order, double price, double stopPx, double qty)
        {
            if (order.IsNotSent)
                throw new ArgumentException($"Can not replace order that is not sent {order}");

            var command = new ExecutionCommand(ExecutionCommandType.Replace, order)
            {
                DateTime = this.framework.Clock.DateTime,
                Id = order.Id,
                OrderId = order.Id,
                ClOrderId = order.ClOrderId,
                ProviderOrderId = order.ProviderOrderId,
                ProviderId = order.ProviderId,
                RouteId = order.RouteId,
                PortfolioId = order.PortfolioId,
                TransactTime = order.TransactTime,
                Instrument = order.Instrument,
                InstrumentId = order.InstrumentId,
                Provider = order.Provider,
                Portfolio = order.Portfolio,
                Side = order.Side,
                OrdType = order.Type,
                TimeInForce = order.TimeInForce,
                Price = order.Price,
                StopPx = order.StopPx,
                Qty = order.Qty,
                OCA = order.OCA,
                Text = order.Text,
                Account = order.Account,
                ClientID = order.ClientID,
                ClientId = order.ClientId
            };
            Messages.Add(command);
            order.OnExecutionCommand(command);
            this.framework.EventServer.OnExecutionCommand(command);
            if (IsPersistent)
                Server?.Save(command, -1);
            order.Provider.Send(command);
        }
Example #24
0
 public override void Send(ExecutionCommand command)
 {
     var sellSideInstrumentStrategy_ = this.idArray_1[command.Order.Instrument.Id];
     switch (command.Type)
     {
         case ExecutionCommandType.Send:
             sellSideInstrumentStrategy_.OnSendCommand(command);
             return;
         case ExecutionCommandType.Cancel:
             sellSideInstrumentStrategy_.OnCancelCommand(command);
             return;
         case ExecutionCommandType.Replace:
             sellSideInstrumentStrategy_.OnReplaceCommand(command);
             return;
         default:
             return;
     }
 }
Example #25
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);
        }
Example #26
0
 public override object Read(BinaryReader reader, byte version)
 {
     var e = new ExecutionCommand();
     e.Id = reader.ReadInt32();
     e.Type = (ExecutionCommandType)reader.ReadByte();
     e.DateTime = new DateTime(reader.ReadInt64());
     e.TransactTime = new DateTime(reader.ReadInt64());
     e.OrderId = reader.ReadInt32();
     e.InstrumentId = reader.ReadInt32();
     e.ProviderId = reader.ReadByte();
     e.RouteId = reader.ReadByte();
     e.PortfolioId = reader.ReadInt32();
     e.ClientId = reader.ReadInt32();
     e.Side = (OrderSide)reader.ReadByte();
     e.OrdType = (OrderType)reader.ReadByte();
     e.TimeInForce = (TimeInForce)reader.ReadByte();
     e.ExpireTime = new DateTime(reader.ReadInt64());
     e.Price = reader.ReadDouble();
     e.StopPx = reader.ReadDouble();
     e.Qty = reader.ReadDouble();
     if (version >= 1)
     {
         e.MinQty = reader.ReadDouble();
         e.PegDifference = reader.ReadDouble();
         e.ExecInst = reader.ReadString();
     }
     e.OCA = reader.ReadString();
     e.Text = reader.ReadString();
     if (reader.ReadBoolean())
         e.Account = reader.ReadString();
     if (reader.ReadBoolean())
         e.ClientID = reader.ReadString();
     if (reader.ReadBoolean())
     {
         e.Fields = (ObjectTable)this.streamerManager.Deserialize(reader);
     }
     e.AlgoId = reader.ReadInt32();
     e.ClOrderId = reader.ReadString();
     return e;
 }
Example #27
0
 public override void OnReplaceCommand(ExecutionCommand command)
 {
     Console.WriteLine("{0} Replace command is not supported.", GetType().Name);
 }
 public virtual void OnCancelCommand(ExecutionCommand command)
 {
     // noop
 }
Example #29
0
 public void OnExecutionCommand(ExecutionCommand command)
 {
     Commands.Add(command);
     Messages.Add(command);
 }
 public virtual void OnSendCommand(ExecutionCommand command)
 {
     // noop
 }
Example #31
0
 public virtual RiskReport OnExecutionCommand(ExecutionCommand command)
 {
     return(null);
 }
Example #32
0
        public override void OnCancelCommand(ExecutionCommand command)
        {
            // Search for needed order processor.
            foreach (OrderProcessor processor in processors)
            {
                if (processor.Order == command.Order)
                {
                    // Cancel leg orders.
                    processor.CancelLegOrders();

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

                    return;
                }
            }
        }
Example #33
0
 public void Register(ExecutionCommand command)
 {
     if (command.Id != -1)
     {
         Console.WriteLine($"OrderManager::Register Error Order is already registered : id = {command.Id}");
         return;
     }
     lock (this.obj)
         command.Id = this.counter++;
     if (this.framework.Mode == FrameworkMode.Realtime && string.IsNullOrEmpty(command.ClOrderId))
         command.ClOrderId = this.framework.Clock.DateTime + " " + command.OrderId;
 }
Example #34
0
        public OrderProcessor(SpreadSellSide strategy, ExecutionCommand command)
        {
            // Add current processor to SellSide processor's list. 
            strategy.processors.AddLast(this);

            // Init OrderProcessor fields.
            this.strategy = strategy;
            this.command = command;
            order = command.Order;
            spreadInstrument = order.Instrument;
            orders = new Dictionary<Order, Leg>();

            // Send leg orders if order type is market.
            if (order.Type == OrderType.Market)
                SendLegOrders();
        }
Example #35
0
 public override void Send(ExecutionCommand command)
 {
     var strategy = this.childrenByInstrument[command.Order.Instrument.Id].First.Data as SellSideInstrumentStrategy;
     switch (command.Type)
     {
         case ExecutionCommandType.Send:
             strategy.OnSendCommand(command);
             return;
         case ExecutionCommandType.Cancel:
             strategy.OnCancelCommand(command);
             return;
         case ExecutionCommandType.Replace:
             strategy.OnReplaceCommand(command);
             return;
         default:
             return;
     }
 }
Example #36
0
 public override void Send(ExecutionCommand command)
 {
     switch (command.Type)
     {
         case ExecutionCommandType.Send:
             method_5(command.Order);
             return;
         case ExecutionCommandType.Cancel:
             method_6(command.Order);
             return;
         case ExecutionCommandType.Replace:
             method_7(command);
             return;
         default:
             return;
     }
 }
Example #37
0
 internal void OnExecutionCommand(ExecutionCommand command) => OnEvent(command);
Example #38
0
        public void Send(Order order)
        {
            if (!order.IsNotSent)
            {
                throw new ArgumentException($"Can not send order that has been already sent {order}");
            }

            this.framework.EventServer.OnSendOrder(order);
            if (order.Id == -1)
            {
                Register(order);
            }

            if (order.IsOCA)
            {
                List <Order> list;
                this.ordersByOCAList.TryGetValue(order.OCA, out list);
                this.ordersByOCAList[order.OCA] = list = list ?? new List <Order>();
                list.Add(order);
            }

            Orders.Add(order);
            this.ordersById[order.Id] = order;

            if (this.framework.Mode == FrameworkMode.Realtime)
            {
                this.ordersByClOrderId[order.ClOrderId] = order;
            }

            order.DateTime = this.framework.Clock.DateTime;
            order.Status   = OrderStatus.PendingNew;
            var command = new ExecutionCommand(ExecutionCommandType.Send, order)
            {
                DateTime        = order.DateTime,
                Id              = order.Id,
                OrderId         = order.Id,
                ClOrderId       = order.ClOrderId,
                ProviderOrderId = order.ProviderOrderId,
                ProviderId      = order.ProviderId,
                RouteId         = order.RouteId,
                PortfolioId     = order.PortfolioId,
                TransactTime    = order.TransactTime,
                Instrument      = order.Instrument,
                InstrumentId    = order.InstrumentId,
                Provider        = order.Provider,
                Portfolio       = order.Portfolio,
                Side            = order.Side,
                OrdType         = order.Type,
                TimeInForce     = order.TimeInForce,
                Price           = order.Price,
                StopPx          = order.StopPx,
                Qty             = order.Qty,
                OCA             = order.OCA,
                Text            = order.Text,
                Account         = order.Account,
                ClientID        = order.ClientID,
                ClientId        = order.ClientId
            };

            Messages.Add(command);
            order.OnExecutionCommand(command);
            this.framework.EventServer.OnExecutionCommand(command);
            this.framework.EventServer.OnPendingNewOrder(order, true);
            if (IsPersistent)
            {
                Server?.Save(command, -1);
            }
            order.Provider.Send(command);
        }
Example #39
0
 public virtual void Send(ExecutionCommand command)
 {
     switch (command.Type)
     {
         case ExecutionCommandType.Send:
             this.OnSendCommand(command);
             return;
         case ExecutionCommandType.Cancel:
             this.OnCancelCommand(command);
             return;
         case ExecutionCommandType.Replace:
             this.OnReplaceCommand(command);
             return;
         default:
             return;
     }
 }
Example #40
0
 public virtual void Send(ExecutionCommand command)
 {
     Console.WriteLine("Provider::Send is not implemented in the base class");
 }
Example #41
0
 private void method_7(ExecutionCommand executionCommand_0)
 {
 }