/// <summary>
        /// Will unsubscribe to previous one.
        /// </summary>
        protected bool SetRemoteStatusSynchronizationSource(TransportInfo sourceTransportInfo)
        {
            lock (this)
            {
                if (_remoteStatusSynchronizationSource != null)
                {
                    SubscribeToOperationalStateChangesMessage message = new SubscribeToOperationalStateChangesMessage(false);
                    message.RequestResponce = false;
                    SendResponding(_remoteStatusSynchronizationSource, message);
                }

                _remoteStatusSynchronizationSource = sourceTransportInfo;
            }

            bool result = true;

            if (sourceTransportInfo != null)
            {
                ResponceMessage responce = SendAndReceiveResponding <ResponceMessage>(sourceTransportInfo,
                                                                                      new SubscribeToOperationalStateChangesMessage(true));

                result = responce != null && responce.OperationResult;
            }

            TracerHelper.TraceEntry(this.GetType().Name + ", Remote synchronization source " + sourceTransportInfo.OriginalSenderId.Value.Id.Name + " assinged - " + result.ToString());
            return(result);
        }
        // >>
        public void OrderOpened(string symbol, int operationID, int orderTicket, decimal openingPrice, 
            int orderOpenTime, bool operationResult, string operationResultMessage)
        {
            TracerHelper.Trace(symbol);

            try
            {
                OperationInformation operation = base.GetOperationById(operationID);

                DateTime? time = GeneralHelper.GenerateDateTimeSecondsFrom1970(orderOpenTime);
                if (time.HasValue == false)
                {
                    if (operation != null)
                    {
                        base.CompleteOperation(operationID, new ResponceMessage(false, "Failed to convert time for order."));
                    }

                    SystemMonitor.Error("Failed to convert time for order.");
                    return;
                }

                string orderId = orderTicket.ToString();
                if (orderTicket < 0)
                {// The system needs orderId empty to recognize the result as failure.
                    orderId = string.Empty;
                    operationResult = false;
                }

                if (operation != null)
                {
                    ResponceMessage message = null;

                    lock (this)
                    {
                        if (operation.Request is SubmitOrderMessage)
                        {
                            message = new SubmitOrderResponceMessage(_accountInfo, orderId, true);
                            message.OperationResultMessage = operationResultMessage;
                            message.OperationResult = operationResult;
                        }
                        else if (operation.Request is ExecuteMarketOrderMessage)
                        {
                            OrderInfo info = new OrderInfo(orderId, CreateSymbol(symbol), OrderTypeEnum.UNKNOWN, OrderStateEnum.Executed, int.MinValue);
                            info.OpenTime = time;
                            info.OpenPrice = openingPrice;

                            message = new ExecuteMarketOrderResponceMessage(_accountInfo, info, operationResult);
                            message.OperationResultMessage = operationResultMessage;
                        }
                        else
                        {
                            SystemMonitor.Error("Failed to establish placed order request type.");
                            message = new ResponceMessage(false);
                        }
                    }

                    base.CompleteOperation(operationID, message);
                }

                if (string.IsNullOrEmpty(orderId) == false)
                {
                    // Do an update of this order.
                    lock (this)
                    {
                        _pendingOrdersInformations.Add(orderId);
                    }
                }
            }
            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);
            }
        }
        protected void Receive(ResponceMessage message)
        {
            if (Arbiter == null)
            {
                SystemMonitor.OperationWarning("Received message [" + message.GetType().Name + "] while already out of arbiter.");
                return;
            }

            ProxyForwardingSend(message);
        }
Пример #4
0
 /// <summary>
 ///
 /// </summary>
 public void CopyParameters(ResponceMessage message)
 {
     this._operationResult   = message.OperationResult;
     _exception              = message.Exception;
     _operationResultMessage = message.OperationResultMessage;
 }
 /// <summary>
 /// 
 /// </summary>
 public void CopyParameters(ResponceMessage message)
 {
     this._operationResult = message.OperationResult;
     _exception = message.Exception;
     _operationResultMessage = message.OperationResultMessage;
 }