/// <summary>
        ///
        /// </summary>
        void InitializeConnection()
        {
            _initializationEvent.Reset();

            if (OperationalState == OperationalStateEnum.Operational ||
                OperationalState == OperationalStateEnum.Initializing ||
                _integrationClient == null)
            {
                SystemMonitor.OperationWarning("Initialize called while operational or initializing.");
                _initializationEvent.Set();
                return;
            }

            ChangeOperationalState(OperationalStateEnum.Initializing);

            ResponceMessage result = this.SendAndReceiveAddressed <ResponceMessage>(
                IntegrationClientId, new SubscribeMessage());

            if (result == null || result.OperationResult == false)
            {
                SystemMonitor.OperationError("Failed to subscribe.", TracerItem.PriorityEnum.Medium);
                ChangeOperationalState(OperationalStateEnum.NotOperational);
                _initializationEvent.Set();

                return;
            }

            _initializationEvent.Set();
        }
Exemple #2
0
        public HttpResponseMessage GetLoadReport()  // IEnumerable(Of String)
        {
            List <SP_LoadReportByRId_Model> objLoadReport = new List <SP_LoadReportByRId_Model>();
            DataSet   Ds = SqlHelper.ExecuteDataset(strConn, CommandType.StoredProcedure, "SP_LoadReportByRId");
            DataTable Dt = Ds.Tables[0];

            if (Dt.Rows.Count > 0)
            {
                foreach (DataRow obj in Dt.Rows)
                {
                    SP_LoadReportByRId_Model Lis = new SP_LoadReportByRId_Model();

                    Lis.ReportId          = obj["ReportId"].ToString();
                    Lis.ReportName        = obj["ReportName"].ToString();
                    Lis.ReportDescription = obj["ReportDescription"].ToString();
                    Lis.ReportData        = obj["ReportData"].ToString();
                    Lis.IsPublish         = obj["IsPublish"].ToString();
                    Lis.PublishDate       = obj["PublishDate"].ToString();
                    Lis.PublishByUsername = obj["PublishByUsername"].ToString();

                    objLoadReport.Add(Lis);
                }
                return(Request.CreateResponse(HttpStatusCode.OK, objLoadReport));
            }
            else
            {
                ResponceMessage objErr = new ResponceMessage();
                objErr.code    = "1";
                objErr.message = "ไม่มีข้อมูล";
                return(Request.CreateResponse(HttpStatusCode.BadRequest, objErr));
            }
        }
Exemple #3
0
        public HttpResponseMessage LoadReportPermissionBy()  // IEnumerable(Of String)
        {
            string CategoryId = HttpContext.Current.Request.Form["CategoryId"].ToString();
            string RoleId     = HttpContext.Current.Request.Form["RoleId"].ToString();
            List <SP_LoadReportByRId_Model> objLoadReport = new List <SP_LoadReportByRId_Model>();
            DataSet Ds = SqlHelper.ExecuteDataset(strConn, CommandType.StoredProcedure, "SP_LoadReportPermissionBy",
                                                  new SqlParameter("@CategoryId", CategoryId)
                                                  , new SqlParameter("@RoleId", RoleId));
            DataTable Dt = Ds.Tables[0];

            if (Dt.Rows.Count > 0)
            {
                foreach (DataRow obj in Dt.Rows)
                {
                    SP_LoadReportByRId_Model Lis = new SP_LoadReportByRId_Model();

                    Lis.ReportId = obj["ReportId"].ToString();

                    Lis.ReportName = obj["ReportName"].ToString();

                    objLoadReport.Add(Lis);
                }
                return(Request.CreateResponse(HttpStatusCode.OK, objLoadReport));
            }
            else
            {
                ResponceMessage objErr = new ResponceMessage();
                objErr.code    = "1";
                objErr.message = "ไม่มีข้อมูล";
                return(Request.CreateResponse(HttpStatusCode.BadRequest, objErr));
            }
        }
        /// <summary>
        /// Get all sources that match the given criteria; multiple criteria can be combined in one sourceType
        /// using bitwise operators (for ex. operationResult = operationResult | SourceTypeEnum.Remote).
        /// </summary>
        /// <param name="sourceType"></param>
        /// <param name="partialMatch">Should we try to match filtering criteria fully or partially.</param>
        /// <returns></returns>
        public Dictionary <Symbol, TimeSpan[]> SearchSymbols(ComponentId sourceId, string symbolMatch)
        {
            if (IsLocalSource(sourceId))
            {
                ISourceDataDelivery delivery = ObtainDataDelivery(sourceId);
                return(delivery.SearchSymbols(symbolMatch));
            }

            List <ArbiterClientId?> sourcePath;

            if (GetSourcePath(sourceId, out sourcePath) == false)
            {
                SystemMonitor.OperationError("Failed to establish source path.");
                return(new Dictionary <Symbol, TimeSpan[]>());
            }

            RequestSymbolsMessage request = new RequestSymbolsMessage()
            {
                SymbolMatch = symbolMatch
            };
            ResponceMessage result = this.SendAndReceiveForwarding <ResponceMessage>(sourcePath, request);

            if (result != null && result.OperationResult)
            {
                return(((RequestSymbolsResponceMessage)result).SymbolsPeriods);
            }

            return(new Dictionary <Symbol, TimeSpan[]>());
        }
Exemple #5
0
        public HttpResponseMessage LoadReportByRoleId()  // IEnumerable(Of String)
        {
            string ReportId = "";

            if (HttpContext.Current.Request.Form["ReportId"].ToString() != null)
            {
                ReportId = HttpContext.Current.Request.Form["ReportId"].ToString();
            }
            List <LoadReportByRoleId_Model> objOnApp = new List <LoadReportByRoleId_Model>();
            DataSet Ds = SqlHelper.ExecuteDataset(strConn, CommandType.StoredProcedure, "SP_LoadReportByRoleId"
                                                  , new SqlParameter("@ReportId", ReportId));
            DataTable Dt = Ds.Tables[0];

            if (Dt.Rows.Count > 0)
            {
                foreach (DataRow obj in Dt.Rows)
                {
                    LoadReportByRoleId_Model item = new LoadReportByRoleId_Model();
                    item.RoleId      = obj["RoleId"].ToString();
                    item.RoleName    = obj["RoleName"].ToString();
                    item.Description = obj["Description"].ToString();
                    item.FullRole    = obj["FullRole"].ToString();
                    objOnApp.Add(item);
                }

                return(Request.CreateResponse(HttpStatusCode.OK, objOnApp));
            }
            else
            {
                ResponceMessage objErr = new ResponceMessage();
                objErr.code    = "0";
                objErr.message = "NoData";
                return(Request.CreateResponse(HttpStatusCode.BadRequest, objErr));
            }
        }
 /// <summary>
 ///
 /// </summary>
 protected bool CompleteOperation(int operationId, ResponceMessage message)
 {
     lock (this)
     {
         return(_stub.CompleteOperation(operationId.ToString(), message));
     }
 }
        protected void Receive(ResponceMessage message)
        {
            if (Arbiter == null)
            {
                SystemMonitor.OperationWarning("Received message [" + message.GetType().Name + "] while already out of arbiter.");
                return;
            }

            ProxyForwardingSend(message);
        }
Exemple #8
0
        /// <summary>
        ///
        /// </summary>
        public string SubmitOrder(AccountInfo account, Order order, Symbol symbol, OrderTypeEnum orderType,
                                  int volume, decimal?allowedSlippage, decimal?desiredPrice, decimal?takeProfit, decimal?stopLoss,
                                  string comment, out string operationResultMessage)
        {
            TracerHelper.Trace(this.Name);

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

            if (account.IsEmpty ||
                string.IsNullOrEmpty(account.Id) ||
                string.IsNullOrEmpty(account.Name))
            {
                operationResultMessage = "Account info on order execution provider not properly assigned.";
                return(null);
            }

            allowedSlippage = ProcessSlippage(allowedSlippage);

            SubmitOrderMessage request = new SubmitOrderMessage(account,
                                                                symbol, orderType, volume, desiredPrice, allowedSlippage, takeProfit, stopLoss, comment);

            request.RequestResponce    = true;
            request.PerformSynchronous = true;

            ResponceMessage responce = this.SendAndReceiveResponding <ResponceMessage>
                                           (SourceTransportInfo, request);

            if (responce == null)
            {// Time out.
                operationResultMessage = "Failed receive result for order request. In this scenario inconsistency may occur!";
                SystemMonitor.Error(operationResultMessage);
                return(null);
            }

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

            SubmitOrderResponceMessage responceMessage = (SubmitOrderResponceMessage)responce;

            operationResultMessage = "Order submited.";

            //RaiseOrderUpdateEvent(account, order.Info, Order.UpdateTypeEnum.Submitted);

            return(responceMessage.OrderId);
        }
Exemple #9
0
        /// <summary>
        ///
        /// </summary>
        public bool DecreaseOrderVolume(AccountInfo account, Order order, decimal volumeDecreasal, decimal?allowedSlippage,
                                        decimal?desiredPrice, out decimal decreasalPrice, out string modifiedId, out string operationResultMessage)
        {
            TracerHelper.Trace(this.Name);
            modifiedId     = order.Id;
            decreasalPrice = decimal.MinValue;

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

            allowedSlippage = ProcessSlippage(allowedSlippage);

            CloseOrderVolumeMessage message = new CloseOrderVolumeMessage(account, order.Symbol, order.Id,
                                                                          order.Tag, volumeDecreasal, desiredPrice, allowedSlippage);

            message.PerformSynchronous = true;

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

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

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

            CloseOrderVolumeResponceMessage responceMessage = (CloseOrderVolumeResponceMessage)responce;

            operationResultMessage = "Order volume decreased.";
            decreasalPrice         = responceMessage.ClosingPrice;

            // When modified, order changes its Id.
            modifiedId = responceMessage.OrderModifiedId;

            RaiseOrderUpdateEvent(account, responceMessage.OrderId, order.Info, ActiveOrder.UpdateTypeEnum.VolumeChanged);

            return(true);
        }
Exemple #10
0
        /// <summary>
        /// Helper.
        /// </summary>
        bool DoCloseOrder(AccountInfo account, Order order, decimal?allowedSlippage, decimal?desiredPrice, out decimal closingPrice,
                          out DateTime closingTime, out string modifiedId, out string operationResultMessage)
        {
            TracerHelper.Trace(this.Name);

            closingPrice = decimal.MinValue;
            closingTime  = DateTime.MinValue;
            modifiedId   = order.Id;

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

            allowedSlippage = ProcessSlippage(allowedSlippage);

            CloseOrderVolumeMessage message = new CloseOrderVolumeMessage(account, order.Symbol, order.Id,
                                                                          order.Tag, desiredPrice, allowedSlippage);

            message.PerformSynchronous = true;

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

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

            if (responce.OperationResult)
            {
                CloseOrderVolumeResponceMessage responceMessage = (CloseOrderVolumeResponceMessage)responce;
                operationResultMessage = "Order closed.";
                closingPrice           = responceMessage.ClosingPrice;
                closingTime            = responceMessage.ClosingDateTime;

                SystemMonitor.CheckError(order.Id == responceMessage.OrderId.ToString(), "Order id mismatch [" + order.Id + " / " + responceMessage.OrderId + "].");

                modifiedId = responceMessage.OrderModifiedId.ToString();
                return(true);
            }

            operationResultMessage = responce.OperationResultMessage;
            return(false);
        }
Exemple #11
0
        /// <summary>
        /// Subscribe to operations on this source accounts. Needed if we are to place orders properly etc.
        /// </summary>
        /// <returns></returns>
        public bool SubscribeToAccounts()
        {
            // Send a subscribe for this account too.
            SubscribeToSourceAccountsUpdatesMessage subscribeRequest = new SubscribeToSourceAccountsUpdatesMessage(true);
            ResponceMessage subscribeResponce = this.SendAndReceiveResponding <ResponceMessage>(
                SourceTransportInfo, subscribeRequest);

            if (subscribeResponce == null || subscribeResponce.OperationResult == false)
            {
                SystemMonitor.OperationError("Failed to subscribe to account.");
                return(false);
            }

            return(true);
        }
        public HttpResponseMessage DeleteReportsByRID()  // IEnumerable(Of String)
        {
            try
            {
                string ReportId = "";

                if (HttpContext.Current.Request.Form["ReportId"].ToString() != null)
                {
                    ReportId = HttpContext.Current.Request.Form["ReportId"].ToString();
                }
                List <DisplayOnApp> objOnApp = new List <DisplayOnApp>();
                DataSet             Ds       = SqlHelper.ExecuteDataset(strConn, CommandType.StoredProcedure, "SP_DeleteReportsByRID",
                                                                        new SqlParameter("@ReportId", ReportId));
                DataTable Dt = Ds.Tables[0];
                if (Dt.Rows.Count > 0)
                {
                    DeleteReportsByRID_Model delete = new DeleteReportsByRID_Model();
                    delete.Status  = "1";
                    delete.Message = "ลบข้อมูลสำเร็จ";


                    return(Request.CreateResponse(HttpStatusCode.OK, delete));
                }
                else
                {
                    ResponceMessage objErr = new ResponceMessage();
                    objErr.code    = "0";
                    objErr.message = "ลบข้อมูลไม่สำเร็จ";
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, objErr));
                }
            }
            catch (Exception ex)
            {
                //Error case เกิดข้อผิดพลาด
                UserError err = new UserError();
                err.status = "ผิดพลาด";
                err.code   = "6"; // error จากสาเหตุอื่นๆ จะมีรายละเอียดจาก system แจ้งกลับ

                err.message = ex.Message;
                //  Return resual
                return(Request.CreateResponse(HttpStatusCode.BadRequest, err));
            }
        }
Exemple #13
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);
        }
Exemple #14
0
        /// <summary>
        ///
        /// </summary>
        public bool GetAvailableAccountInfos(out AccountInfo[] accounts)
        {
            accounts = new AccountInfo[] { };
            if (SourceTransportInfo == null)
            {
                SystemMonitor.OperationWarning("Failed to obtain account information - SourceTransportInfo not assigned.");
                return(false);
            }

            GetAvailableAccountsMessage request  = new GetAvailableAccountsMessage();
            ResponceMessage             responce = this.SendAndReceiveResponding <ResponceMessage>(SourceTransportInfo, request);

            if (responce == null || responce.OperationResult == false)
            {
                return(false);
            }

            accounts = ((GetAvailableAccountsResponceMessage)responce).Accounts;
            return(true);
        }
        public HttpResponseMessage Update_ReportPermission()  // IEnumerable(Of String)
        {
            string ReportId = " ";
            string RoleId   = "";

            if (HttpContext.Current.Request.Form["ReportId"].ToString() != null)
            {
                ReportId = HttpContext.Current.Request.Form["ReportId"].ToString();
            }
            RoleId = HttpContext.Current.Request.Form["RoleId"].ToString();

            List <LoadReportByRoleId_Model> objOnApp = new List <LoadReportByRoleId_Model>();
            DataSet Ds = SqlHelper.ExecuteDataset(strConn, CommandType.StoredProcedure, "SP_Update_ReportPermission",
                                                  new SqlParameter("@ReportId", ReportId), new SqlParameter("@RoleId", RoleId));
            DataTable dt = new DataTable();

            dt = Ds.Tables[0];
            if (dt.Rows.Count > 0)
            {
                List <Dictionary <string, object> > rows = new List <Dictionary <string, object> >();
                Dictionary <string, object>         row;
                foreach (DataRow dr in dt.Rows)
                {
                    row = new Dictionary <string, object>();
                    foreach (DataColumn col in dt.Columns)
                    {
                        row.Add(col.ColumnName, dr[col]);
                    }
                    rows.Add(row);
                }
                return(Request.CreateResponse(HttpStatusCode.OK, rows));
            }

            else
            {
                ResponceMessage objErr = new ResponceMessage();
                objErr.code    = "0";
                objErr.message = "NoData";
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "NoData"));
            }
        }
        /// <summary>
        ///
        /// </summary>
        public Dictionary <Symbol, TimeSpan[]> SearchSymbols(string symbolMatchPattern)
        {
            if (OperationalState != OperationalStateEnum.Operational)
            {
                return(new Dictionary <Symbol, TimeSpan[]>());
            }

            RequestSymbolsMessage request = new RequestSymbolsMessage()
            {
                SymbolMatch = symbolMatchPattern
            };

            ResponceMessage responce = SendAndReceiveResponding <ResponceMessage>(SourceTransportInfo, request);

            if (responce != null && responce.OperationResult)
            {
                return(((RequestSymbolsResponceMessage)responce).SymbolsPeriods);
            }

            return(new Dictionary <Symbol, TimeSpan[]>());
        }
        /// <summary>
        ///
        /// </summary>
        public List <RuntimeDataSessionInformation> GetSymbolsRuntimeSessionInformations(Symbol[] symbols)
        {
            List <RuntimeDataSessionInformation> result = new List <RuntimeDataSessionInformation>();

            if (OperationalState != OperationalStateEnum.Operational)
            {
                SystemMonitor.Warning("Using stub when not operational.");
                return(result);
            }

            RequestSymbolsRuntimeInformationMessage request = new RequestSymbolsRuntimeInformationMessage(symbols);

            ResponceMessage responce = this.SendAndReceiveResponding <ResponceMessage>(
                SourceTransportInfo, request);

            if (responce == null || responce.OperationResult == false)
            {
                SystemMonitor.OperationError("Symbol session runtime information obtain failed due to timeout.");
                return(result);
            }

            return(((SessionsRuntimeInformationMessage)responce).Informations);
        }
        public bool RequestDataHistoryUpdate(DataSessionInfo sessionInfo, DataHistoryRequest request, bool waitResult)
        {
            if (OperationalState != OperationalStateEnum.Operational)
            {
                return(false);
            }

            RequestDataHistoryMessage requestMessage = new RequestDataHistoryMessage(sessionInfo, request)
            {
                RequestResponce = false
            };

            requestMessage.RequestResponce = waitResult;
            if (waitResult)
            {
                ResponceMessage responce = SendAndReceiveResponding <ResponceMessage>(SourceTransportInfo, requestMessage, this.DefaultTimeOut);
                return(responce != null && responce.OperationResult);
            }
            else
            {
                SendResponding(SourceTransportInfo, requestMessage);
                return(true);
            }
        }
        /// <summary>
        /// Get dataDelivery sessions for baseCurrency, source must be dataDelivery source.
        /// </summary>
        public DataSessionInfo?GetSymbolDataSessionInfo(ComponentId sourceId, Symbol symbol)
        {
            lock (_cachedDataSessions)
            {
                if (_cachedDataSessions.ContainsKey(sourceId) == false)
                {
                    _cachedDataSessions.Add(sourceId, new Dictionary <Symbol, DataSessionInfo?>());
                }

                if (_cachedDataSessions[sourceId].ContainsKey(symbol) == false)
                {
                    _cachedDataSessions[sourceId].Add(symbol, null);
                }
                else if (_cachedDataSessions[sourceId][symbol].HasValue)
                {
                    return(_cachedDataSessions[sourceId][symbol]);
                }
            }

            if (IsLocalSource(sourceId))
            {
                ISourceDataDelivery delivery = ObtainDataDelivery(sourceId);
                if (delivery == null)
                {
                    SystemMonitor.OperationError("Failed to establish local delivery.");
                    return(null);
                }

                RuntimeDataSessionInformation session = delivery.GetSymbolRuntimeSessionInformation(symbol);
                if (session == null)
                {
                    SystemMonitor.OperationError("Failed to establish symbol session [" + symbol.Name + "].");
                    return(null);
                }
                return(session.Info);
            }

            List <ArbiterClientId?> sourcePath;

            if (GetSourcePath(sourceId, out sourcePath) == false)
            {
                SystemMonitor.OperationError("Failed to establish source path.");
                return(null);
            }

            RequestSymbolsRuntimeInformationMessage request = new RequestSymbolsRuntimeInformationMessage(new Symbol[] { symbol });
            ResponceMessage responce = this.SendAndReceiveForwarding <ResponceMessage>(sourcePath, request);

            if (responce != null && responce.OperationResult)
            {
                SessionsRuntimeInformationMessage responceMessage = (SessionsRuntimeInformationMessage)responce;
                if (responceMessage.Informations.Count > 0)
                {
                    lock (_cachedDataSessions)
                    {
                        _cachedDataSessions[sourceId][symbol] = responceMessage.Informations[0].Info;
                    }

                    return(responceMessage.Informations[0].Info);
                }
            }

            return(null);
        }
Exemple #20
0
        // >>
        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);
            }
        }
Exemple #21
0
        /// <summary>
        /// Main SynchronousExecute method.
        /// </summary>
        public bool SynchronousExecute(AccountInfo account, Order order, Symbol symbol, OrderTypeEnum orderType,
                                       int volume, decimal?allowedSlippage, decimal?desiredPrice, decimal?takeProfit, decimal?stopLoss,
                                       string comment, TimeSpan operationTimeOut, out OrderInfo?info, out string operationResultMessage)
        {
            TracerHelper.Trace(this.Name);

            info = null;
            operationResultMessage = string.Empty;

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

            if (account.IsEmpty ||
                string.IsNullOrEmpty(account.Id))
            {
                operationResultMessage = "Account info on order execution provider not properly assigned.";
                return(false);
            }

            allowedSlippage = ProcessSlippage(allowedSlippage);

            ExecuteMarketOrderMessage request = new ExecuteMarketOrderMessage(account,
                                                                              symbol, orderType, volume, desiredPrice, allowedSlippage, takeProfit, stopLoss, comment);

            request.PerformSynchronous = true;

            ResponceMessage responce = this.SendAndReceiveResponding <ResponceMessage>
                                           (SourceTransportInfo, request, operationTimeOut);

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

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


            //if (orderType == OrderTypeEnum.BUY_MARKET
            //    || orderType == OrderTypeEnum.SELL_MARKET)
            //{// Immediate order.
            //    resultState = OrderStateEnum.Executed;
            //}
            //else
            //{// Delayed pending order.
            //    resultState = OrderStateEnum.Submitted;
            //}

            ExecuteMarketOrderResponceMessage responceMessage = (ExecuteMarketOrderResponceMessage)responce;

            operationResultMessage = "Order opened.";

            info = responceMessage.Info;

            //RaiseOrderUpdateEvent(account, order.Info, ActiveOrder.UpdateTypeEnum.Submitted);

            return(true);
        }