private void OnSessionOrderChanged(LmaxOrder lmaxOrder)
        {
            var transactionId = TryParseTransactionId(lmaxOrder.InstructionId);

            if (transactionId == null)
            {
                return;
            }

            LmaxOrderCondition condition = null;
            decimal            price     = 0;
            OrderTypes         orderType;

            switch (lmaxOrder.OrderType)
            {
            case OrderType.MARKET:
                orderType = OrderTypes.Market;
                break;

            case OrderType.LIMIT:
                orderType = OrderTypes.Limit;

                if (lmaxOrder.LimitPrice == null)
                {
                    throw new ArgumentException(LocalizedStrings.Str3394Params.Put(transactionId), nameof(lmaxOrder));
                }

                price = (decimal)lmaxOrder.LimitPrice;
                break;

            case OrderType.STOP_ORDER:
            case OrderType.STOP_LOSS_MARKET_ORDER:
            case OrderType.STOP_PROFIT_LIMIT_ORDER:
                orderType = OrderTypes.Conditional;

                if (lmaxOrder.StopPrice == null)
                {
                    throw new ArgumentException(LocalizedStrings.Str3395Params.Put(transactionId), nameof(lmaxOrder));
                }

                price = (decimal)lmaxOrder.StopPrice;

                condition = new LmaxOrderCondition
                {
                    StopLossOffset   = lmaxOrder.StopLossOffset,
                    TakeProfitOffset = lmaxOrder.StopProfitOffset,
                };
                break;

            case OrderType.CLOSE_OUT_ORDER_POSITION:
            case OrderType.CLOSE_OUT_POSITION:
            case OrderType.SETTLEMENT_ORDER:
            case OrderType.OFF_ORDERBOOK:
            case OrderType.REVERSAL:
            case OrderType.UNKNOWN:
                orderType = OrderTypes.Execute;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            DateTimeOffset?expiryDate = null;
            var            tif        = StockSharpTimeInForce.PutInQueue;

            switch (lmaxOrder.TimeInForce)
            {
            case LmaxTimeInForce.FillOrKill:
                tif = StockSharpTimeInForce.MatchOrCancel;
                break;

            case LmaxTimeInForce.ImmediateOrCancel:
                tif = StockSharpTimeInForce.CancelBalance;
                break;

            case LmaxTimeInForce.GoodForDay:
                expiryDate = DateTime.Today.ApplyTimeZone(TimeZoneInfo.Utc);
                break;

            case LmaxTimeInForce.GoodTilCancelled:
                break;

            case LmaxTimeInForce.Unknown:
                throw new NotSupportedException(LocalizedStrings.Str3396Params.Put(lmaxOrder.TimeInForce, transactionId.Value, lmaxOrder.OrderId));

            default:
                throw new InvalidOperationException(LocalizedStrings.Str3397Params.Put(lmaxOrder.TimeInForce, transactionId.Value, lmaxOrder.OrderId));
            }

            var msg = new ExecutionMessage
            {
                SecurityId = new SecurityId {
                    Native = lmaxOrder.InstrumentId
                },
                OriginalTransactionId = transactionId.Value,
                OrderType             = orderType,
                OrderPrice            = price,
                Condition             = condition,
                OrderVolume           = lmaxOrder.Quantity.Abs(),
                Side          = lmaxOrder.Quantity > 0 ? Sides.Buy : Sides.Sell,
                Balance       = lmaxOrder.Quantity - lmaxOrder.FilledQuantity,
                PortfolioName = lmaxOrder.AccountId.To <string>(),
                TimeInForce   = tif,
                ExpiryDate    = expiryDate,
                OrderStringId = lmaxOrder.OrderId,
                ExecutionType = ExecutionTypes.Transaction,
                Commission    = lmaxOrder.Commission,
                ServerTime    = CurrentTime.Convert(TimeZoneInfo.Utc),
                HasOrderInfo  = true,
            };

            msg.OrderState = lmaxOrder.CancelledQuantity > 0
                                                                ? OrderStates.Done
                                                                : (msg.Balance == 0 ? OrderStates.Done : OrderStates.Active);

            //msg.Action = lmaxOrder.CancelledQuantity > 0
            //				 ? ExecutionActions.Canceled
            //				 : (lmaxOrder.FilledQuantity == 0 ? ExecutionActions.Registered : ExecutionActions.Matched);

            SendOutMessage(msg);
        }
		private void OnSessionOrderChanged(LmaxOrder lmaxOrder)
		{
			var transactionId = TryParseTransactionId(lmaxOrder.InstructionId);

			if (transactionId == null)
				return;

			LmaxOrderCondition condition = null;
			decimal price = 0;
			OrderTypes orderType;

			switch (lmaxOrder.OrderType)
			{
				case OrderType.MARKET:
					orderType = OrderTypes.Market;
					break;
				case OrderType.LIMIT:
					orderType = OrderTypes.Limit;

					if (lmaxOrder.LimitPrice == null)
						throw new ArgumentException(LocalizedStrings.Str3394Params.Put(transactionId), nameof(lmaxOrder));

					price = (decimal)lmaxOrder.LimitPrice;
					break;
				case OrderType.STOP_ORDER:
				case OrderType.STOP_LOSS_MARKET_ORDER:
				case OrderType.STOP_PROFIT_LIMIT_ORDER:
					orderType = OrderTypes.Conditional;

					if (lmaxOrder.StopPrice == null)
						throw new ArgumentException(LocalizedStrings.Str3395Params.Put(transactionId), nameof(lmaxOrder));

					price = (decimal)lmaxOrder.StopPrice;

					condition = new LmaxOrderCondition
					{
						StopLossOffset = lmaxOrder.StopLossOffset,
						TakeProfitOffset = lmaxOrder.StopProfitOffset,
					};
					break;
				case OrderType.CLOSE_OUT_ORDER_POSITION:
				case OrderType.CLOSE_OUT_POSITION:
				case OrderType.SETTLEMENT_ORDER:
				case OrderType.OFF_ORDERBOOK:
				case OrderType.REVERSAL:
				case OrderType.UNKNOWN:
					orderType = OrderTypes.Execute;
					break;
				default:
					throw new ArgumentOutOfRangeException();
			}

			DateTimeOffset? expiryDate = null;
			var tif = StockSharpTimeInForce.PutInQueue;

			switch (lmaxOrder.TimeInForce)
			{
				case LmaxTimeInForce.FillOrKill:
					tif = StockSharpTimeInForce.MatchOrCancel;
					break;
				case LmaxTimeInForce.ImmediateOrCancel:
					tif = StockSharpTimeInForce.CancelBalance;
					break;
				case LmaxTimeInForce.GoodForDay:
					expiryDate = DateTime.Today.ApplyTimeZone(TimeZoneInfo.Utc);
					break;
				case LmaxTimeInForce.GoodTilCancelled:
					break;
				case LmaxTimeInForce.Unknown:
					throw new NotSupportedException(LocalizedStrings.Str3396Params.Put(lmaxOrder.TimeInForce, transactionId.Value, lmaxOrder.OrderId));
				default:
					throw new InvalidOperationException(LocalizedStrings.Str3397Params.Put(lmaxOrder.TimeInForce, transactionId.Value, lmaxOrder.OrderId));
			}

			var msg = new ExecutionMessage
			{
				SecurityId = new SecurityId { Native = lmaxOrder.InstrumentId },
				OriginalTransactionId = transactionId.Value,
				OrderType = orderType,
				OrderPrice = price,
				Condition = condition,
				OrderVolume = lmaxOrder.Quantity.Abs(),
				Side = lmaxOrder.Quantity > 0 ? Sides.Buy : Sides.Sell,
				Balance = lmaxOrder.Quantity - lmaxOrder.FilledQuantity,
				PortfolioName = lmaxOrder.AccountId.To<string>(),
				TimeInForce = tif,
				ExpiryDate = expiryDate,
				OrderStringId = lmaxOrder.OrderId,
				ExecutionType = ExecutionTypes.Transaction,
				Commission = lmaxOrder.Commission,
				ServerTime = CurrentTime.Convert(TimeZoneInfo.Utc)
			};

			msg.OrderState = lmaxOrder.CancelledQuantity > 0
								? OrderStates.Done
								: (msg.Balance == 0 ? OrderStates.Done : OrderStates.Active);

			//msg.Action = lmaxOrder.CancelledQuantity > 0
			//				 ? ExecutionActions.Canceled
			//				 : (lmaxOrder.FilledQuantity == 0 ? ExecutionActions.Registered : ExecutionActions.Matched);

			SendOutMessage(msg);
		}