AccountResponseMessage Receive(ModifyOrderMessage message)
        {
            IImplementation implementation = _implementation;

            if (implementation == null || OperationalState != OperationalStateEnum.Operational)
            {
                return(new AccountResponseMessage(message.AccountInfo, false));
            }

            string modifiedId, operationResultMessage;
            ModifyOrderResponseMessage response;

            if (implementation.ModifyOrder(message.AccountInfo, message.OrderId, message.StopLoss, message.TakeProfit, message.TargetOpenPrice,
                                           out modifiedId, out operationResultMessage))
            {
                response = new ModifyOrderResponseMessage(message.AccountInfo,
                                                          message.OrderId, modifiedId, true);
            }
            else
            {
                response = new ModifyOrderResponseMessage(message.AccountInfo,
                                                          message.OrderId, modifiedId, false);
            }

            response.ResultMessage = operationResultMessage;
            return(response);
        }
        public bool ModifyOrder(AccountInfo account, Order order, decimal?stopLoss, decimal?takeProfit,
                                decimal?targetOpenPrice, out string modifiedId, out string operationResultMessage)
        {
            TracerHelper.Trace(this.Name);
            modifiedId = order.Id;

            if (OperationalState != OperationalStateEnum.Operational)
            {
                operationResultMessage = "Attempted operations on non operational order executioner.";
                SystemMonitor.Error(operationResultMessage);
                return(false);
            }

            ModifyOrderMessage message = new ModifyOrderMessage(account, order.Symbol, order.Id, stopLoss, takeProfit, targetOpenPrice, null);

            message.PerformSynchronous = true;

            ResponseMessage responseMessage = this.SendAndReceiveResponding <ResponseMessage>(
                SourceTransportInfo, message);

            if (responseMessage == null)
            {// Time out.
                operationResultMessage = "Timeout, failed receive result for order modification request. In this scenario inconsistency may occur!";
                SystemMonitor.Error(operationResultMessage);
                return(false);
            }

            if (responseMessage.OperationResult == false)
            {
                operationResultMessage = responseMessage.OperationResultMessage;
                return(false);
            }

            ModifyOrderResponseMessage castedResponseMessage = (ModifyOrderResponseMessage)responseMessage;

            SystemMonitor.CheckError(string.IsNullOrEmpty(castedResponseMessage.OrderModifiedId) == false, "Modified not assigned.");
            modifiedId             = castedResponseMessage.OrderModifiedId;
            operationResultMessage = "Order modified.";

            RaiseOrderUpdateEvent(account, castedResponseMessage.OrderId, order.Info, ActiveOrder.UpdateTypeEnum.Modified);

            return(true);
        }
        AccountResponseMessage Receive(ModifyOrderMessage message)
        {
            IImplementation implementation = _implementation;
            if (implementation == null || OperationalState != OperationalStateEnum.Operational)
            {
                return new AccountResponseMessage(message.AccountInfo, false);
            }

            string modifiedId, operationResultMessage;
            ModifyOrderResponseMessage response;

            if (implementation.ModifyOrder(message.AccountInfo, message.OrderId, message.StopLoss, message.TakeProfit, message.TargetOpenPrice,
                out modifiedId, out operationResultMessage))
            {
                response = new ModifyOrderResponseMessage(message.AccountInfo,
                    message.OrderId, modifiedId, true);
            }
            else
            {
                response = new ModifyOrderResponseMessage(message.AccountInfo,
                    message.OrderId, modifiedId, false);
            }

            response.ResultMessage = operationResultMessage;
            return response;
        }
        // >>
        public void OrderModified(string symbol, int operationID, int orderTicket, int orderNewTicket, bool operationResult, string operationResultMessage)
        {
            TracerHelper.Trace(symbol);
            try
            {
                OperationInformation operation = base.GetOperationById(operationID);

                if (operation != null)
                {
                    ModifyOrderResponseMessage message;
                    lock (this)
                    {
                        message = new ModifyOrderResponseMessage(_accountInfo, orderTicket.ToString(), orderNewTicket.ToString(), operationResult);
                        message.OperationResultMessage = operationResultMessage;
                    }

                    base.CompleteOperation(operationID, message);
                }

                lock (this)
                {
                    _pendingOrdersInformations.Add(orderTicket.ToString());
                }
            }
            catch (Exception ex)
            {// Make sure we handle any possible unexpected exceptions, as otherwise they bring the
                // entire package (MT4 included) down with a bad error.
                SystemMonitor.Error(ex.Message);
            }
        }