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

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

            string modifiedId, operationResultMessage;
            ModifyOrderResponceMessage responce;

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

            responce.ResultMessage = operationResultMessage;
            return(responce);
        }
Ejemplo n.º 2
0
        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;

            ResponceMessage responceMessage = this.SendAndReceiveResponding <ResponceMessage>(
                SourceTransportInfo, message);

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

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

            ModifyOrderResponceMessage castedResponceMessage = (ModifyOrderResponceMessage)responceMessage;

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

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

            return(true);
        }
        // >>
        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)
                {
                    ModifyOrderResponceMessage message;
                    lock (this)
                    {
                        message = new ModifyOrderResponceMessage(_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);
            }
        }
        AccountResponceMessage Receive(ModifyOrderMessage message)
        {
            IImplementation implementation = _implementation;
            if (implementation == null || OperationalState != OperationalStateEnum.Operational)
            {
                return new AccountResponceMessage(message.AccountInfo, false);
            }

            string modifiedId, operationResultMessage;
            ModifyOrderResponceMessage responce;

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

            responce.ResultMessage = operationResultMessage;
            return responce;
        }