Beispiel #1
0
        public bool SendSessionStatus(string status)
        {
            switch (status)
            {
            case "2":
                ProviderSimulator.SetOrderServerOnline();
                break;

            case "3":
                ProviderSimulator.SetOrderServerOffline();
                break;

            default:
                throw new ApplicationException("Unknown session status:" + status);
            }
            var mbtMsg = FixFactory.Create();

            mbtMsg.AddHeader("h");
            mbtMsg.SetTradingSessionId("TSSTATE");
            mbtMsg.SetTradingSessionStatus(status);
            if (debug)
            {
                log.Debug("Sending order server status: " + mbtMsg);
            }
            SendMessage(mbtMsg);
            return(true);
        }
Beispiel #2
0
        public void OnCancelBrokerOrder(SymbolInfo symbol, object origBrokerOrder)
        {
            PhysicalOrder physicalOrder;

            try {
                physicalOrder = GetOrderById(origBrokerOrder);
            } catch (ApplicationException ex) {
                log.Warn("Order probably already canceled. " + ex.Message);
                if (SyncTicks.Enabled)
                {
                    var tickSync = SyncTicks.GetTickSync(symbol.BinaryIdentifier);
                    tickSync.RemovePhysicalOrder();
                }
                return;
            }
            physicalOrder.OrderState = OrderState.Pending;
            if (debug)
            {
                log.Debug("OnCancelBrokerOrder " + physicalOrder);
            }

            var    fixMsg           = (FIXMessage4_4)FixFactory.Create();
            string newClientOrderId = physicalOrder.LogicalOrderId + "." + GetUniqueOrderId();

            fixMsg.SetOriginalClientOrderId((string)origBrokerOrder);
            fixMsg.SetClientOrderId(newClientOrderId);
            fixMsg.SetAccount(AccountNumber);
            fixMsg.SetSide(GetOrderSide(physicalOrder.Side));
            fixMsg.AddHeader("F");
            fixMsg.SetSymbol(physicalOrder.Symbol.Symbol);
            fixMsg.SetTransactTime(TimeStamp.UtcNow);
            SendMessage(fixMsg);
        }
Beispiel #3
0
        private void SendHeartbeat()
        {
            var fixMsg = (FIXMessage4_4)FixFactory.Create();

            fixMsg.AddHeader("0");
            SendMessage(fixMsg);
        }
Beispiel #4
0
        private void SendHeartbeat()
        {
            if (debug)
            {
                log.Debug("SendHeartBeat Status " + ConnectionStatus + ", Session Status Online " + isOrderServerOnline + ", Resend Complete " + IsResendComplete);
            }
            if (!IsRecovered)
            {
                TryEndRecovery();
            }
            if (IsRecovered)
            {
                lock (orderAlgorithmsLocker)
                {
                    foreach (var kvp in orderAlgorithms)
                    {
                        var algo = kvp.Value;
                        algo.OrderAlgorithm.RejectRepeatCounter = 0;
                        if (!algo.OrderAlgorithm.CheckForPending())
                        {
                            algo.OrderAlgorithm.ProcessOrders();
                        }
                    }
                }
            }
            var fixMsg = (FIXMessage4_2)FixFactory.Create();

            fixMsg.AddHeader("0");
            SendMessage(fixMsg);
            previousHeartbeatTime = recentHeartbeatTime;
            recentHeartbeatTime   = TimeStamp.UtcNow;
        }
        private void SendPositionUpdate(SymbolInfo symbol, int position)
        {
            var writePacket = fixSocket.CreatePacket();
            var mbtMsg      = (FIXMessage4_4)FixFactory.Create();

            mbtMsg.SetAccount("33006566");
            mbtMsg.SetSymbol(symbol.Symbol);
            if (position <= 0)
            {
                mbtMsg.SetShortQty(position);
            }
            else
            {
                mbtMsg.SetLongQty(position);
            }
            mbtMsg.AddHeader("AP");
            string message = mbtMsg.ToString();

            writePacket.DataOut.Write(message.ToCharArray());
            if (debug)
            {
                log.Debug("Sending position update: " + message);
            }
            fixPacketQueue.Enqueue(writePacket);
        }
Beispiel #6
0
        private void Logout()
        {
            var mbtMsg = FixFactory.Create();

            log.Info("Logout message = " + mbtMsg);
            mbtMsg.AddHeader("5");
            SendMessage(mbtMsg);
        }
Beispiel #7
0
        private FIXTMessage1_1 GapFillMessage(int currentSequence)
        {
            var message = FixFactory.Create(currentSequence);

            message.SetGapFill();
            message.SetNewSeqNum(currentSequence + 1);
            message.AddHeader("4");
            return(message);
        }
Beispiel #8
0
        private FIXTMessage1_1 CreateLoginResponse()
        {
            var mbtMsg = (FIXTMessage1_1)FixFactory.Create();

            mbtMsg.SetEncryption(0);
            mbtMsg.SetHeartBeatInterval(HeartbeatDelay);
            mbtMsg.AddHeader("A");
            mbtMsg.SetSendTime(new TimeStamp(1800, 1, 1));
            return(mbtMsg);
        }
Beispiel #9
0
        private void RequestOrders()
        {
            var fixMsg = (FIXMessage4_4)FixFactory.Create();

            fixMsg.SetAccount(AccountNumber);
            fixMsg.SetMassStatusRequestID(TimeStamp.UtcNow);
            fixMsg.SetMassStatusRequestType(90);
            fixMsg.AddHeader("AF");
            SendMessage(fixMsg);
        }
Beispiel #10
0
        private void SendHeartbeat()
        {
            var mbtMsg = (FIXTMessage1_1)FixFactory.Create();

            mbtMsg.AddHeader("0");
            if (trace)
            {
                log.Trace("Requesting heartbeat: " + mbtMsg);
            }
            SendMessage(mbtMsg);
        }
Beispiel #11
0
        private void SendLogout()
        {
            var mbtMsg = (FIXMessage4_2)FixFactory.Create();

            mbtMsg.AddHeader("5");
            SendMessage(mbtMsg);
            if (trace)
            {
                log.Trace("Sending logout confirmation: " + mbtMsg);
            }
        }
Beispiel #12
0
        private void RequestPositions()
        {
            var fixMsg = (FIXMessage4_4)FixFactory.Create();

            fixMsg.SetSubscriptionRequestType(1);
            fixMsg.SetAccount(AccountNumber);
            fixMsg.SetPositionRequestId(1);
            fixMsg.SetPositionRequestType(0);
            fixMsg.AddHeader("AN");
            SendMessage(fixMsg);
        }
Beispiel #13
0
        private void FIXPositionList(MessageFIX4_2 packet)
        {
            var mbtMsg = (FIXMessage4_4)FixFactory.Create();

            mbtMsg.SetText("DONE");
            mbtMsg.AddHeader("AO");
            if (debug)
            {
                log.Debug("Sending end of position list: " + mbtMsg);
            }
            SendMessage(mbtMsg);
        }
Beispiel #14
0
        private void FIXOrderList(MessageFIX4_2 packet)
        {
            var mbtMsg = (FIXMessage4_4)FixFactory.Create();

            mbtMsg.SetText("END");
            mbtMsg.AddHeader("8");
            if (debug)
            {
                log.Debug("Sending end of order list: " + mbtMsg);
            }
            SendMessage(mbtMsg);
        }
Beispiel #15
0
        private void SendSystemOffline()
        {
            var mbtMsg = FixFactory.Create();

            mbtMsg.AddHeader("5");
            mbtMsg.SetText("System offline");
            SendMessage(mbtMsg);
            if (trace)
            {
                log.Trace("Sending system offline simulation: " + mbtMsg);
            }
            //resetSequenceNumbersNextDisconnect = true;
        }
Beispiel #16
0
        private void OnBusinessRejectOrder(string clientOrderId, string error)
        {
            var mbtMsg = (FIXMessage4_2)FixFactory.Create();

            //mbtMsg.SetBusinessRejectReferenceId(clientOrderId);
            mbtMsg.SetText(error);
            mbtMsg.SetTransactTime(TimeStamp.UtcNow);
            mbtMsg.AddHeader("j");
            if (trace)
            {
                log.Trace("Sending business reject order: " + mbtMsg);
            }
            SendMessage(mbtMsg);
        }
        private void CloseWithFixError(PacketFIX4_4 packet, string message)
        {
            var       writePacket = fixSocket.CreatePacket();
            var       fixMsg      = (FIXMessage4_4)FixFactory.Create();
            TimeStamp timeStamp   = TimeStamp.UtcNow;

            fixMsg.SetAccount(packet.Account);
            fixMsg.SetText(message);
            fixMsg.AddHeader("j");
            string errorMessage = fixMsg.ToString();

            writePacket.DataOut.Write(errorMessage.ToCharArray());
            fixPacketQueue.Enqueue(writePacket);
        }
Beispiel #18
0
 protected virtual Yield OnHeartbeat()
 {
     if (fixSocket != null && FixFactory != null)
     {
         var mbtMsg = (FIXTMessage1_1)FixFactory.Create();
         mbtMsg.AddHeader("1");
         if (trace)
         {
             log.Trace("Requesting heartbeat: " + mbtMsg);
         }
         SendMessage(mbtMsg);
     }
     return(Yield.DidWork.Return);
 }
 private Yield OnHeartbeat()
 {
     if (fixSocket != null && FixFactory != null)
     {
         var writePacket = fixSocket.CreatePacket();
         var mbtMsg      = (FIXMessage4_4)FixFactory.Create();
         mbtMsg.AddHeader("1");
         string message = mbtMsg.ToString();
         writePacket.DataOut.Write(message.ToCharArray());
         if (trace)
         {
             log.Trace("Requesting heartbeat: " + message);
         }
         fixPacketQueue.Enqueue(writePacket);
     }
     return(Yield.DidWork.Return);
 }
Beispiel #20
0
        public override void OnRejectOrder(CreateOrChangeOrder order, string error)
        {
            var mbtMsg = (FIXMessage4_2)FixFactory.Create();

            mbtMsg.SetAccount("33006566");
            mbtMsg.SetClientOrderId(order.BrokerOrder.ToString());
            mbtMsg.SetOrderStatus("8");
            mbtMsg.SetText(error);
            mbtMsg.SetSymbol(order.Symbol.Symbol);
            mbtMsg.SetTransactTime(TimeStamp.UtcNow);
            mbtMsg.AddHeader("8");
            if (trace)
            {
                log.Trace("Sending reject order: " + mbtMsg);
            }
            SendMessage(mbtMsg);
        }
        private void FIXPositionList(PacketFIX4_4 packet)
        {
            var writePacket = fixSocket.CreatePacket();
            var mbtMsg      = (FIXMessage4_4)FixFactory.Create();

            mbtMsg.SetText("DONE");
            mbtMsg.AddHeader("AO");
            string message = mbtMsg.ToString();

            writePacket.DataOut.Write(message.ToCharArray());
            fixPacketQueue.Enqueue(writePacket);

            if (debug)
            {
                log.Debug("Sending end of position list: " + message);
            }
        }
Beispiel #22
0
        private bool Resend(MessageFIXT1_1 messageFix)
        {
            if (!isResendComplete)
            {
                return(true);
            }
            var mbtMsg = FixFactory.Create();

            mbtMsg.AddHeader("2");
            mbtMsg.SetBeginSeqNum(RemoteSequence);
            mbtMsg.SetEndSeqNum(0);
            if (debug)
            {
                log.Debug("Sending resend request: " + mbtMsg);
            }
            SendMessage(mbtMsg);
            return(true);
        }
Beispiel #23
0
        private void OnRejectCancel(string symbol, string clientOrderId, string origClientOrderId, string error)
        {
            var mbtMsg = (FIXMessage4_2)FixFactory.Create();

            mbtMsg.SetAccount("33006566");
            mbtMsg.SetClientOrderId(clientOrderId);
            mbtMsg.SetOriginalClientOrderId(origClientOrderId);
            mbtMsg.SetOrderStatus("8");
            mbtMsg.SetText(error);
            //mbtMsg.SetSymbol(symbol);
            mbtMsg.SetTransactTime(TimeStamp.UtcNow);
            mbtMsg.AddHeader("9");
            if (trace)
            {
                log.Trace("Sending reject cancel." + mbtMsg);
            }
            SendMessage(mbtMsg);
        }
        private void OnRejectOrder(PhysicalOrder order, string error)
        {
            var writePacket = fixSocket.CreatePacket();
            var mbtMsg      = (FIXMessage4_4)FixFactory.Create();

            mbtMsg.SetAccount("33006566");
            mbtMsg.SetClientOrderId(order.BrokerOrder.ToString());
            mbtMsg.SetOrderStatus("8");
            mbtMsg.SetText(error);
            mbtMsg.AddHeader("8");
            string message = mbtMsg.ToString();

            writePacket.DataOut.Write(message.ToCharArray());
            if (debug)
            {
                log.Debug("Sending position update: " + message);
            }
            fixPacketQueue.Enqueue(writePacket);
        }
Beispiel #25
0
        private void SendCancelOrder(CreateOrChangeOrder order, bool resend)
        {
            var fixMsg = (FIXMessage4_2)(resend ? FixFactory.Create(order.Sequence) : FixFactory.Create());

            order.Sequence = fixMsg.Sequence;
            OrderStore.SetOrder(order);
            var newClientOrderId = order.BrokerOrder;

            fixMsg.SetOriginalClientOrderId(order.OriginalOrder.BrokerOrder.ToString());
            fixMsg.SetClientOrderId(newClientOrderId.ToString());
#if NOT_LIME
            fixMsg.SetAccount(AccountNumber);
            fixMsg.SetSide(GetOrderSide(order.OriginalOrder.Side));
            fixMsg.SetSymbol(order.Symbol.Symbol);
            fixMsg.SetTransactTime(TimeStamp.UtcNow);
#endif
            fixMsg.AddHeader("F");
            if (resend)
            {
                fixMsg.SetDuplicate(true);
            }
            SendMessage(fixMsg);
        }
Beispiel #26
0
        private void OnCreateOrChangeBrokerOrder(PhysicalOrder physicalOrder, object origBrokerOrder, bool isChange)
        {
            var fixMsg = (FIXMessage4_4)FixFactory.Create();

            lock ( openOrdersLocker) {
                openOrders[(string)physicalOrder.BrokerOrder] = physicalOrder;
            }

            if (debug)
            {
                log.Debug("Adding Order to open order list: " + physicalOrder);
            }
            if (isChange)
            {
                fixMsg.SetClientOrderId((string)physicalOrder.BrokerOrder);
                fixMsg.SetOriginalClientOrderId((string)origBrokerOrder);
                var origOrder = GetPhysicalOrder((string)origBrokerOrder);
                if (origOrder != null)
                {
                    origOrder.Replace = physicalOrder;
                    if (debug)
                    {
                        log.Debug("Setting replace property of " + origBrokerOrder + " to " + physicalOrder.BrokerOrder);
                    }
                }
            }
            else
            {
                fixMsg.SetClientOrderId((string)physicalOrder.BrokerOrder);
            }
            fixMsg.SetAccount(AccountNumber);
            if (isChange)
            {
                fixMsg.AddHeader("G");
            }
            else
            {
                fixMsg.AddHeader("D");
                if (physicalOrder.Symbol.Destination.ToLower() == "default")
                {
                    fixMsg.SetDestination("MBTX");
                }
                else
                {
                    fixMsg.SetDestination(physicalOrder.Symbol.Destination);
                }
            }
            fixMsg.SetHandlingInstructions(1);
            fixMsg.SetSymbol(physicalOrder.Symbol.Symbol);
            fixMsg.SetSide(GetOrderSide(physicalOrder.Side));
            switch (physicalOrder.Type)
            {
            case OrderType.BuyLimit:
                fixMsg.SetOrderType(2);
                fixMsg.SetPrice(physicalOrder.Price);
                fixMsg.SetTimeInForce(1);
                break;

            case OrderType.BuyMarket:
                fixMsg.SetOrderType(1);
                fixMsg.SetTimeInForce(0);
                break;

            case OrderType.BuyStop:
                fixMsg.SetOrderType(3);
                fixMsg.SetPrice(physicalOrder.Price);
                fixMsg.SetStopPrice(physicalOrder.Price);
                fixMsg.SetTimeInForce(1);
                break;

            case OrderType.SellLimit:
                fixMsg.SetOrderType(2);
                fixMsg.SetPrice(physicalOrder.Price);
                fixMsg.SetTimeInForce(1);
                break;

            case OrderType.SellMarket:
                fixMsg.SetOrderType(1);
                fixMsg.SetTimeInForce(0);
                break;

            case OrderType.SellStop:
                fixMsg.SetOrderType(3);
                fixMsg.SetPrice(physicalOrder.Price);
                fixMsg.SetStopPrice(physicalOrder.Price);
                fixMsg.SetTimeInForce(1);
                break;
            }
            fixMsg.SetLocateRequired("N");
            fixMsg.SetTransactTime(TimeStamp.UtcNow);
            fixMsg.SetOrderQuantity((int)physicalOrder.Size);
            fixMsg.SetOrderCapacity("A");
            fixMsg.SetUserName();
            if (isChange)
            {
                if (debug)
                {
                    log.Debug("Change order: \n" + fixMsg);
                }
            }
            else
            {
                if (debug)
                {
                    log.Debug("Create new order: \n" + fixMsg);
                }
            }
            SendMessage(fixMsg);
        }
        private void SendExecutionReport(PhysicalOrder order, string status, double price, int orderQty, int cumQty, int lastQty, int leavesQty, TimeStamp time, PacketFIX4_4 packet)
        {
            int orderType = 0;

            switch (order.Type)
            {
            case OrderType.BuyMarket:
            case OrderType.SellMarket:
                orderType = 1;
                break;

            case OrderType.BuyLimit:
            case OrderType.SellLimit:
                orderType = 2;
                break;

            case OrderType.BuyStop:
            case OrderType.SellStop:
                orderType = 3;
                break;
            }
            int orderSide = 0;

            switch (order.Side)
            {
            case OrderSide.Buy:
                orderSide = 1;
                break;

            case OrderSide.Sell:
                orderSide = 2;
                break;

            case OrderSide.SellShort:
                orderSide = 5;
                break;
            }
            var writePacket = fixSocket.CreatePacket();
            var mbtMsg      = (FIXMessage4_4)FixFactory.Create();

            mbtMsg.SetAccount("33006566");
            mbtMsg.SetDestination("MBTX");
            mbtMsg.SetOrderQuantity(orderQty);
            mbtMsg.SetLastQuantity(Math.Abs(lastQty));
            if (lastQty != 0)
            {
                mbtMsg.SetLastPrice(price);
            }
            mbtMsg.SetCumulativeQuantity(Math.Abs(cumQty));
            mbtMsg.SetOrderStatus(status);
            mbtMsg.SetPositionEffect("O");
            mbtMsg.SetOrderType(orderType);
            mbtMsg.SetSide(orderSide);
            if (packet == null)
            {
                mbtMsg.SetClientOrderId(order.BrokerOrder.ToString());
            }
            else
            {
                mbtMsg.SetClientOrderId(packet.ClientOrderId);
                if (packet.OriginalClientOrderId != null)
                {
                    mbtMsg.SetOriginalClientOrderId(packet.OriginalClientOrderId);
                }
            }
            mbtMsg.SetPrice(order.Price);
            mbtMsg.SetSymbol(order.Symbol.Symbol);
            mbtMsg.SetTimeInForce(0);
            mbtMsg.SetExecutionType(status);
            mbtMsg.SetTransactTime(time);
            mbtMsg.SetLeavesQuantity(Math.Abs(leavesQty));
            mbtMsg.AddHeader("8");
            string message = mbtMsg.ToString();

            writePacket.DataOut.Write(message.ToCharArray());
            if (debug)
            {
                log.Debug("Sending execution report: " + message);
            }
            fixPacketQueue.Enqueue(writePacket);
        }
Beispiel #28
0
        private void OnCreateOrChangeBrokerOrder(CreateOrChangeOrder order, bool resend)
        {
            var fixMsg = (FIXMessage4_2)(resend ? FixFactory.Create(order.Sequence) : FixFactory.Create());

            order.Sequence = fixMsg.Sequence;
            OrderStore.SetOrder(order);
            OrderStore.SetSequences(RemoteSequence, FixFactory.LastSequence);

            if (order.Size > order.Symbol.MaxOrderSize)
            {
                throw new ApplicationException("Order was greater than MaxOrderSize of " + order.Symbol.MaxPositionSize + " for:\n" + order);
            }

            var orderHandler = GetAlgorithm(order.Symbol.BinaryIdentifier);
            var orderSize    = order.Type == OrderType.SellLimit || order.Type == OrderType.SellMarket || order.Type == OrderType.SellStop ? -order.Size : order.Size;

            if (Math.Abs(orderHandler.OrderAlgorithm.ActualPosition + orderSize) > order.Symbol.MaxPositionSize)
            {
                throw new ApplicationException("Order was greater than MaxPositionSize of " + order.Symbol.MaxPositionSize + " for:\n" + order);
            }

            if (debug)
            {
                log.Debug("Adding Order to open order list: " + order);
            }
            if (order.Action == OrderAction.Change)
            {
                var origBrokerOrder = order.OriginalOrder.BrokerOrder;
                fixMsg.SetClientOrderId(order.BrokerOrder.ToString());
                fixMsg.SetOriginalClientOrderId(origBrokerOrder.ToString());
                CreateOrChangeOrder origOrder;
                if (OrderStore.TryGetOrderById(origBrokerOrder, out origOrder))
                {
                    origOrder.ReplacedBy = order;
                    if (debug)
                    {
                        log.Debug("Setting replace property of " + origBrokerOrder + " to " + order.BrokerOrder);
                    }
                }
            }
            else
            {
                fixMsg.SetClientOrderId(order.BrokerOrder.ToString());
            }

            if (order.Action == OrderAction.Change)
            {
                fixMsg.AddHeader("G");
            }
            else
            {
                fixMsg.AddHeader("D");
                if (order.Symbol.Destination.ToLower() == "default")
                {
                    fixMsg.SetDestination(Destination);
                }
                else
                {
                    fixMsg.SetDestination(order.Symbol.Destination);
                }
            }
            fixMsg.SetSymbol(order.Symbol.Symbol);
            fixMsg.SetSide(order.Side == OrderSide.Buy ? 1 : 5);
            switch (order.Type)
            {
            case OrderType.BuyLimit:
                fixMsg.SetOrderType(2);
                fixMsg.SetPrice(order.Price);
                switch (order.Symbol.TimeInForce)
                {
                case TimeInForce.Day:
                    fixMsg.SetTimeInForce(0);
                    break;

                case TimeInForce.GTC:
                    throw new LimeException("Lime does not accept GTC Buy Lime Orders");

                default:
                    throw new ArgumentOutOfRangeException();
                }
                break;

            case OrderType.BuyMarket:
                fixMsg.SetOrderType(1);
                //fixMsg.SetTimeInForce(0);
                break;

            case OrderType.BuyStop:
                // throw new LimeException("Lime does not accept Buy Stop Orders");
                log.Error("Lime: Buy Stops not supproted");
                break;

            case OrderType.SellLimit:
                fixMsg.SetOrderType(2);
                fixMsg.SetPrice(order.Price);
                switch (order.Symbol.TimeInForce)
                {
                case TimeInForce.Day:
                    fixMsg.SetTimeInForce(0);
                    break;

                case TimeInForce.GTC:
                    throw new LimeException("Lime does not accept GTC Buy Lime Orders");

                default:
                    throw new ArgumentOutOfRangeException();
                }
                break;

            case OrderType.SellMarket:
                fixMsg.SetOrderType(1);
                //fixMsg.SetTimeInForce(0);
                break;

            case OrderType.SellStop:
                //throw new LimeException("Lime does not accept Sell Stop Orders");
                log.Error("Lime: Sell Stops not supproted");
                break;

            default:
                throw new LimeException("Unknown OrderType");
            }
            fixMsg.SetOrderQuantity((int)order.Size);
            if (order.Action == OrderAction.Change)
            {
                if (verbose)
                {
                    log.Verbose("Change order: \n" + fixMsg);
                }
            }
            else
            {
                if (verbose)
                {
                    log.Verbose("Create new order: \n" + fixMsg);
                }
            }
            if (resend)
            {
                fixMsg.SetDuplicate(true);
            }
#if NOT_LIME
            fixMsg.SetAccount(AccountNumber);
            fixMsg.SetHandlingInstructions(1);
            fixMsg.SetLocateRequired("N");
            fixMsg.SetTransactTime(order.UtcCreateTime);
            fixMsg.SetOrderCapacity("A");
            fixMsg.SetUserName();
#endif
            fixMsg.SetSendTime(order.UtcCreateTime);
            SendMessage(fixMsg);
        }
Beispiel #29
0
        private void SendExecutionReport(CreateOrChangeOrder order, string status, string executionType, double price, int orderQty, int cumQty, int lastQty, int leavesQty, TimeStamp time)
        {
            int orderType = 0;

            switch (order.Type)
            {
            case OrderType.BuyMarket:
            case OrderType.SellMarket:
                orderType = 1;
                break;

            case OrderType.BuyLimit:
            case OrderType.SellLimit:
                orderType = 2;
                break;

            default:
                throw new LimeException("Unsupproted order type");
            }
            int orderSide = 0;

            switch (order.Side)
            {
            case OrderSide.Buy:
                orderSide = 1;
                break;

            case OrderSide.Sell:
                orderSide = 2;
                break;

            case OrderSide.SellShort:
                orderSide = 5;
                break;
            }
            var mbtMsg = (FIXMessage4_2)FixFactory.Create();

            mbtMsg.SetOrderQuantity(orderQty);
            mbtMsg.SetLastQuantity(Math.Abs(lastQty));
            if (lastQty != 0)
            {
                mbtMsg.SetLastPrice(price);
            }
            mbtMsg.SetCumulativeQuantity(Math.Abs(cumQty));
            mbtMsg.SetOrderStatus(status);
            mbtMsg.SetPositionEffect("O");
            mbtMsg.SetOrderType(orderType);
            mbtMsg.SetSide(orderSide);
            mbtMsg.SetClientOrderId(order.BrokerOrder.ToString());
            if (order.OriginalOrder != null)
            {
                mbtMsg.SetOriginalClientOrderId(order.OriginalOrder.BrokerOrder.ToString());
            }
            mbtMsg.SetPrice(order.Price);
            mbtMsg.SetSymbol(order.Symbol.Symbol);
            mbtMsg.SetTimeInForce(0);
            mbtMsg.SetExecutionType(executionType);
            mbtMsg.SetExcTransType("0");
            mbtMsg.SetTransactTime(time);
            mbtMsg.SetLeavesQuantity(Math.Abs(leavesQty));
            mbtMsg.AddHeader("8");
            SendMessage(mbtMsg);
            if (trace)
            {
                log.Trace("Sending execution report: " + mbtMsg);
            }
        }