/// <summary>
        /// 
        /// </summary>
        /// <param name="Command"></param>
        /// <returns></returns>
        public static TradingServer.ClientBusiness.DealMessage FacadeMakeBinaryCommand(TradingServer.ClientBusiness.Command objCommand)
        {
            ClientBusiness.DealMessage Result = new ClientBusiness.DealMessage();
            Result.isDeal = false;

            Business.OpenTrade Command = new Business.OpenTrade();

            FillInstanceOpenTrade(objCommand, Command);

            #region CHECK TIME MARKET
            if (!Business.Market.IsOpen)
            {
                string Message = "AddBinary$False,MARKET IS CLOSE," + Command.ID + "," + Command.Investor.InvestorID + "," +
                            Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," +
                            Command.StopLoss + "," + Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," +
                            Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + "Open" + "," + 1 + "," +
                            Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," +
                            Command.Margin + ",Open";

                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();
                Command.Investor.ClientCommandQueue.Add(Message);

                Result.isDeal = false;
                Result.Error = "MARKET IS CLOSE";
                Result.Command = objCommand;

                return Result;
            }
            #endregion

            #region CHECK HOLIDAY OF SERVER(COMMENT)
            //if (Command.Symbol.IsHoliday == 1)
            //{
            //    string Message = "AddBinary$False,MARKET IS HOLIDAY," + Command.ID + "," + Command.Investor.InvestorID + "," +
            //                   Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," +
            //                   Command.StopLoss + "," + Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," +
            //                   Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + "Open" + "," + 1 + "," +
            //                   Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," +
            //                   Command.Margin + ",Open";

            //    if (Command.Investor.ClientCommandQueue == null)
            //        Command.Investor.ClientCommandQueue = new List<string>();
            //    Command.Investor.ClientCommandQueue.Add(Message);

            //    Result.isDeal = false;
            //    Result.Error = "MARKET IS HOLIDAY";
            //    Result.Command = objCommand;

            //    return Result;
            //}
            #endregion

            if (Command.Investor != null)
            {
                #region CHECK INVESTOR ISDISABLE
                if (Command.Investor.IsDisable)
                {
                    //Add Result To Client Command Queue Of Investor
                    string Message = "AddBinary$False,ACCOUNT IS DISABLED," + Command.ID + "," + Command.Investor.InvestorID + "," +
                            Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                "Open" + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                    if (Command.Investor.ClientBinaryQueue == null)
                        Command.Investor.ClientBinaryQueue = new List<string>();

                    Command.Investor.ClientBinaryQueue.Add(Message);

                    Result.isDeal = false;
                    Result.Error = "ACCOUNT IS DISABLED";
                    Result.Command = objCommand;

                    return Result;
                }
                #endregion

                #region CHECK INVESTOR READ ONLY
                if (Command.Investor.ReadOnly)
                {
                    //Add Result To Client Command Queue Of Investor
                    string Message = "AddBinary$False,TRADE IS DISABLED," + Command.ID + "," + Command.Investor.InvestorID + "," +
                            Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                "Open" + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                    if (Command.Investor.ClientBinaryQueue == null)
                        Command.Investor.ClientBinaryQueue = new List<string>();

                    Command.Investor.ClientBinaryQueue.Add(Message);

                    Result.isDeal = false;
                    Result.Error = "TRADE IS DISABLED";
                    Result.Command = objCommand;

                    return Result;
                }
                #endregion
            }

            //Command.OpenPrice = double.Parse(objCommand.OpenPrice);
            Command.Size = objCommand.Size;
            //Command.StopLoss = objCommand.StopLoss;
            //Command.TakeProfit = objCommand.TakeProfit;
            Command.ClientCode = objCommand.ClientCode;
            Command.CloseTime = DateTime.Now;
            Command.ExpTime = DateTime.Now;

            #region Get Setting IsTrade In Group
            bool IsTradeGroup = false;
            if (Business.Market.InvestorGroupList != null)
            {
                int count = Business.Market.InvestorGroupList.Count;
                for (int i = 0; i < count; i++)
                {
                    if (Business.Market.InvestorGroupList[i].InvestorGroupID == Command.Investor.InvestorGroupInstance.InvestorGroupID)
                    {
                        if (Business.Market.InvestorGroupList[i].ParameterItems != null)
                        {
                            int countParameter = Business.Market.InvestorGroupList[i].ParameterItems.Count;
                            for (int j = 0; j < countParameter; j++)
                            {
                                if (Business.Market.InvestorGroupList[i].ParameterItems[j].Code == "G01")
                                {
                                    if (Business.Market.InvestorGroupList[i].ParameterItems[j].BoolValue == 1)
                                        IsTradeGroup = true;

                                    break;
                                }
                            }
                        }
                        break;
                    }
                }
            }
            #endregion

            if (IsTradeGroup == true)
            {
                if (Command.Symbol == null || Command.Investor == null || Command.Type == null)
                {
                    Result.isDeal = false;

                    #region Session Close
                    ///Return false
                    ///
                    if (Command.Investor.ClientBinaryQueue == null)
                        Command.Investor.ClientBinaryQueue = new List<string>();

                    //Add String Command Server To Client
                    string Message = string.Empty;
                    Message = "AddBinary$False,Can't Find Symbol, Investor Or Type," + Command.ID + "," + Command.Investor.InvestorID + "," +
                                Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," +
                                Command.OpenPrice + "," + Command.StopLoss + "," + Command.TakeProfit + "," +
                                Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," +
                                Command.Profit + "," + "Comment," + Command.ID + "," + "BinaryTrading" + "," +
                                1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000" + "," +
                                Command.IsHedged + "," + "-1" + "," + Command.Margin + ",Binary";

                    Command.Investor.ClientBinaryQueue.Add(Message);
                    #endregion
                }
                else
                {
                    #region Check Lots Minimum And Maximum In IGroupSecurity And Check IsTrade In IGroupSecurity
                    bool IsTrade = false;
                    double Minimum = -1;
                    double Maximum = -1;
                    double Step = -1;
                    bool ResultCheckStepLots = false;

                    #region Get Config IGroupSecurity
                    if (Command.IGroupSecurity.IGroupSecurityConfig != null)
                    {
                        int countIGroupSecurityConfig = Command.IGroupSecurity.IGroupSecurityConfig.Count;
                        for (int i = 0; i < countIGroupSecurityConfig; i++)
                        {
                            if (Command.IGroupSecurity.IGroupSecurityConfig[i].Code == "B01")
                            {
                                if (Command.IGroupSecurity.IGroupSecurityConfig[i].BoolValue == 1)
                                    IsTrade = true;
                            }

                            if (Command.IGroupSecurity.IGroupSecurityConfig[i].Code == "B11")
                            {
                                double.TryParse(Command.IGroupSecurity.IGroupSecurityConfig[i].NumValue, out Minimum);
                            }

                            if (Command.IGroupSecurity.IGroupSecurityConfig[i].Code == "B12")
                            {
                                double.TryParse(Command.IGroupSecurity.IGroupSecurityConfig[i].NumValue, out Maximum);
                            }

                            if (Command.IGroupSecurity.IGroupSecurityConfig[i].Code == "B13")
                            {
                                double.TryParse(Command.IGroupSecurity.IGroupSecurityConfig[i].NumValue, out Step);
                            }
                        }
                    }
                    #endregion

                    if (IsTrade == true)
                    {
                        ResultCheckStepLots = Command.IGroupSecurity.CheckStepLots(Minimum, Maximum, Step, Command.Size);

                        #region If Check Step Lots False Return Client
                        if (ResultCheckStepLots == false)
                        {
                            string Message = "AddBinary$False,WRONG VOLUME," + Command.ID + "," + Command.Investor.InvestorID + "," +
                                    Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                        Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                        Command.Type.Name + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                            if (Command.Investor.ClientBinaryQueue == null)
                                Command.Investor.ClientBinaryQueue = new List<string>();

                            Command.Investor.ClientBinaryQueue.Add(Message);

                            Result.isDeal = false;
                            Result.Error = "WRONG VOLUME";
                            Result.Command = objCommand;

                            return Result;
                        }
                        #endregion
                    }
                    else
                    {
                        #region Check IsTrade  == False
                        string Message = "AddBinary$False,SYMBOL CANNOT BE TRADED," + Command.ID + "," + Command.Investor.InvestorID + "," +
                                    Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                        Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                        Command.Type.Name + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                        if (Command.Investor.ClientCommandQueue == null)
                            Command.Investor.ClientCommandQueue = new List<string>();

                        Command.Investor.ClientCommandQueue.Add(Message);

                        Result.isDeal = false;
                        Result.Error = "SYMBOL CANNOT BE TRADED";
                        Result.Command = objCommand;

                        return Result;
                        #endregion
                    }
                    #endregion

                    Command.Symbol.MarketAreaRef.AddCommand(Command);
                    Result.Command = objCommand;
                    Result.isDeal = true;
                }
            }
            else
            {
                if (Command.Investor != null)
                {
                    //Add Result To Client Command Queue Of Investor
                    string Message = "AddBinary$False,ACTION NOT ALLOWED," + Result + "," + Command.Investor.InvestorID + "," +
                            Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                Command.Type.Name + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                    if (Command.Investor.ClientCommandQueue == null)
                        Command.Investor.ClientCommandQueue = new List<string>();

                    Command.Investor.ClientCommandQueue.Add(Message);
                }
            }

            return Result;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// UPDATE ONLINE COMMAND
        /// </summary>
        /// <param name="Command"></param>
        /// <returns></returns>
        public static TradingServer.ClientBusiness.DealMessage FacadeUpdateOnlineCommand(TradingServer.ClientBusiness.Command objCommand)
        {
            TradingServer.ClientBusiness.DealMessage Result = new ClientBusiness.DealMessage();
            Result.isDeal = false;

            Business.OpenTrade Command = new Business.OpenTrade();

            //Find In Command List Of Symbol
            if (Business.Market.SymbolList != null)
            {
                int count = Business.Market.SymbolList.Count;
                bool flag = false;
                for (int i = 0; i < count; i++)
                {
                    if (flag == false)
                    {
                        if (Business.Market.SymbolList[i].CommandList != null)
                        {
                            int countCommand = Business.Market.SymbolList[i].CommandList.Count;
                            for (int j = 0; j < countCommand; j++)
                            {
                                if (Business.Market.SymbolList[i].CommandList[j].ID == objCommand.CommandID)
                                {
                                    #region SET VALUE FOR COMMAND
                                    Command.Symbol = Business.Market.SymbolList[i];
                                    Command.Investor = Business.Market.SymbolList[i].CommandList[j].Investor;
                                    Command.Type = Business.Market.SymbolList[i].CommandList[j].Type;
                                    Command.Size = Business.Market.SymbolList[i].CommandList[j].Size;
                                    Command.ClosePrice = Business.Market.SymbolList[i].CommandList[j].ClosePrice;

                                    bool isPending = TradingServer.Model.TradingCalculate.Instance.CheckIsPendingPosition(Business.Market.SymbolList[i].CommandList[j].Type.ID);
                                    double tempOpenPrice = 0;
                                    if (isPending)
                                        tempOpenPrice = double.Parse(objCommand.OpenPrice);
                                    else
                                        tempOpenPrice = Business.Market.SymbolList[i].CommandList[j].OpenPrice;

                                    Command.OpenPrice = tempOpenPrice;
                                    Command.CommandCode = Business.Market.SymbolList[i].CommandList[j].CommandCode;
                                    Command.IGroupSecurity = Business.Market.SymbolList[i].CommandList[j].IGroupSecurity;
                                    #endregion

                                    #region INSERT SYSTEM LOG BEFORE MODIFY COMMAND
                                    string content = string.Empty;
                                    string comment = "[modify order]";
                                    string mode = TradingServer.Facade.FacadeGetTypeNameByTypeID(Command.Type.ID).ToLower();

                                    string size = TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Command.Size.ToString(), 2);
                                    string openPrice = string.Empty;
                                    string afterOpenPrice = string.Empty;
                                    string stopLoss = TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(objCommand.StopLoss.ToString(),
                                        Command.Symbol.Digit);
                                    string takeProfit = TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(objCommand.TakeProfit.ToString(),
                                        Command.Symbol.Digit);
                                    string bid = TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Business.Market.SymbolList[i].CommandList[j].Symbol.TickValue.Bid.ToString(),
                                        Business.Market.SymbolList[i].CommandList[j].Symbol.Digit);
                                    string ask = TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Business.Market.SymbolList[i].CommandList[j].Symbol.TickValue.Ask.ToString(),
                                        Business.Market.SymbolList[i].CommandList[j].Symbol.Digit);

                                    openPrice = TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Business.Market.SymbolList[i].CommandList[j].OpenPrice.ToString(),
                                    Business.Market.SymbolList[i].Digit);

                                    if (objCommand.OpenPrice != null && !string.IsNullOrEmpty(objCommand.OpenPrice))
                                    {
                                        afterOpenPrice = TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(objCommand.OpenPrice.ToString(), Business.Market.SymbolList[i].Digit);
                                    }
                                    else
                                    {
                                        afterOpenPrice = openPrice;
                                    }

                                    string firstStopLoss = TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Business.Market.SymbolList[i].CommandList[j].StopLoss.ToString(), Business.Market.SymbolList[i].Digit);
                                    string firstTakeProfit = TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Business.Market.SymbolList[i].CommandList[j].TakeProfit.ToString(), Business.Market.SymbolList[i].Digit);
                                    content = "'" + Command.Investor.Code + "': modify order #" + Command.CommandCode + " " + mode + " " + size + " " + Command.Symbol.Name + " at " + openPrice +
                                                " sl: " + firstStopLoss + " tp: " + firstTakeProfit + " -> open price " + afterOpenPrice + " sl: " + stopLoss + " tp: " + takeProfit + " (" + bid + "/" + ask + ")";

                                    TradingServer.Facade.FacadeAddNewSystemLog(5, content, comment, objCommand.IpAddress, Command.Investor.Code);
                                    #endregion

                                    bool isRequest = false;
                                    if (Business.Market.marketInstance.MQLCommands != null)
                                    {
                                        int countMQL = Business.Market.marketInstance.MQLCommands.Count;
                                        for (int n = 0; n < countMQL; n++)
                                        {
                                            if (Business.Market.marketInstance.MQLCommands[n].ClientCode == objCommand.ClientCode)
                                            {
                                                isRequest = true;
                                                break;
                                            }
                                        }

                                        if (!isRequest)
                                        {
                                            NJ4XConnectSocket.MQLCommand newMQLCommand = new NJ4XConnectSocket.MQLCommand();
                                            newMQLCommand.ClientCode = objCommand.ClientCode;
                                            newMQLCommand.InvestorCode = Command.Investor.Code;
                                            newMQLCommand.IpAddress = objCommand.IpAddress;

                                            Business.Market.marketInstance.MQLCommands.Add(newMQLCommand);
                                        }
                                    }

                                    #region CHECK INVESTOR ONLINE(CHECK ACCOUNT READ ONLY)
                                    bool _checkOnline = TradingServer.Business.Investor.investorInstance.CheckPrimaryInvestorOnline(Business.Market.SymbolList[i].CommandList[j].Investor.InvestorID,
                                                                                                                                        Business.TypeLogin.Primary, objCommand.LoginKey);
                                    if (!_checkOnline)
                                    {
                                        Result.isDeal = false;
                                        Result.Command = objCommand;
                                        Result.Error = "ACCOUNT READ ONLY";

                                        string Message = "UpdateCommand$False,ACCOUNT READ ONLY," + Command.ID + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Investor.InvestorID + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Symbol.Name + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Size + "," + false + "," +
                                                Business.Market.SymbolList[i].CommandList[j].OpenTime + "," +
                                                Business.Market.SymbolList[i].CommandList[j].OpenPrice + "," +
                                                Business.Market.SymbolList[i].CommandList[j].StopLoss + "," +
                                                Business.Market.SymbolList[i].CommandList[j].TakeProfit + "," +
                                                Business.Market.SymbolList[i].CommandList[j].ClosePrice + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Commission + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Swap + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Profit + "," + "Comment," +
                                                Business.Market.SymbolList[i].CommandList[j].ID + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Type.Name + "," +
                                                1 + "," + Business.Market.SymbolList[i].CommandList[j].ExpTime + "," +
                                                Business.Market.SymbolList[i].CommandList[j].ClientCode + "," +
                                                Business.Market.SymbolList[i].CommandList[j].CommandCode + "," +
                                                Business.Market.SymbolList[i].CommandList[j].IsHedged + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Type.ID + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Margin + ",Update";

                                        //If Client Update Command Then Add Message To Client Message
                                        if (Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue == null)
                                            Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue = new List<string>();

                                        Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue.Add(Message);

                                        #region INSERT SYSTEM LOG CHECK ACCOUNT INVESTOR TRADE IS DISABLED
                                        string tempContent = string.Empty;
                                        tempContent = "'" + Command.Investor.Code + "': modified #" + Command.CommandCode + " " + mode + " " + size + " " + Command.Symbol.Name + " at " +
                                            openPrice + " sl: " + stopLoss + " tp: " + takeProfit + " unsuccesful [account read only] (" + bid + "/" + ask + ")";

                                        TradingServer.Facade.FacadeAddNewSystemLog(5, tempContent, comment, Command.Investor.IpAddress, Command.Investor.Code);
                                        #endregion

                                        return Result;
                                    }
                                    #endregion

                                    #region CHECK IF MANUAL ONLY THEN SEND TO MT4 CLIENT(MQL OR NJ4X)
                                    string executionType = Business.Market.marketInstance.GetExecutionType(Command.IGroupSecurity, "B03");

                                    if (executionType == "manual only- no automation" ||
                                        executionType == "manual- but automatic if no dealer online" ||
                                        executionType == "automatic only")
                                    {
                                        Command.StopLoss = objCommand.StopLoss;
                                        Command.TakeProfit = objCommand.TakeProfit;
                                        Command.ID = objCommand.CommandID;
                                        Command.Comment = objCommand.Comment;

                                        Command.Symbol.MarketAreaRef.UpdateCommand(Command);

                                        Result.isDeal = true;
                                        Result.Command = objCommand;

                                        return Result;
                                    }
                                    #endregion

                                    #region CHECK SYMBOL ON HOLD
                                    if (!Business.Market.SymbolList[i].CheckTimeTick())
                                    {
                                        #region MAP COMMAND TO CLIENT
                                        if (Business.Market.SymbolList[i].CommandList[j].Investor != null)
                                        {
                                            string message = "UpdateCommand$False,MARKET ON HOLD," + Business.Market.SymbolList[i].CommandList[j].ID + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Investor.InvestorID + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Symbol.Name + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Size + "," + false + "," +
                                            Business.Market.SymbolList[i].CommandList[j].OpenTime + "," +
                                            Business.Market.SymbolList[i].CommandList[j].OpenPrice + "," +
                                            Business.Market.SymbolList[i].CommandList[j].StopLoss + "," +
                                            Business.Market.SymbolList[i].CommandList[j].TakeProfit + "," +
                                            Business.Market.SymbolList[i].CommandList[j].ClosePrice + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Commission + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Swap + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Profit + "," + "Comment," +
                                            Business.Market.SymbolList[i].CommandList[j].ID + "," + "BuyFutureCommand" + "," + 1 + "," +
                                            Business.Market.SymbolList[i].CommandList[j].ExpTime + "," +
                                            Business.Market.SymbolList[i].CommandList[j].ClientCode + "," + "0000000," +
                                            Business.Market.SymbolList[i].CommandList[j].IsHedged + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Type.ID + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Margin + ",Open";

                                            if (Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue == null)
                                                Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue = new List<string>();

                                            Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue.Add(message);
                                        }
                                        #endregion

                                        Result.isDeal = false;
                                        Result.Error = "MARKET ON HOLD";
                                        Result.Command = objCommand;

                                        #region INSERT SYSTEM LOG TIME SESSION OF SYMBOL FUTURE
                                        string tempContent = "update online command";
                                        tempContent += " unsucessful [symbol on hold]";

                                        TradingServer.Facade.FacadeAddNewSystemLog(5, tempContent, "[symbol on hold]", Business.Market.SymbolList[i].CommandList[j].Investor.IpAddress,
                                            Business.Market.SymbolList[i].CommandList[j].Investor.Code);
                                        #endregion

                                        return Result;
                                    }
                                    #endregion

                                    #region IF SYMBOL IS FUTURE THEN CHECK TIME SESSION OF FUTURE
                                    if (Business.Market.SymbolList[i].MarketAreaRef.IMarketAreaName == "FutureCommand")
                                    {
                                        if (Business.Market.SymbolList[i].isCloseOnlyFuture)
                                        {
                                            string message = "UpdateCommand$False,SYMBOL CLOSE ONLY," + Business.Market.SymbolList[i].CommandList[j].ID + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Investor.InvestorID + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Symbol.Name + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Size + "," + false + "," +
                                            Business.Market.SymbolList[i].CommandList[j].OpenTime + "," +
                                            Business.Market.SymbolList[i].CommandList[j].OpenPrice + "," +
                                            Business.Market.SymbolList[i].CommandList[j].StopLoss + "," +
                                            Business.Market.SymbolList[i].CommandList[j].TakeProfit + "," +
                                            Business.Market.SymbolList[i].CommandList[j].ClosePrice + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Commission + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Swap + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Profit + "," + "Comment," +
                                            Business.Market.SymbolList[i].CommandList[j].ID + "," + "BuyFutureCommand" + "," + 1 + "," +
                                            Business.Market.SymbolList[i].CommandList[j].ExpTime + "," +
                                            Business.Market.SymbolList[i].CommandList[j].ClientCode + "," + "0000000," +
                                            Business.Market.SymbolList[i].CommandList[j].IsHedged + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Type.ID + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Margin + ",BuyFutureCommand";

                                            if (Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue == null)
                                                Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue = new List<string>();

                                            Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue.Add(message);

                                            Result.isDeal = false;
                                            Result.Error = "SYMBOL CLOSE ONLY";
                                            Result.Command = objCommand;

                                            #region INSERT SYSTEM LOG TIME SESSION OF SYMBOL FUTURE
                                            string tempContent = string.Empty;
                                            tempContent = "'" + Command.Investor.Code + "': modified #" + Command.CommandCode + " " + mode + " " + size + " " + Command.Symbol.Name + " at " +
                                                openPrice + " sl: " + stopLoss + " tp: " + takeProfit + " unsuccesful [symbol is close] (" + bid + "/" + ask + ")";

                                            TradingServer.Facade.FacadeAddNewSystemLog(5, tempContent, comment, Command.Investor.IpAddress, Command.Investor.Code);
                                            #endregion

                                            return Result;
                                        }
                                    }
                                    #endregion

                                    #region CHECK IP ADDRESS
                                    bool checkIP = TradingServer.Business.ValidIPAddress.Instance.ValidIpAddress(Business.Market.SymbolList[i].CommandList[j].Investor.InvestorID,
                                                                                                                    objCommand.IpAddress);
                                    if (!checkIP)
                                    {
                                        Result.isDeal = false;
                                        Result.Command = objCommand;
                                        Result.Error = "INVALID IP ADDRESS";

                                        string Message = "UpdateCommand$False,INVALID IP ADDRESS," + Command.ID + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Investor.InvestorID + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Symbol.Name + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Size + "," + false + "," +
                                                Business.Market.SymbolList[i].CommandList[j].OpenTime + "," +
                                                Business.Market.SymbolList[i].CommandList[j].OpenPrice + "," +
                                                Business.Market.SymbolList[i].CommandList[j].StopLoss + "," +
                                                Business.Market.SymbolList[i].CommandList[j].TakeProfit + "," +
                                                Business.Market.SymbolList[i].CommandList[j].ClosePrice + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Commission + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Swap + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Profit + "," + "Comment," +
                                                Business.Market.SymbolList[i].CommandList[j].ID + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Type.Name + "," +
                                                1 + "," + Business.Market.SymbolList[i].CommandList[j].ExpTime + "," +
                                                Business.Market.SymbolList[i].CommandList[j].ClientCode + "," +
                                                Business.Market.SymbolList[i].CommandList[j].CommandCode + "," +
                                                Business.Market.SymbolList[i].CommandList[j].IsHedged + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Type.ID + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Margin + ",Update";

                                        //If Client Update Command Then Add Message To Client Message
                                        if (Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue == null)
                                            Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue = new List<string>();

                                        Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue.Add(Message);

                                        #region INSERT SYSTEM LOG CHECK ACCOUNT INVESTOR TRADE IS DISABLED
                                        string tempContent = string.Empty;
                                        tempContent = "'" + Command.Investor.Code + "': modified #" + Command.CommandCode + " " + mode + " " + size + " " + Command.Symbol.Name + " at " +
                                            openPrice + " sl: " + stopLoss + " tp: " + takeProfit + " unsuccesful [invalid ip address] (" + bid + "/" + ask + ")";

                                        TradingServer.Facade.FacadeAddNewSystemLog(5, tempContent, comment, Command.Investor.IpAddress, Command.Investor.Code);
                                        #endregion

                                        return Result;
                                    }
                                    #endregion

                                    bool isOnline = TradingServer.Business.Investor.investorInstance.CheckInvestorOnline(Business.Market.SymbolList[i].CommandList[j].Investor.InvestorID,
                                        Business.Market.SymbolList[i].CommandList[j].Investor.LoginKey);
                                    if (!isOnline)
                                    {
                                        //ADD CLIENT TO LIST ONLINE IF CLIENT TIMEOUT
                                        TradingServer.Business.Investor.investorInstance.CheckOnlineInvestor(Business.Market.SymbolList[i].CommandList[j].Investor.InvestorID,
                                            Business.Market.SymbolList[i].CommandList[j].Investor.LoginKey);
                                    }

                                    #region CHECK INVESTOR ONLINE(CHECK ACCOUNT READ ONLY)
                                    bool checkOnline = TradingServer.Business.Investor.investorInstance.CheckPrimaryInvestorOnline(Business.Market.SymbolList[i].CommandList[j].Investor.InvestorID,
                                                                                                                                        Business.TypeLogin.Primary, objCommand.LoginKey);
                                    if (!checkOnline)
                                    {
                                        Result.isDeal = false;
                                        Result.Command = objCommand;
                                        Result.Error = "ACCOUNT READ ONLY";

                                        string Message = "UpdateCommand$False,ACCOUNT READ ONLY," + Command.ID + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Investor.InvestorID + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Symbol.Name + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Size + "," + false + "," +
                                                Business.Market.SymbolList[i].CommandList[j].OpenTime + "," +
                                                Business.Market.SymbolList[i].CommandList[j].OpenPrice + "," +
                                                Business.Market.SymbolList[i].CommandList[j].StopLoss + "," +
                                                Business.Market.SymbolList[i].CommandList[j].TakeProfit + "," +
                                                Business.Market.SymbolList[i].CommandList[j].ClosePrice + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Commission + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Swap + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Profit + "," + "Comment," +
                                                Business.Market.SymbolList[i].CommandList[j].ID + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Type.Name + "," +
                                                1 + "," + Business.Market.SymbolList[i].CommandList[j].ExpTime + "," +
                                                Business.Market.SymbolList[i].CommandList[j].ClientCode + "," +
                                                Business.Market.SymbolList[i].CommandList[j].CommandCode + "," +
                                                Business.Market.SymbolList[i].CommandList[j].IsHedged + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Type.ID + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Margin + ",Update";

                                        //If Client Update Command Then Add Message To Client Message
                                        if (Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue == null)
                                            Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue = new List<string>();

                                        Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue.Add(Message);

                                        #region INSERT SYSTEM LOG CHECK ACCOUNT INVESTOR TRADE IS DISABLED
                                        string tempContent = string.Empty;
                                        tempContent = "'" + Command.Investor.Code + "': modified #" + Command.CommandCode + " " + mode + " " + size + " " + Command.Symbol.Name + " at " +
                                            openPrice + " sl: " + stopLoss + " tp: " + takeProfit + " unsuccesful [account read only] (" + bid + "/" + ask + ")";

                                        TradingServer.Facade.FacadeAddNewSystemLog(5, tempContent, comment, Command.Investor.IpAddress, Command.Investor.Code);
                                        #endregion

                                        return Result;
                                    }
                                    #endregion

                                    #region CHECK ACCOUNT INVESTOR LOGIN WITH READ ONLY PASSWORD
                                    if (Business.Market.SymbolList[i].CommandList[j].Investor.IsReadOnly)
                                    {
                                        string Message = "UpdateCommand$False,TRADE IS DISABLED," + Command.ID + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Investor.InvestorID + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Symbol.Name + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Size + "," + false + "," +
                                                Business.Market.SymbolList[i].CommandList[j].OpenTime + "," +
                                                Business.Market.SymbolList[i].CommandList[j].OpenPrice + "," +
                                                Business.Market.SymbolList[i].CommandList[j].StopLoss + "," +
                                                Business.Market.SymbolList[i].CommandList[j].TakeProfit + "," +
                                                Business.Market.SymbolList[i].CommandList[j].ClosePrice + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Commission + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Swap + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Profit + "," + "Comment," +
                                                Business.Market.SymbolList[i].CommandList[j].ID + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Type.Name + "," +
                                                1 + "," + Business.Market.SymbolList[i].CommandList[j].ExpTime + "," +
                                                Business.Market.SymbolList[i].CommandList[j].ClientCode + "," +
                                                Business.Market.SymbolList[i].CommandList[j].CommandCode + "," +
                                                Business.Market.SymbolList[i].CommandList[j].IsHedged + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Type.ID + "," +
                                                Business.Market.SymbolList[i].CommandList[j].Margin + ",Update";

                                        //If Client Update Command Then Add Message To Client Message
                                        if (Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue == null)
                                            Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue = new List<string>();

                                        Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue.Add(Message);

                                        Result.isDeal = false;
                                        Result.Command = objCommand;
                                        Result.Error = "TRADE IS DISABLED";

                                        #region INSERT SYSTEM LOG CHECK ACCOUNT INVESTOR TRADE IS DISABLED
                                        string tempContent = string.Empty;
                                        tempContent = "'" + Command.Investor.Code + "': modified #" + Command.CommandCode + " " + mode + " " + size + " " + Command.Symbol.Name + " at " +
                                            openPrice + " sl: " + stopLoss + " tp: " + takeProfit + " unsuccesful [trade is disabled] (" + bid + "/" + ask + ")";

                                        TradingServer.Facade.FacadeAddNewSystemLog(5, tempContent, comment, Command.Investor.IpAddress, Command.Investor.Code);
                                        #endregion

                                        return Result;
                                    }
                                    #endregion

                                    #region CHECK TIME MARKET
                                    if (!Business.Market.IsOpen)
                                    {
                                        string Message = "UpdateCommand$False,MARKET IS CLOSE," + Business.Market.SymbolList[i].CommandList[j].ID + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Investor.InvestorID + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Symbol.Name + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Size + "," + false + "," +
                                            Business.Market.SymbolList[i].CommandList[j].OpenTime + "," +
                                            Business.Market.SymbolList[i].CommandList[j].OpenPrice + "," +
                                            Business.Market.SymbolList[i].CommandList[j].StopLoss + "," +
                                            Business.Market.SymbolList[i].CommandList[j].TakeProfit + "," +
                                            Business.Market.SymbolList[i].CommandList[j].ClosePrice + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Commission + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Swap + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Profit + "," + "Comment," +
                                            Business.Market.SymbolList[i].CommandList[j].ID + "," + "Open" + "," + 1 + "," +
                                            Business.Market.SymbolList[i].CommandList[j].ExpTime + "," +
                                            Business.Market.SymbolList[i].CommandList[j].ClientCode + "," + "0000000," +
                                            Business.Market.SymbolList[i].CommandList[j].IsHedged + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Type.ID + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Margin + ",Open";

                                        if (Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue == null)
                                            Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue = new List<string>();

                                        Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue.Add(Message);

                                        Result.isDeal = false;
                                        Result.Error = "MARKET IS CLOSE";
                                        Result.Command = objCommand;

                                        #region INSERT SYSTEM LOG CHECK TIME MARKET
                                        string tempContent = string.Empty;
                                        tempContent = "'" + Command.Investor.Code + "': modified #" + Command.CommandCode + " " + mode + " " + size + " " + Command.Symbol.Name + " at " +
                                            openPrice + " sl: " + stopLoss + " tp: " + takeProfit + " unsuccesful [market is close] (" + bid + "/" + ask + ")";

                                        TradingServer.Facade.FacadeAddNewSystemLog(5, tempContent, comment, Command.Investor.IpAddress, Command.Investor.Code);
                                        #endregion

                                        return Result;
                                    }
                                    #endregion

                                    #region CHECK HOLIDAY OF SERVER
                                    if (Business.Market.SymbolList[i].IsHoliday)
                                    {
                                        string Message = "UpdateCommand$False,MARKET IS HOLIDAY," + Business.Market.SymbolList[i].CommandList[j].ID + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Investor.InvestorID + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Symbol.Name + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Size + "," + false + "," +
                                            Business.Market.SymbolList[i].CommandList[j].OpenTime + "," +
                                            Business.Market.SymbolList[i].CommandList[j].OpenPrice + "," +
                                            Business.Market.SymbolList[i].CommandList[j].StopLoss + "," +
                                            Business.Market.SymbolList[i].CommandList[j].TakeProfit + "," +
                                            Business.Market.SymbolList[i].CommandList[j].ClosePrice + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Commission + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Swap + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Profit + "," + "Comment," +
                                            Business.Market.SymbolList[i].CommandList[j].ID + "," + "BuySpotCommand" + "," + 1 + "," +
                                            Business.Market.SymbolList[i].CommandList[j].ExpTime + "," +
                                            Business.Market.SymbolList[i].CommandList[j].ClientCode + "," + "0000000," +
                                            Business.Market.SymbolList[i].CommandList[j].IsHedged + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Type.ID + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Margin + ",Open";

                                        if (Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue == null)
                                            Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue = new List<string>();

                                        Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue.Add(Message);

                                        Result.isDeal = false;
                                        Result.Error = "MARKET IS HOLIDAY";
                                        Result.Command = objCommand;

                                        #region INSERT SYSTEM LOG CHECK HOLIDAY SERVER
                                        string tempContent = string.Empty;
                                        tempContent = "'" + Command.Investor.Code + "': modified #" + Command.CommandCode + " " + mode + " " + size + " " + Command.Symbol.Name + " at " +
                                            openPrice + " sl: " + stopLoss + " tp: " + takeProfit + " unsuccesful [market is holiday] (" + bid + "/" + ask + ")";

                                        TradingServer.Facade.FacadeAddNewSystemLog(5, tempContent, comment, Command.Investor.IpAddress, Command.Investor.Code);
                                        #endregion

                                        return Result;
                                    }
                                    #endregion

                                    if (Business.Market.SymbolList[i].CommandList[j].Investor.IsDisable)
                                    {
                                        #region CHECK ISDISABLE OF INVESTOR
                                        string Message = "UpdateCommand$False,ACCOUNT IS DISABLED," + Command.ID + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Investor.InvestorID + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Symbol.Name + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Size + "," + false + "," +
                                            Business.Market.SymbolList[i].CommandList[j].OpenTime + "," +
                                            Business.Market.SymbolList[i].CommandList[j].OpenPrice + "," +
                                            Business.Market.SymbolList[i].CommandList[j].StopLoss + "," +
                                            Business.Market.SymbolList[i].CommandList[j].TakeProfit + "," +
                                            Business.Market.SymbolList[i].CommandList[j].ClosePrice + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Commission + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Swap + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Profit + "," + "Comment," +
                                            Business.Market.SymbolList[i].CommandList[j].ID + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Type.Name + "," +
                                            1 + "," + Business.Market.SymbolList[i].CommandList[j].ExpTime + "," +
                                            Business.Market.SymbolList[i].CommandList[j].ClientCode + "," +
                                            Business.Market.SymbolList[i].CommandList[j].CommandCode + "," +
                                            Business.Market.SymbolList[i].CommandList[j].IsHedged + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Type.ID + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Margin + ",Update";

                                        //If Client Update Command Then Add Message To Client Message
                                        if (Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue == null)
                                            Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue = new List<string>();

                                        Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue.Add(Message);

                                        Result.isDeal = false;
                                        Result.Command = objCommand;
                                        Result.Error = "ACCOUNT IS DISABLED";

                                        #region INSERT SYSTEM LOG CHECK STATUS OF ACCOUNT(DISABLE)
                                        string tempContent = string.Empty;
                                        tempContent = "'" + Command.Investor.Code + "': modified #" + Command.CommandCode + " " + mode + " " + size + " " + Command.Symbol.Name + " at " +
                                            openPrice + " sl: " + stopLoss + " tp: " + takeProfit + " unsuccesful [account is disabled] (" + bid + "/" + ask + ")";

                                        TradingServer.Facade.FacadeAddNewSystemLog(5, tempContent, comment, Command.Investor.IpAddress, Command.Investor.Code);
                                        #endregion

                                        return Result;
                                        #endregion
                                    }

                                    #region CHECK READ ONLY OF INVESTOR
                                    if (Business.Market.SymbolList[i].CommandList[j].Investor.ReadOnly)
                                    {
                                        string Message = "UpdateCommand$False,TRADE IS DISABLED," + Command.ID + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Investor.InvestorID + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Symbol.Name + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Size + "," + false + "," +
                                            Business.Market.SymbolList[i].CommandList[j].OpenTime + "," +
                                            Business.Market.SymbolList[i].CommandList[j].OpenPrice + "," +
                                            Business.Market.SymbolList[i].CommandList[j].StopLoss + "," +
                                            Business.Market.SymbolList[i].CommandList[j].TakeProfit + "," +
                                            Business.Market.SymbolList[i].CommandList[j].ClosePrice + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Commission + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Swap + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Profit + "," + "Comment," +
                                            Business.Market.SymbolList[i].CommandList[j].ID + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Type.Name + "," +
                                            1 + "," + Business.Market.SymbolList[i].CommandList[j].ExpTime + "," +
                                            Business.Market.SymbolList[i].CommandList[j].ClientCode + "," +
                                            Business.Market.SymbolList[i].CommandList[j].CommandCode + "," +
                                            Business.Market.SymbolList[i].CommandList[j].IsHedged + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Type.ID + "," +
                                            Business.Market.SymbolList[i].CommandList[j].Margin + ",Update";

                                        //If Client Update Command Then Add Message To Client Message
                                        if (Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue == null)
                                            Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue = new List<string>();

                                        Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue.Add(Message);

                                        Result.isDeal = false;
                                        Result.Command = objCommand;
                                        Result.Error = "TRADE IS DISABLED";

                                        #region INSERT SYSTEM LOG CHECK ACCOUNT READ ONLY
                                        string tempContent = string.Empty;
                                        tempContent = "'" + Command.Investor.Code + "': modified #" + Command.CommandCode + " " + mode + " " + size + " " + Command.Symbol.Name + " at " +
                                            openPrice + " sl: " + stopLoss + " tp: " + takeProfit + " unsuccesful [account read only] (" + bid + "/" + ask + ")";

                                        TradingServer.Facade.FacadeAddNewSystemLog(5, tempContent, comment, Command.Investor.IpAddress, Command.Investor.Code);
                                        #endregion

                                        return Result;
                                    }
                                    #endregion

                                    #region CHECK OPEN PRICE OF PENDING ORDER
                                    if (Business.Market.SymbolList[i].CommandList[j].Type.ID == 7 || Business.Market.SymbolList[i].CommandList[j].Type.ID == 8 ||
                                        Business.Market.SymbolList[i].CommandList[j].Type.ID == 9 || Business.Market.SymbolList[i].CommandList[j].Type.ID == 10 ||
                                        Business.Market.SymbolList[i].CommandList[j].Type.ID == 17 || Business.Market.SymbolList[i].CommandList[j].Type.ID == 18 ||
                                        Business.Market.SymbolList[i].CommandList[j].Type.ID == 19 || Business.Market.SymbolList[i].CommandList[j].Type.ID == 20)
                                    {
                                        bool ResultCheckOpenPrice = false;
                                        double tempOpenPrices = 0;
                                        bool parseOpenPrice = double.TryParse(objCommand.OpenPrice, out tempOpenPrices);
                                        if (Business.Market.SymbolList[i].CommandList[j].OpenPrice != tempOpenPrices)
                                        {
                                            if (parseOpenPrice)
                                            {
                                                ResultCheckOpenPrice = Business.Market.SymbolList[i].CommandList[j].Symbol.CheckOpenPricePendingOrder(Business.Market.SymbolList[i].CommandList[j].Symbol.Name,
                                                    Business.Market.SymbolList[i].CommandList[j].Type.ID, tempOpenPrices, Business.Market.SymbolList[i].CommandList[j].Symbol.LimitLevel,
                                                    Business.Market.SymbolList[i].CommandList[j].Symbol.StopLevel,
                                                    Business.Market.SymbolList[i].CommandList[j].Symbol.Digit,
                                                    int.Parse(Business.Market.SymbolList[i].CommandList[j].SpreaDifferenceInOpenTrade.ToString()));
                                            }

                                            #region CONVERT TYPE.ID TO COMMAND TYPE
                                            string CommandType = string.Empty;
                                            switch (Business.Market.SymbolList[i].CommandList[j].Type.ID)
                                            {
                                                case 1:
                                                    CommandType = "Open";
                                                    break;
                                                case 2:
                                                    CommandType = "Open";
                                                    break;
                                                case 7:
                                                    CommandType = "BuyLimit";
                                                    break;
                                                case 8:
                                                    CommandType = "SellLimit";
                                                    break;
                                                case 9:
                                                    CommandType = "BuyStop";
                                                    break;
                                                case 10:
                                                    CommandType = "SellStop";
                                                    break;
                                                case 11:
                                                    CommandType = "BuyFuture";
                                                    break;
                                                case 12:
                                                    CommandType = "SellFuture";
                                                    break;
                                                case 17:
                                                    CommandType = "BuyStopFutureCommand";
                                                    break;
                                                case 18:
                                                    CommandType = "SellStopFutureCommand";
                                                    break;
                                                case 19:
                                                    CommandType = "BuyLimitFutureCommand";
                                                    break;
                                                case 20:
                                                    CommandType = "SellLimitFutureCommand";
                                                    break;
                                            }
                                            #endregion

                                            if (ResultCheckOpenPrice == false)
                                            {
                                                #region MAP COMMAND TO CLIENT
                                                string Message = "UpdateCommand$False,INVALID OPEN PRICE," + Business.Market.SymbolList[i].CommandList[j].ID + "," +
                                                    Business.Market.SymbolList[i].CommandList[j].Investor.InvestorID + "," +
                                                    Business.Market.SymbolList[i].CommandList[j].Symbol.Name + "," + Business.Market.SymbolList[i].CommandList[j].Size + "," +
                                                    false + "," + Business.Market.SymbolList[i].CommandList[j].OpenTime + "," + Business.Market.SymbolList[i].CommandList[j].OpenPrice + "," +
                                                    Business.Market.SymbolList[i].CommandList[j].StopLoss + "," + Business.Market.SymbolList[i].CommandList[j].TakeProfit + "," +
                                                    Business.Market.SymbolList[i].CommandList[j].ClosePrice + "," + Business.Market.SymbolList[i].CommandList[j].Commission + "," +
                                                    Business.Market.SymbolList[i].CommandList[j].Swap + "," + Business.Market.SymbolList[i].CommandList[j].Profit + "," + "Comment," +
                                                    Business.Market.SymbolList[i].CommandList[j].ID + "," + CommandType + "," + 1 + "," + Business.Market.SymbolList[i].CommandList[j].ExpTime + "," +
                                                    Business.Market.SymbolList[i].CommandList[j].ClientCode + "," + "0000000," + Business.Market.SymbolList[i].CommandList[j].IsHedged + "," +
                                                    Business.Market.SymbolList[i].CommandList[j].Type.ID + "," + Business.Market.SymbolList[i].CommandList[j].Margin + ",Open";

                                                if (Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue == null)
                                                    Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue = new List<string>();

                                                Business.Market.SymbolList[i].CommandList[j].Investor.ClientCommandQueue.Add(Message);

                                                Result.Error = "INVALID OPEN PRICE";
                                                Result.Command = objCommand;
                                                Result.isDeal = false;

                                                #region INSERT SYSTEM LOG CHECK OPEN PRICE PENDING ORDER FALSE
                                                string tempContent = string.Empty;
                                                tempContent = "'" + Command.Investor.Code + "': modified #" + Command.CommandCode + " " + mode + " " + size + " " + Command.Symbol.Name + " at " +
                                                    openPrice + " sl: " + stopLoss + " tp: " + takeProfit + " unsuccesful [invalid open price] (" + bid + "/" + ask + ")";

                                                TradingServer.Facade.FacadeAddNewSystemLog(5, tempContent, comment, Command.Investor.IpAddress, Command.Investor.Code);
                                                #endregion
                                                #endregion

                                                return Result;
                                            }   //END IF CHECK S/L AND T/P OF COMMAND
                                        }

                                    }   //END IF CHECK COMMAND IS PENDING ORDER
                                    #endregion

                                    flag = true;

                                    //SET CLIENT CODE
                                    Command.ClientCode = Business.Market.SymbolList[i].CommandList[j].ClientCode;
                                    Command.RefCommandID = Business.Market.SymbolList[i].CommandList[j].RefCommandID;

                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }

            Command.ID = objCommand.CommandID;
            Command.TakeProfit = objCommand.TakeProfit;
            Command.StopLoss = objCommand.StopLoss;
            Command.Comment = objCommand.Comment;

            //CHECK IF COMMAND IS PENDING ORDER AND OPEN PRICES != 0 THEN UPDATE COMMAND THIS
            if (Command.Type != null)
            {
                if (Command.Type.ID == 7 || Command.Type.ID == 8 || Command.Type.ID == 9 || Command.Type.ID == 10 ||
                    Command.Type.ID == 17 || Command.Type.ID == 18 || Command.Type.ID == 19 || Command.Type.ID == 20)
                {
                    double tempOpenPrice = 0;
                    double.TryParse(objCommand.OpenPrice, out tempOpenPrice);
                    if (tempOpenPrice != 0)
                    {
                        Command.OpenPrice = tempOpenPrice;
                    }
                }
            }

            Command.Investor.IpAddress = objCommand.IpAddress;

            if (Command != null)
            {
                if (Command.Symbol != null && Command.Investor != null && Command.Type != null)
                {
                    Command.Symbol.MarketAreaRef.UpdateCommand(Command);
                }
            }

            Result.isDeal = true;
            Result.Command = objCommand;

            return Result;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="objCommand"></param>
        /// <returns></returns>
        public static ClientBusiness.DealMessage FacadeMultiUpdateCommand(TradingServer.ClientBusiness.Command objCommand)
        {
            ClientBusiness.DealMessage Result = new ClientBusiness.DealMessage();

            Result.isDeal = false;

            Business.OpenTrade Command = new Business.OpenTrade();

            FillInstanceOpenTrade(objCommand, Command);

            if (Command == null)
            {
                TradingServer.Facade.FacadeAddNewSystemLog(1, "some info empty(command)", "[multiple update command]", "", "");
                return Result;
            }

            if (Command.Type == null || Command.Investor == null || Command.IGroupSecurity == null || Command.Symbol == null)
            {
                TradingServer.Facade.FacadeAddNewSystemLog(1, "some info empty(type,investor,igroupsecurity,symbol)", "[multiple update command]", "", "");
                return Result;
            }

            #region INSERT SYSTEM LOG BEFORE MODIFY COMMAND
            string content = string.Empty;
            string comment = "[multi modify order]";

            string stopLoss = TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(objCommand.StopLoss.ToString(),
                Command.Symbol.Digit);
            string takeProfit = TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(objCommand.TakeProfit.ToString(),
                Command.Symbol.Digit);

            content = "'" + Command.Investor.Code + "': multiple modify by for symbol " + Command.Symbol.Name + " -> sl: " + stopLoss + " tp: " + takeProfit;

            TradingServer.Facade.FacadeAddNewSystemLog(5, content, comment, Command.Investor.IpAddress, Command.Investor.Code);
            #endregion

            Command.StopLoss = objCommand.StopLoss;
            Command.TakeProfit = objCommand.TakeProfit;

            bool ResultTakeProfit = false;
            if (Command.StopLoss != 0 || Command.TakeProfit != 0)
            {
                #region Call Check FreezeLevel
                ResultTakeProfit = Command.Symbol.CheckLimitAndStop(Command.Symbol.Name, Command.Type.ID, Command.StopLoss, Command.TakeProfit,
                                            Command.Symbol.FreezeLevel, Command.Symbol.Digit, int.Parse(Command.SpreaDifferenceInOpenTrade.ToString()));

                if (ResultTakeProfit == false)
                {
                    bool IsBuy = false;

                    string message = "UpdateCommand$False,INVALID FREEZE LEVEL," + Command.ID + "," + Command.Investor.InvestorID + "," + Command.Symbol.Name + "," +
                                        Command.Size + "," + IsBuy + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," + Command.TakeProfit +
                                        "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID +
                                        "," + Command.Type.Name + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + Command.CommandCode + "," +
                                        Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Update";

                    if (Command.Investor.ClientCommandQueue == null)
                        Command.Investor.ClientCommandQueue = new List<string>();

                    Command.Investor.ClientCommandQueue.Add(message);

                    #region INSERT SYSTEM LOG AFTER MODIFY COMMAND
                    string tempContent = string.Empty;
                    tempContent = "'" + Command.Investor.Code + "': multiple modified by for symbol " + Command.Symbol.Name + " -> sl: " + stopLoss + " tp: " + takeProfit + " unsuccesful [invalid freeze level]";

                    TradingServer.Facade.FacadeAddNewSystemLog(5, tempContent, comment, Command.Investor.IpAddress, Command.Investor.Code);
                    #endregion

                    Result.isDeal = false;
                    Result.Command = objCommand;
                    Result.Error = "INVALID FREEZE LEVEL";

                    return Result;
                }
                #endregion

                #region Check Valid Take Profit And Stop Loss
                ResultTakeProfit = Command.Symbol.CheckLimitAndStop(Command.Symbol.Name, Command.Type.ID, Command.StopLoss, Command.TakeProfit,
                    Command.Symbol.StopLossTakeProfitLevel, Command.Symbol.Digit, int.Parse(Command.SpreaDifferenceInOpenTrade.ToString()));

                if (ResultTakeProfit == false)
                {
                    bool IsBuy = false;

                    string message = "UpdateCommand$False,INVALID S/L OR T/P," + Command.ID + "," + Command.Investor.InvestorID + "," + Command.Symbol.Name + "," +
                                        Command.Size + "," + IsBuy + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," + Command.TakeProfit + "," +
                                        Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + Command.Type.Name + "," +
                                        1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + Command.CommandCode + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Update";

                    if (Command.Investor.ClientCommandQueue == null)
                        Command.Investor.ClientCommandQueue = new List<string>();

                    Command.Investor.ClientCommandQueue.Add(message);

                    #region INSERT SYSTEM LOG AFTER MODIFY COMMAND
                    string tempContent = string.Empty;
                    tempContent = "'" + Command.Investor.Code + "': multiple modified by for symbol" + Command.Symbol.Name + " -> sl: " + stopLoss + " tp: " + takeProfit + " unsuccesful [invalid s/l or t/p]";

                    TradingServer.Facade.FacadeAddNewSystemLog(5, tempContent, comment, Command.Investor.IpAddress, Command.Investor.Code);
                    #endregion

                    Result.isDeal = false;
                    Result.Error = "INVALID FREEZE LEVEL";
                    Result.Command = objCommand;

                    return Result;
                }
                #endregion
            }

            #region IF SYMBOL IS FUTURE THEN CHECK TIME SESSION OF FUTURE
            if (Command.Symbol.MarketAreaRef.IMarketAreaName == "FutureCommand")
            {
                if (Command.Symbol.isCloseOnlyFuture)
                {
                    string message = "UpdateCommand$False,SYMBOL CLOSE ONLY," + Command.ID + "," + Command.Investor.InvestorID + "," + Command.Symbol.Name + "," +
                    Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," + Command.TakeProfit + "," +
                    Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + "BuyFutureCommand" +
                    "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",BuyFutureCommand";

                    if (Command.Investor.ClientCommandQueue == null)
                        Command.Investor.ClientCommandQueue = new List<string>();

                    Command.Investor.ClientCommandQueue.Add(message);

                    Result.isDeal = false;
                    Result.Error = "SYMBOL CLOSE ONLY";
                    Result.Command = objCommand;

                    #region INSERT SYSTEM LOG TIME SESSION OF SYMBOL FUTURE
                    string tempContent = string.Empty;
                    tempContent = "'" + Command.Investor.Code + "': multiple modified by for symbol " + Command.Symbol.Name + " -> sl: " + stopLoss + " tp: " + takeProfit + " unsuccesful [symbol is close]";

                    TradingServer.Facade.FacadeAddNewSystemLog(5, tempContent, comment, Command.Investor.IpAddress, Command.Investor.Code);
                    #endregion

                    return Result;
                }
            }
            #endregion

            #region CHECK ACCOUNT INVESTOR LOGIN WITH READ ONLY PASSWORD
            if (Command.Investor.IsReadOnly)
            {
                string Message = "UpdateCommand$False,TRADE IS DISABLED," + Command.ID + "," + Command.Investor.InvestorID + "," + Command.Symbol.Name + "," +
                        Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," + Command.TakeProfit + "," +
                        Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                        Command.Type.Name + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + Command.CommandCode + "," + Command.IsHedged + "," +
                        Command.Type.ID + "," + Command.Margin + ",Update";

                //If Client Update Command Then Add Message To Client Message
                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();

                Command.Investor.ClientCommandQueue.Add(Message);

                Result.isDeal = false;
                Result.Command = objCommand;
                Result.Error = "TRADE IS DISABLED";

                #region INSERT SYSTEM LOG CHECK ACCOUNT INVESTOR TRADE IS DISABLED
                string tempContent = string.Empty;
                tempContent = "'" + Command.Investor.Code + "': multiple modified by for symbol " + Command.Symbol.Name + " -> sl: " + stopLoss + " tp: " + takeProfit + " unsuccesful [trade is disabled]";

                TradingServer.Facade.FacadeAddNewSystemLog(5, tempContent, comment, Command.Investor.IpAddress, Command.Investor.Code);
                #endregion

                return Result;
            }
            #endregion

            #region CHECK TIME MARKET
            if (!Business.Market.IsOpen)
            {
                string Message = "UpdateCommand$False,MARKET IS CLOSE," + Command.ID + "," + Command.Investor.InvestorID + "," + Command.Symbol.Name + "," +
                    Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," + Command.TakeProfit + "," +
                    Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + "Open" + "," + 1 +
                    "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();

                Command.Investor.ClientCommandQueue.Add(Message);

                Result.isDeal = false;
                Result.Error = "MARKET IS CLOSE";
                Result.Command = objCommand;

                #region INSERT SYSTEM LOG CHECK TIME MARKET
                string tempContent = string.Empty;
                tempContent = "'" + Command.Investor.Code + "': multiple modified by for symbol " + Command.Symbol.Name + " -> sl: " + stopLoss + " tp: " + takeProfit + " unsuccesful [market is close]";

                TradingServer.Facade.FacadeAddNewSystemLog(5, tempContent, comment, Command.Investor.IpAddress, Command.Investor.Code);
                #endregion

                return Result;
            }
            #endregion

            #region CHECK HOLIDAY OF SERVER
            if (Command.Symbol.IsHoliday)
            {
                string Message = "UpdateCommand$False,MARKET IS HOLIDAY," + Command.ID + "," + Command.Investor.InvestorID + "," + Command.Symbol.Name + "," + Command.Size +
                    "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," + Command.TakeProfit + "," + Command.ClosePrice + "," +
                    Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + "BuySpotCommand" + "," + 1 + "," +
                    Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();

                Command.Investor.ClientCommandQueue.Add(Message);

                Result.isDeal = false;
                Result.Error = "MARKET IS HOLIDAY";
                Result.Command = objCommand;

                #region INSERT SYSTEM LOG CHECK HOLIDAY SERVER
                string tempContent = string.Empty;
                tempContent = "'" + Command.Investor.Code + "': multiple modified by for symbol " + Command.Symbol.Name + " -> sl: " + stopLoss + " tp: " + takeProfit + " unsuccesful [market is holiday]";

                TradingServer.Facade.FacadeAddNewSystemLog(5, tempContent, comment, Command.Investor.IpAddress, Command.Investor.Code);
                #endregion

                return Result;
            }
            #endregion

            if (Command.Investor.IsDisable)
            {
                #region CHECK ISDISABLE OF INVESTOR
                string Message = "UpdateCommand$False,ACCOUNT IS DISABLED," + Command.ID + "," + Command.Investor.InvestorID + "," + Command.Symbol.Name + "," +
                    Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," + Command.TakeProfit + "," +
                    Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + Command.Type.Name +
                    "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + Command.CommandCode + "," + Command.IsHedged + "," + Command.Type.ID + "," +
                    Command.Margin + ",Update";

                //If Client Update Command Then Add Message To Client Message
                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();

                Command.Investor.ClientCommandQueue.Add(Message);

                Result.isDeal = false;
                Result.Command = objCommand;
                Result.Error = "ACCOUNT IS DISABLED";

                #region INSERT SYSTEM LOG CHECK STATUS OF ACCOUNT(DISABLE)
                string tempContent = string.Empty;
                tempContent = "'" + Command.Investor.Code + "': multiple modified by for symbol " + Command.Symbol.Name + " -> sl: " + stopLoss + " tp: " + takeProfit + " unsuccesful [account is disabled]";

                TradingServer.Facade.FacadeAddNewSystemLog(5, tempContent, comment, Command.Investor.IpAddress, Command.Investor.Code);
                #endregion

                return Result;
                #endregion
            }

            #region CHECK READ ONLY OF INVESTOR
            if (Command.Investor.ReadOnly)
            {
                string Message = "UpdateCommand$False,TRADE IS DISABLED," + Command.ID + "," + Command.Investor.InvestorID + "," + Command.Symbol.Name + "," +
                    Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," + Command.TakeProfit + "," +
                    Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                    Command.Type.Name + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + Command.CommandCode + "," + Command.IsHedged + "," +
                    Command.Type.ID + "," + Command.Margin + ",Update";

                //If Client Update Command Then Add Message To Client Message
                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();

                Command.Investor.ClientCommandQueue.Add(Message);

                Result.isDeal = false;
                Result.Command = objCommand;
                Result.Error = "TRADE IS DISABLED";

                #region INSERT SYSTEM LOG CHECK ACCOUNT READ ONLY
                string tempContent = string.Empty;
                tempContent = "'" + Command.Investor.Code + "': multiple modified by for symbol " + Command.Symbol.Name + " -> sl: " + stopLoss + " tp: " + takeProfit + " unsuccesful [account read only]";

                TradingServer.Facade.FacadeAddNewSystemLog(5, tempContent, comment, Command.Investor.IpAddress, Command.Investor.Code);
                #endregion

                return Result;
            }
            #endregion

            Command.ID = objCommand.CommandID;
            Command.Comment = objCommand.Comment;
            Command.Investor.IpAddress = objCommand.IpAddress;

            if (Command != null)
            {
                if (Command.Symbol != null && Command.Investor != null && Command.Type != null)
                {
                    Command.Symbol.MarketAreaRef.MultiUpdateCommand(Command);
                }
            }

            Result.isDeal = true;
            Result.Command = objCommand;

            return Result;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="objCommand"></param>
        /// <returns></returns>
        public static ClientBusiness.DealMessage FacadeMultiCloseCommand(TradingServer.ClientBusiness.Command objCommand)
        {
            ClientBusiness.DealMessage Result = new ClientBusiness.DealMessage();

            Result.isDeal = false;

            TradingServer.Business.OpenTrade Command = new Business.OpenTrade();

            FillInstanceOpenTrade(objCommand, Command);

            #region CHECK SYMBOL ON HOLD
            if (!Command.Symbol.CheckTimeTick())
            {
                if (Command.Investor != null)
                {
                    //Add Result To Client Command Queue Of Investor
                    string Message = "CloseCommand$False,MARKET ON HOLD," + Command.ID + "," + Command.Investor.InvestorID + "," +
                            Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                "BuySpotCommand" + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                    if (Command.Investor.ClientCommandQueue == null)
                        Command.Investor.ClientCommandQueue = new List<string>();

                    Command.Investor.ClientCommandQueue.Add(Message);
                }

                #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                string tempContent = "multiple close command";
                tempContent = tempContent + " unsuccessful [symbol on hold]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, tempContent, "[symbol on hold]", objCommand.IpAddress, Command.Investor.Code);
                #endregion

                return Result;
            }
            #endregion

            #region CHECK NULL COMMAND
            if (Command == null)
            {
                TradingServer.Facade.FacadeAddNewSystemLog(1, "command is empty", "Check Null Close Command", "", "");
                return Result;
            }

            if (Command.Investor == null || Command.Symbol == null || Command.Type == null)
            {
                TradingServer.Facade.FacadeAddNewSystemLog(1, "symbol investor or type command empty", "Check Null Close Command", "", "");
                return null;
            }
            #endregion

            Command.ClosePrice = objCommand.ClosePrice;

            #region BEGIN INSERT SYSTEM LOG
            string bid = TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Command.Symbol.TickValue.Bid.ToString(), Command.Symbol.Digit);
            string ask = TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Command.Symbol.TickValue.Ask.ToString(), Command.Symbol.Digit);
            string closePrice = TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Command.ClosePrice.ToString(), Command.Symbol.Digit);

            string mode = string.Empty;
            string content = string.Empty;
            string comment = string.Empty;

            content = "'" + Command.Investor.Code + "': multiple close by for symbol " + Command.Symbol.Name + " at close price " + closePrice + " (" + bid + "/" + ask + ")";
            comment = "[multiple close]";

            TradingServer.Facade.FacadeAddNewSystemLog(5, content, comment, Command.Investor.IpAddress, Command.Investor.Code);
            #endregion

            #region CHECK IP ADDRESS
            bool checkIp = TradingServer.Business.ValidIPAddress.Instance.ValidIpAddress(objCommand.InvestorID, objCommand.IpAddress);
            if (!checkIp)
            {
                Result.isDeal = false;
                Result.Command = objCommand;
                Result.Error = "INVALID IP ADDRESS";

                string Message = "CloseCommand$False,INVALID IP ADDRESS," + Command.ID + "," + Command.Investor.InvestorID + "," + Command.Symbol.Name + "," +
                            Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," + Command.TakeProfit + "," +
                            Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + Command.Type.Name + "," +
                            1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + Command.CommandCode + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Close," +
                            DateTime.Now;

                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();

                Command.Investor.ClientCommandQueue.Add(Message);

                content = content + " unsuccessful [invalid ip address]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[invalid ip address]", objCommand.IpAddress, Command.Investor.Code);

                return Result;
            }
            #endregion

            #region CHECK INVESTOR ONLINE
            bool checkOnline = TradingServer.Business.Investor.investorInstance.CheckPrimaryInvestorOnline(objCommand.InvestorID, Business.TypeLogin.Primary, objCommand.LoginKey);
            if (!checkOnline)
            {
                Result.isDeal = false;
                Result.Command = objCommand;
                Result.Error = "ACCOUNT READ ONLY";

                string Message = "CloseCommand$False,ACCOUNT READ ONLY," + Command.ID + "," + Command.Investor.InvestorID + "," + Command.Symbol.Name + "," +
                            Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," + Command.TakeProfit + "," +
                            Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + Command.Type.Name + "," +
                            1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + Command.CommandCode + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Close," +
                            DateTime.Now;

                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();

                Command.Investor.ClientCommandQueue.Add(Message);

                content = content + " unsuccessful [account read only]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[account read only]", objCommand.IpAddress, Command.Investor.Code);

                return Result;
            }
            #endregion

            #region CHECK INVESTOR LOGIN WITH PASSWORD READ ONLY
            if (Command.Investor.IsReadOnly)
            {
                string Message = "CloseCommand$False,TRADE IS DISABLED," + Command.ID + "," + Command.Investor.InvestorID + "," + Command.Symbol.Name + "," +
                            Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," + Command.TakeProfit + "," +
                            Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + Command.Type.Name + "," +
                            1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + Command.CommandCode + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Close," +
                            DateTime.Now;

                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();

                Command.Investor.ClientCommandQueue.Add(Message);

                Result.isDeal = false;
                Result.Error = "TRADE IS DISABLED";
                Result.Command = objCommand;

                content = content + " unsuccessful [login password read only]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[login password read only]", objCommand.IpAddress, Command.Investor.Code);

                return Result;
            }
            #endregion

            #region CHECK TIME MARKET
            if (!Business.Market.IsOpen)
            {
                string Message = "CloseCommand$False,MARKET IS CLOSE," + Command.ID + "," + Command.Investor.InvestorID + "," +
                            Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," +
                            Command.StopLoss + "," + Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," +
                            Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + "BuySpotCommand" + "," + 1 + "," +
                            Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," +
                            Command.Margin + ",Open," + DateTime.Now;

                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();

                Command.Investor.ClientCommandQueue.Add(Message);

                Result.isDeal = false;
                Result.Error = "MARKET IS CLOSE";
                Result.Command = objCommand;

                #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                content = content + " unsuccessful [market is close]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[market is close]", objCommand.IpAddress, Command.Investor.Code);
                #endregion

                return Result;
            }
            #endregion

            #region CHECK IS TRADE OF SYMBOL
            if (!Command.Symbol.IsTrade)
            {
                string Message = "CloseCommand$False,SYMBOL IS CLOSE," + Command.ID + "," + Command.Investor.InvestorID + "," +
                                Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," +
                                Command.StopLoss + "," + Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," +
                                Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + "BuySpotCommand" + "," + 1 + "," +
                                Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," +
                                Command.Margin + ",Open," + DateTime.Now;

                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();

                Command.Investor.ClientCommandQueue.Add(Message);

                Result.isDeal = false;
                Result.Error = "SYMBOL IS CLOSE";
                Result.Command = objCommand;

                content = content + " unsuccessful [symbol is close]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[symbol is close]", objCommand.IpAddress, Command.Investor.Code);

                return Result;
            }
            #endregion

            #region CHECK HOLIDAY OF SERVER
            if (Command.Symbol.IsHoliday)
            {
                string Message = "CloseCommand$False,MARKET IS HOLIDAY," + Command.ID + "," + Command.Investor.InvestorID + "," +
                               Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," +
                               Command.StopLoss + "," + Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," +
                               Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + Command.Type.Name + "," + 1 + "," +
                               Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," +
                               Command.Margin + ",Open," + DateTime.Now;

                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();

                Command.Investor.ClientCommandQueue.Add(Message);

                Result.isDeal = false;
                Result.Error = "MARKET IS HOLIDAY";
                Result.Command = objCommand;

                content = content + " unsuccessful [market is holiday]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[market is holiday]", objCommand.IpAddress, Command.Investor.Code);

                return Result;
            }
            #endregion

            #region CHECK TRADE IN GROUP
            #region Get Setting IsTrade In Group
            bool IsTradeGroup = false;
            if (Business.Market.InvestorGroupList != null)
            {
                int count = Business.Market.InvestorGroupList.Count;
                for (int i = 0; i < count; i++)
                {
                    if (Business.Market.InvestorGroupList[i].InvestorGroupID == Command.Investor.InvestorGroupInstance.InvestorGroupID)
                    {
                        if (Business.Market.InvestorGroupList[i].ParameterItems != null)
                        {
                            int countParameter = Business.Market.InvestorGroupList[i].ParameterItems.Count;
                            for (int j = 0; j < countParameter; j++)
                            {
                                if (Business.Market.InvestorGroupList[i].ParameterItems[j].Code == "G01")
                                {
                                    if (Business.Market.InvestorGroupList[i].ParameterItems[j].BoolValue == 1)
                                        IsTradeGroup = true;

                                    break;
                                }
                            }
                        }
                        break;
                    }
                }
            }
            #endregion

            #region CHECK TRADE GROUP
            if (!IsTradeGroup)
            {
                string Message = "CloseCommand$False,GROUP IS DISABLED," + Command.ID + "," + Command.Investor.InvestorID + "," + Command.Symbol.Name + "," +
                                    Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," + Command.TakeProfit + "," +
                                    Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + Command.Type.Name + "," +
                                    1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + Command.CommandCode + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin +
                                    ",Close," + DateTime.Now;

                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();

                Command.Investor.ClientCommandQueue.Add(Message);

                Result.isDeal = false;
                Result.Error = "GROUP IS DISABLED";
                Result.Command = objCommand;

                content = content + " unsuccessful [group is disable]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[group is disable]", objCommand.IpAddress, Command.Investor.Code);

                return Result;
            }
            #endregion
            #endregion

            if (Command.Investor != null)
            {
                #region CHECK ISDISABLE OF INVESTOR
                if (Command.Investor.IsDisable)
                {
                    string Message = "CloseCommand$False,ACCOUNT IS DISABLED," + Command.ID + "," + Command.Investor.InvestorID + "," + Command.Symbol.Name + "," +
                                Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," + Command.TakeProfit + "," +
                                Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + Command.Type.Name + "," +
                                1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + Command.CommandCode + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin +
                                ",Close," + DateTime.Now;

                    if (Command.Investor.ClientCommandQueue == null)
                        Command.Investor.ClientCommandQueue = new List<string>();

                    Command.Investor.ClientCommandQueue.Add(Message);

                    Result.isDeal = false;
                    Result.Error = "ACCOUNT IS DISABLED";
                    Result.Command = objCommand;

                    content = content + " unsuccessful [account is disable]";
                    TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[account is disable]", objCommand.IpAddress, Command.Investor.Code);

                    return Result;
                }
                #endregion

                #region CHECK READ ONLY OF INVESTOR
                if (Command.Investor.ReadOnly)
                {
                    string Message = "CloseCommand$False,TRADE IS DISABLED," + Command.ID + "," + Command.Investor.InvestorID + "," + Command.Symbol.Name + "," +
                            Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," + Command.TakeProfit + "," +
                            Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + Command.Type.Name + "," +
                            1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + Command.CommandCode + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin +
                            ",Close," + DateTime.Now;

                    if (Command.Investor.ClientCommandQueue == null)
                        Command.Investor.ClientCommandQueue = new List<string>();

                    Command.Investor.ClientCommandQueue.Add(Message);

                    Result.isDeal = false;
                    Result.Error = "TRADE IS DISABLED";
                    Result.Command = objCommand;

                    content = content + " unsuccessful [account read only]";
                    TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[account read only]", objCommand.IpAddress, Command.Investor.Code);

                    return Result;
                }

                #endregion
            }

            #region Check Status Trade Of Symbol(Full Access,Close Only, No)
            if (Command.Symbol.Trade == "No")
            {
                bool IsBuy = false;

                string Message = "CloseCommand$False,ACTION NOT ALLOWED," + Command.ID + "," + Command.Investor.InvestorID + "," +
                        Command.Symbol.Name + "," + Command.Size + "," + IsBuy + "," + Command.OpenTime + "," + Command.OpenPrice + "," +
                        Command.StopLoss + "," + Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," +
                        Command.Profit + "," + "Comment," + Command.ID + "," + Command.Type.Name + "," + 1 + "," + Command.ExpTime + "," +
                        Command.ClientCode + "," + Command.CommandCode + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin +
                        ",Close," + DateTime.Now;

                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();

                Command.Investor.ClientCommandQueue.Add(Message);

                Result.isDeal = false;
                Result.Error = "ACTION NOT ALLOWED";

                content = content + " unsuccessful [status trade no]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[status trade no]", objCommand.IpAddress, Command.Investor.Code);

                return Result;
            }
            #endregion

            //set ipaddress to investor
            Command.Investor.IpAddress = objCommand.IpAddress;
            Command.ClosePrice = objCommand.ClosePrice;
            Command.IsMultiClose = true;
            Command.CloseTime = DateTime.Now;

            if (Command.Type.ID != 7 && Command.Type.ID != 8 && Command.Type.ID != 9 && Command.Type.ID != 10)
            {
                //Call Dealer
                Business.RequestDealer newRequestDealer = new Business.RequestDealer();
                newRequestDealer.InvestorID = Command.Investor.InvestorID;
                newRequestDealer.MaxDev = Command.MaxDev;
                newRequestDealer.Name = "Close";
                newRequestDealer.Request = Command;
                newRequestDealer.TimeClientRequest = DateTime.Now;

                TradingServer.Facade.FacadeSendRequestToDealer(newRequestDealer);

                Result.isDeal = true;
                Result.Error = "Close Command Complete" + Command.Symbol.MarketAreaRef.IMarketAreaName;

                return Result;
            }
            else
            {
                Command.Symbol.MarketAreaRef.MultiCloseCommand(Command);

                Result.isDeal = true;
                Result.Error = "Close Command Complete" + Command.Symbol.MarketAreaRef.IMarketAreaName;

                return Result;
            }
        }
Ejemplo n.º 5
0
        //======================================================
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Command"></param>
        /// <returns></returns>
        public static ClientBusiness.DealMessage FacadeMakeCommand(TradingServer.ClientBusiness.Command objCommand)
        {
            ClientBusiness.DealMessage Result = new ClientBusiness.DealMessage();
            Result.isDeal = false;

            Business.OpenTrade Command = new Business.OpenTrade();

            FillInstanceOpenTrade(objCommand, Command);

            #region SET VALUE FOR COMMAND
            bool isRequest = false;
            if (Business.Market.marketInstance.MQLCommands != null)
            {
                int count = Business.Market.marketInstance.MQLCommands.Count;
                for (int i = 0; i < count; i++)
                {
                    if (Business.Market.marketInstance.MQLCommands[i].ClientCode == objCommand.ClientCode)
                    {
                        isRequest = true;
                        break;
                    }
                }

                if(!isRequest)
                {
                    NJ4XConnectSocket.MQLCommand newMQLCommand = new NJ4XConnectSocket.MQLCommand();
                    newMQLCommand.ClientCode = objCommand.ClientCode;
                    newMQLCommand.InvestorCode = Command.Investor.Code;
                    newMQLCommand.IpAddress = objCommand.IpAddress;

                    Business.Market.marketInstance.MQLCommands.Add(newMQLCommand);
                }
            }
            Command.ClientCode = objCommand.ClientCode;
            #endregion

            #region INSERT SYSTEM LOG EVENT MAKE COMMAND
            string size = TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(objCommand.Size.ToString(), 2);
            string openPrice = TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(objCommand.OpenPrice.ToString(), Command.Symbol.Digit);
            string takeProfit = TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(objCommand.TakeProfit.ToString(), Command.Symbol.Digit);
            string stopLoss = TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(objCommand.StopLoss.ToString(), Command.Symbol.Digit);
            string bid = TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Command.Symbol.TickValue.Bid.ToString(), Command.Symbol.Digit);
            string ask = TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Command.Symbol.TickValue.Ask.ToString(), Command.Symbol.Digit);

            string mode = string.Empty;
            string content = string.Empty;
            string comment = string.Empty;
            switch (Command.Type.ID)
            {
                case 1:
                    {
                        content = "'" + Command.Investor.Code + "': instant buy " + size + " " + Command.Symbol.Name + " at " + openPrice +
                            " sl: " + stopLoss + " tp: " + takeProfit + " (" + bid + "/" + ask + ")";
                        comment = "[instant buy]";
                    }
                    break;
                case 2:
                    {
                        content = "'" + Command.Investor.Code + "': instant sell " + size + " " + Command.Symbol.Name + " at " + openPrice +
                                " sl: " + stopLoss + " tp: " + takeProfit + " (" + bid + "/" + ask + ")";
                        comment = "[instant sell]";
                    }
                    break;
                case 7:
                    {
                        content = "'" + Command.Investor.Code + "': order buy limit " + size + " " + Command.Symbol.Name + " at " + openPrice +
                                " sl: " + stopLoss + " tp: " + takeProfit + " exp " + Command.ExpTime + " (" + bid + "/" + ask + ")";
                        comment = "[order buy limit]";
                    }
                    break;
                case 8:
                    {
                        content = "'" + Command.Investor.Code + "': order sell limit " + size + " " + Command.Symbol.Name + " at " + openPrice +
                                " sl: " + stopLoss + " tp: " + takeProfit + " exp " + Command.ExpTime + " (" + bid + "/" + ask + ")";
                        comment = "[order sell limit]";
                    }
                    break;
                case 9:
                    {
                        content = "'" + Command.Investor.Code + "': order buy stop " + size + " " + Command.Symbol.Name + " at " + openPrice +
                            " sl: " + stopLoss + " tp: " + takeProfit + " exp " + Command.ExpTime + " (" + bid + "/" + ask + ")";
                        comment = "[order buy stop]";
                    }
                    break;
                case 10:
                    {
                        content = "'" + Command.Investor.Code + "': order sell stop " + size + " " + Command.Symbol.Name + " at " + openPrice +
                            " sl: " + stopLoss + " tp: " + takeProfit + " exp " + Command.ExpTime + " (" + bid + "/" + ask + ")";
                        comment = "[order sell stop]";
                    }
                    break;
                case 11:
                    {
                        content = "'" + Command.Investor.Code + "': future buy " + size + " " + Command.Symbol.Name + " at " + openPrice +
                                " sl: " + stopLoss + " tp: " + takeProfit + " exp " + Command.ExpTime + " (" + bid + "/" + ask + ")";
                        comment = "[future buy]";
                    }
                    break;
                case 12:
                    {
                        content = "'" + Command.Investor.Code + "': future sell " + size + " " + Command.Symbol.Name + " at " + openPrice +
                                " sl: " + stopLoss + " tp: " + takeProfit + " exp " + Command.ExpTime + " (" + bid + "/" + ask + ")";
                        comment = "[future sell]";
                    }
                    break;
                case 17:
                    {
                        content = "'" + Command.Investor.Code + "': order buy stop " + size + " " + Command.Symbol.Name + " at " + openPrice +
                                " sl: " + stopLoss + " tp: " + takeProfit + " exp " + Command.ExpTime + " (" + bid + "/" + ask + ")";
                        comment = "[order buy stop]";
                    }
                    break;
                case 18:
                    {
                        content = "'" + Command.Investor.Code + "': order sell stop " + size + " " + Command.Symbol.Name + " at " + openPrice +
                                " sl: " + stopLoss + " tp: " + takeProfit + " exp " + Command.ExpTime + " (" + bid + "/" + ask + ")";
                        comment = "[order sell stop]";
                    }
                    break;
                case 19:
                    {
                        content = "'" + Command.Investor.Code + "': order buy limit " + size + " " + Command.Symbol.Name + " at " + openPrice +
                                " sl: " + stopLoss + " tp: " + takeProfit + " exp " + Command.ExpTime + " (" + bid + "/" + ask + ")";
                        comment = "[order buy limit]";
                    }
                    break;
                case 20:
                    {
                        content = "'" + Command.Investor.Code + "': order sell limit " + size + " " + Command.Symbol.Name + " at " + openPrice +
                                " sl: " + stopLoss + " tp: " + takeProfit + " exp " + Command.ExpTime + " (" + bid + "/" + ask + ")";
                        comment = "[sell limit]";
                    }
                    break;
            }

            if (!isRequest)
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, comment, objCommand.IpAddress, Command.Investor.Code);
            #endregion

            TimeSpan _timeSpan = DateTime.Now - Command.Investor.TimeDelayMakeCommand;
            if (_timeSpan.TotalSeconds > 0 & _timeSpan.TotalSeconds < 1)
            {
                Result.isDeal = false;
                Result.Command = objCommand;
                Result.Error = "PLEASE TRY AGAIN";

                //string message = "AddCommand$False,ACCOUNT READ ONLY," + Command.ID + "," + Command.Investor.InvestorID + "," + Command.Symbol.Name + "," +
                //            Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," + Command.TakeProfit + "," +
                //            Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + Command.Type.Name + "," +
                //            1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + Command.CommandCode + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Close," +
                //            DateTime.Now;

                //Command.Investor.ClientCommandQueue.Add(message);

                //if (Command.Investor.IsOnline == false)
                //{
                //    Business.Investor.investorInstance.SendCommandToInvestorOnline(Command.Investor.InvestorID, Business.TypeLogin.ReadOnly, message);
                //}

                //#region INSERT SYSTEM LOG EVENT MAKE COMMAND
                //content = content + " unsuccessful [account read only]";
                //TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[account read only]", objCommand.IpAddress, Command.Investor.Code);
                //#endregion
                Command.Investor.TimeDelayMakeCommand = DateTime.Now;

                return Result;
            }

            Command.Investor.TimeDelayMakeCommand = DateTime.Now;

            #region CHECK INVESTOR ONLINE(CHECK ACCOUNT IS PRIMARY)
            bool checkOnline = TradingServer.Business.Investor.investorInstance.CheckPrimaryInvestorOnline(objCommand.InvestorID, TradingServer.Business.TypeLogin.Primary, objCommand.LoginKey);
            if (!checkOnline)
            {
                Result.isDeal = false;
                Result.Command = objCommand;
                Result.Error = "ACCOUNT READ ONLY";

                string message = "AddCommand$False,ACCOUNT READ ONLY," + Command.ID + "," + Command.Investor.InvestorID + "," + Command.Symbol.Name + "," +
                            Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," + Command.TakeProfit + "," +
                            Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + Command.Type.Name + "," +
                            1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + Command.CommandCode + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Close," +
                            DateTime.Now;

                Command.Investor.ClientCommandQueue.Add(message);

                if (Command.Investor.IsOnline == false)
                {
                    Business.Investor.investorInstance.SendCommandToInvestorOnline(Command.Investor.InvestorID, Business.TypeLogin.ReadOnly, message);
                }

                #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                content = content + " unsuccessful [account read only]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[account read only]", objCommand.IpAddress, Command.Investor.Code);
                #endregion

                return Result;
            }
            #endregion

            #region CHECK MANUAL DEALERS OR AUTOMATIC
            string executionType = Business.Market.marketInstance.GetExecutionType(Command.IGroupSecurity, "B03");

            if (executionType == "manual only- no automation" ||
                executionType == "manual- but automatic if no dealer online" ||
                executionType == "automatic only")
            {
                Command.OpenPrice = double.Parse(objCommand.OpenPrice);
                Command.Size = objCommand.Size;
                Command.StopLoss = objCommand.StopLoss;
                Command.TakeProfit = objCommand.TakeProfit;
                Command.ClientCode = objCommand.ClientCode;
                Command.IsHedged = Command.Symbol.IsHedged;
                Command.MaxDev = objCommand.MaxDev;
                Command.ExpTime = objCommand.TimeExpiry;
                Command.IpAddress = objCommand.IpAddress;

                Command.Symbol.MarketAreaRef.AddCommand(Command);
                Result.Command = objCommand;
                Result.isDeal = true;
                return Result;
            }
            #endregion

            //===========================================================================================================================

            #region SET PRICE SERVER
            Command.BidServer = Command.Symbol.TickValue.Bid;
            Command.AskServer = Command.Symbol.TickValue.Ask;
            #endregion

            #region CHECK RULE TRADE IN ET5 SYSTEM(UPDATE 19/09/2013). NOTE: THE SAME MT4(ANDREW BOSS)
            bool isEnable = Command.IsEnableCheckRuleTrade(Command);
            if (isEnable)
            {
                bool isValidRule = Command.CheckRuleTrader(Command, objCommand.Size);
                if (!isValidRule)
                {
                    if (Command.Investor != null)
                    {
                        //Add Result To Client Command Queue Of Investor
                        string Message = "AddCommand$False,TRADE IS DISABLED," + Command.ID + "," + Command.Investor.InvestorID + "," +
                                Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                    Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                    "Open" + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                        if (Command.Investor.ClientCommandQueue == null)
                            Command.Investor.ClientCommandQueue = new List<string>();

                        int investorOnline = Command.Investor.CountInvestorOnline(Command.Investor.InvestorID);
                        if (investorOnline > 0)
                            Command.Investor.ClientCommandQueue.Add(Message);
                    }

                    Result.isDeal = false;
                    Result.Error = "TRADE IS DISABLED";
                    Result.Command = objCommand;

                    #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                    string tempContent = "make command";
                    tempContent = tempContent + " unsuccessful [trade is disabled]";
                    TradingServer.Facade.FacadeAddNewSystemLog(5, tempContent, "[trade is disabled]", objCommand.IpAddress, Command.Investor.Code);
                    #endregion

                    return Result;
                }
            }
            #endregion

            #region CHECK TIME TICK SERVER
            if (!Command.Symbol.CheckTimeTick())
            {
                if (Command.Investor != null)
                {
                    //Add Result To Client Command Queue Of Investor
                    string Message = "AddCommand$False,MARKET ON HOLD," + Command.ID + "," + Command.Investor.InvestorID + "," +
                            Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                "Open" + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                    if (Command.Investor.ClientCommandQueue == null)
                        Command.Investor.ClientCommandQueue = new List<string>();

                    int investorOnline = Command.Investor.CountInvestorOnline(Command.Investor.InvestorID);
                    if (investorOnline > 0)
                        Command.Investor.ClientCommandQueue.Add(Message);
                }

                Result.isDeal = false;
                Result.Error = "MARKET ON HOLD";
                Result.Command = objCommand;

                #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                string tempContent = "make command";
                tempContent = tempContent + " unsuccessful [symbol on hold]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, tempContent, "[symbol on hold]", objCommand.IpAddress, Command.Investor.Code);
                #endregion

                return Result;
            }
            #endregion

            #region CHECK NULL OBJECT
            if (Command == null)
            {
                TradingServer.Facade.FacadeAddNewSystemLog(1, "[Make Command Error] Command Is Null", "[Make Command Failed]", "", "");

                return Result;
            }

            if (Command.Investor == null || Command.Symbol == null || Command.Type == null || Command.IGroupSecurity == null)
            {
                //Add Result To Client Command Queue Of Investor
                string Message = "AddCommand$False,COMMAND DON'T EXISTS," + Command.ID + "," + Command.Investor.InvestorID + "," +
                        Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                            Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                            "Open" + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();

                //int countInvestorOnline = Command.Investor.CountInvestorOnline(Command.Investor.InvestorID);
                //if (countInvestorOnline > 0)
                    Command.Investor.ClientCommandQueue.Add(Message);

                Result.isDeal = false;
                Result.Error = "TRADE IS DISABLED. PLEASE TRY AGAIN";
                Result.Command = objCommand;

                TradingServer.Facade.FacadeAddNewSystemLog(1, "symbol, investor, type or igroupsecurity empty", "[make command]", "", "");

                return Result;
            }
            #endregion

            #region CHECK VALID IPADDRESS
            bool checkIP = TradingServer.Business.ValidIPAddress.Instance.ValidIpAddress(objCommand.InvestorID, objCommand.IpAddress);
            if (!checkIP)
            {
                Result.isDeal = false;
                Result.Command = objCommand;
                Result.Error = "INVALID IP ADDRESS";

                string message = "AddCommand$False,INVALID IP ADDRESS," + Command.ID + "," + Command.Investor.InvestorID + "," + Command.Symbol.Name + "," +
                            Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," + Command.TakeProfit + "," +
                            Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + Command.Type.Name + "," +
                            1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + Command.CommandCode + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Close," +
                            DateTime.Now;

                Command.Investor.ClientCommandQueue.Add(message);

                #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                content = content + " unsuccessful [invalid ip address]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[invalid ip address]", objCommand.IpAddress, Command.Investor.Code);
                #endregion

                return Result;
            }
            #endregion

            #region CHECK INVESTOR ONLINE
            //CHECK INVESTOR ONLINE
            bool isOnline = TradingServer.Business.Investor.investorInstance.CheckInvestorOnline(objCommand.InvestorID, objCommand.LoginKey);
            if (!isOnline)
            {
                //ADD INVESTOR TO LIST ONLINE IF CLIENT TIME OUT
                bool isAdd = TradingServer.Business.Investor.investorInstance.CheckOnlineInvestor(objCommand.InvestorID, objCommand.LoginKey);
            }
            #endregion

            #region CHECK INVESTOR ONLINE(CHECK ACCOUNT IS PRIMARY)
            //bool checkOnline = TradingServer.Business.Investor.investorInstance.CheckPrimaryInvestorOnline(objCommand.InvestorID, TradingServer.Business.TypeLogin.Primary, objCommand.LoginKey);
            //if (!checkOnline)
            //{
            //    Result.isDeal = false;
            //    Result.Command = objCommand;
            //    Result.Error = "ACCOUNT READ ONLY";

            //    string message = "AddCommand$False,ACCOUNT READ ONLY," + Command.ID + "," + Command.Investor.InvestorID + "," + Command.Symbol.Name + "," +
            //                Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," + Command.TakeProfit + "," +
            //                Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + Command.Type.Name + "," +
            //                1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + Command.CommandCode + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Close," +
            //                DateTime.Now;

            //    Command.Investor.ClientCommandQueue.Add(message);

            //    #region INSERT SYSTEM LOG EVENT MAKE COMMAND
            //    content = content + " unsuccessful [account read only]";
            //    TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[account read only]", objCommand.IpAddress, Command.Investor.Code);
            //    #endregion

            //    return Result;
            //}
            #endregion

            Command.Investor.IpAddress = objCommand.IpAddress;

            #region CHECK SYMBOL EXISTS IN SECURITY
            bool isExists = Business.Market.marketInstance.IsExistsSymbolInSecurity(Command);
            if (!isExists)
            {
                //Add Result To Client Command Queue Of Investor
                string Message = "AddCommand$False,ACTION NOT ALLOW," + Command.ID + "," + Command.Investor.InvestorID + "," +
                        Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                            Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                            "Open" + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();

                Command.Investor.ClientCommandQueue.Add(Message);

                Result.isDeal = false;
                Result.Error = "ACTION NOT ALLOW";
                Result.Command = objCommand;

                #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                content = content + " unsuccessful [symbol don't exits in security]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[symbol don't exits in security]", objCommand.IpAddress, Command.Investor.Code);
                #endregion

                return Result;
            }
            #endregion

            #region CHECK ACCOUNT LOGIN WITH PASSWORD READ ONLY
            if (Command.Investor.IsReadOnly)
            {
                //Add Result To Client Command Queue Of Investor
                string Message = "AddCommand$False,TRADE IS DISABLED," + Command.ID + "," + Command.Investor.InvestorID + "," +
                        Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                            Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                            "Open" + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();

                Command.Investor.ClientCommandQueue.Add(Message);

                Result.isDeal = false;
                Result.Error = "TRADE IS DISABLED";
                Result.Command = objCommand;

                #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                content = content + " unsuccessful [trade is disabled]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[trade is disabled]", objCommand.IpAddress, Command.Investor.Code);
                #endregion

                return Result;
            }
            #endregion

            #region CONVERT TYPE.ID TO COMMAND TYPE
            string CommandType = string.Empty;
            switch (Command.Type.ID)
            {
                case 1:
                    CommandType = "Open";
                    break;
                case 2:
                    CommandType = "Open";
                    break;
                case 7:
                    CommandType = "BuyLimit";
                    break;
                case 8:
                    CommandType = "SellLimit";
                    break;
                case 9:
                    CommandType = "BuyStop";
                    break;
                case 10:
                    CommandType = "SellStop";
                    break;
                case 11:
                    CommandType = "BuyFuture";
                    break;
                case 12:
                    CommandType = "SellFuture";
                    break;
                case 17:
                    CommandType = "BuyStopFutureCommand";
                    break;
                case 18:
                    CommandType = "SellStopFutureCommand";
                    break;
                case 19:
                    CommandType = "BuyLimitFutureCommand";
                    break;
                case 20:
                    CommandType = "SellLimitFutureCommand";
                    break;
            }
            #endregion

            #region CHECK TIME MARKET
            if (!Business.Market.IsOpen)
            {
                string Message = "AddCommand$False,MARKET IS CLOSE," + Command.ID + "," + Command.Investor.InvestorID + "," +
                            Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," +
                            Command.StopLoss + "," + Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," +
                            Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + "Open" + "," + 1 + "," +
                            Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," +
                            Command.Margin + ",Open";

                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();

                Command.Investor.ClientCommandQueue.Add(Message);

                Result.isDeal = false;
                Result.Error = "MARKET IS CLOSE";
                Result.Command = objCommand;

                #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                content = content + " unsuccessful [market is close]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[market is close]", objCommand.IpAddress, Command.Investor.Code);
                #endregion

                return Result;
            }   //END IF CHECK STATUS MARKET
            #endregion

            #region CHECK IS TRADE OF SYMBOL
            if (!Command.Symbol.IsTrade)
            {
                string Message = "AddCommand$False,SYMBOL IS CLOSE," + Command.ID + "," + Command.Investor.InvestorID + "," +
                                Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," +
                                Command.StopLoss + "," + Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," +
                                Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + "Open" + "," + 1 + "," +
                                Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," +
                                Command.Margin + ",Open";

                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();

                Command.Investor.ClientCommandQueue.Add(Message);

                Result.isDeal = false;
                Result.Error = "SYMBOL IS CLOSE";
                Result.Command = objCommand;

                #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                content = content + " unsuccessful [symbol is close]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[symbol is close]", objCommand.IpAddress, Command.Investor.Code);
                #endregion

                return Result;
            }
            #endregion

            #region CHECK HOLIDAY OF SERVER
            if (Command.Symbol.IsHoliday)
            {
                string Message = "AddCommand$False,MARKET IS HOLIDAY," + Command.ID + "," + Command.Investor.InvestorID + "," +
                               Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," +
                               Command.StopLoss + "," + Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," +
                               Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + "Open" + "," + 1 + "," +
                               Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," +
                               Command.Margin + ",Open";

                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();

                Command.Investor.ClientCommandQueue.Add(Message);

                Result.isDeal = false;
                Result.Error = "MARKET IS HOLIDAY";
                Result.Command = objCommand;

                #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                content = content + " unsuccessful [market is holiday]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[market is holiday]", objCommand.IpAddress, Command.Investor.Code);
                #endregion

                return Result;
            }
            #endregion

            if (Command.Investor != null)
            {
                #region CHECK INVESTOR ISDISABLE
                if (Command.Investor.IsDisable)
                {
                    //Add Result To Client Command Queue Of Investor
                    string Message = "AddCommand$False,ACCOUNT IS DISABLED," + Command.ID + "," + Command.Investor.InvestorID + "," +
                            Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                "Open" + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                    if (Command.Investor.ClientCommandQueue == null)
                        Command.Investor.ClientCommandQueue = new List<string>();

                    Command.Investor.ClientCommandQueue.Add(Message);

                    Result.isDeal = false;
                    Result.Error = "ACCOUNT IS DISABLED";
                    Result.Command = objCommand;

                    #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                    content = content + " unsuccessful [account is disabled]";
                    TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[account is disabled]", objCommand.IpAddress, Command.Investor.Code);
                    #endregion

                    return Result;
                }   //END IF CHECK ISDISABLE OF ACCOUNT
                #endregion

                #region CHECK INVESTOR READ ONLY
                if (Command.Investor.ReadOnly)
                {
                    //Add Result To Client Command Queue Of Investor
                    string Message = "AddCommand$False,TRADE IS DISABLED," + Command.ID + "," + Command.Investor.InvestorID + "," +
                            Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                "Open" + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                    if (Command.Investor.ClientCommandQueue == null)
                        Command.Investor.ClientCommandQueue = new List<string>();

                    int countInvestorOnline = Command.Investor.CountInvestorOnline(Command.Investor.InvestorID);
                    if (countInvestorOnline > 0)
                        Command.Investor.ClientCommandQueue.Add(Message);

                    Result.isDeal = false;
                    Result.Error = "TRADE IS DISABLED";
                    Result.Command = objCommand;

                    #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                    content = content + " unsuccessful [trade is disabled]";
                    TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[trade is disabled]", objCommand.IpAddress, Command.Investor.Code);
                    #endregion

                    return Result;
                }   //END IF CHECK READ ONLY OF ACCOUNT
                #endregion
            }

            #region CHECK TICK SIZE OF SYMBOL
            bool CheckTickSize = Command.Symbol.CheckTickSizeAtOpenCommand(Command.OpenPrice, Command.Symbol.Digit, Command.Symbol.TickSize);
            if (!CheckTickSize)
            {
                string Message = "AddCommand$False,INVALID TICK SIZE," + Command.ID + "," + Command.Investor.InvestorID + "," +
                            Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," +
                            Command.StopLoss + "," + Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," +
                            Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + "Open" + "," + 1 + "," +
                            Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," +
                            Command.Margin + ",Open";

                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();

                int countInvestorOnline = Command.Investor.CountInvestorOnline(Command.Investor.InvestorID);
                if (countInvestorOnline > 0)
                    Command.Investor.ClientCommandQueue.Add(Message);

                Result.isDeal = false;
                Result.Error = "INVALID TICK SIZE";
                Result.Command = objCommand;

                #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                content = content + " unsuccessful [invalid tick size]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[invalid tick size]", objCommand.IpAddress, Command.Investor.Code);
                #endregion

                return Result;
            }   //END IF CHECK TICK SIZE OF SYMBOL
            #endregion

            Command.OpenPrice = double.Parse(objCommand.OpenPrice);
            Command.Size = objCommand.Size;
            Command.StopLoss = objCommand.StopLoss;
            Command.TakeProfit = objCommand.TakeProfit;
            Command.ClientCode = objCommand.ClientCode;
            Command.IsHedged = Command.Symbol.IsHedged;
            Command.MaxDev = objCommand.MaxDev;
            Command.ExpTime = objCommand.TimeExpiry;

            #region CHECK OPEN PRICE OF PENDING ORDER
            if (Command.Type.ID == 7 || Command.Type.ID == 8 || Command.Type.ID == 9 || Command.Type.ID == 10 ||
                Command.Type.ID == 17 || Command.Type.ID == 18 || Command.Type.ID == 19 || Command.Type.ID == 20)
            {
                bool ResultCheckOpenPrice = false;
                ResultCheckOpenPrice = Command.Symbol.CheckOpenPricePendingOrder(Command.Symbol.Name, Command.Type.ID, Command.OpenPrice, Command.Symbol.LimitLevel,
                                            Command.Symbol.StopLevel, Command.Symbol.Digit, int.Parse(Command.SpreaDifferenceInOpenTrade.ToString()));
                if (ResultCheckOpenPrice == false)
                {
                    string Message = "AddCommand$False,INVALID OPEN PRICE," + Command.ID + "," + Command.Investor.InvestorID + "," +
                                    Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                        Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                        CommandType + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                    if (Command.Investor.ClientCommandQueue == null)
                        Command.Investor.ClientCommandQueue = new List<string>();

                    int countInvestorOnline = Command.Investor.CountInvestorOnline(Command.Investor.InvestorID);
                    if (countInvestorOnline > 0)
                        Command.Investor.ClientCommandQueue.Add(Message);

                    Result.Error = "INVALID OPEN PRICE";
                    Result.Command = objCommand;
                    Result.isDeal = false;

                    #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                    content = content + " unsuccessful [invalid open price]";
                    TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[invalid open price]", objCommand.IpAddress, Command.Investor.Code);
                    #endregion

                    return Result;
                }   //END IF CHECK S/L AND T/P OF COMMAND
            }   //END IF CHECK COMMAND IS PENDING ORDER
            #endregion

            #region Get Setting IsTrade In Group
            bool IsTradeGroup = false;
            if (Business.Market.InvestorGroupList != null)
            {
                int count = Business.Market.InvestorGroupList.Count;
                for (int i = 0; i < count; i++)
                {
                    if (Business.Market.InvestorGroupList[i].InvestorGroupID == Command.Investor.InvestorGroupInstance.InvestorGroupID)
                    {
                        if (Business.Market.InvestorGroupList[i].ParameterItems != null)
                        {
                            int countParameter = Business.Market.InvestorGroupList[i].ParameterItems.Count;
                            for (int j = 0; j < countParameter; j++)
                            {
                                if (Business.Market.InvestorGroupList[i].ParameterItems[j].Code == "G01")
                                {
                                    if (Business.Market.InvestorGroupList[i].ParameterItems[j].BoolValue == 1)
                                        IsTradeGroup = true;

                                    break;
                                }
                            }
                        }
                        break;
                    }
                }
            }
            #endregion

            if (IsTradeGroup)
            {
                if (Command.Symbol == null || Command.Investor == null || Command.Type == null || Command.IGroupSecurity == null)
                {
                    #region Check Investor != null Then Return Error To Client
                    if (Command.Investor != null)
                    {
                        //Add Result To Client Command Queue Of Investor
                        string Message = "AddCommand$False,TRADE IS DISABLED," + Result + "," + Command.Investor.InvestorID + "," +
                                Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                    Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                    "Open" + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                        if (Command.Investor.ClientCommandQueue == null)
                            Command.Investor.ClientCommandQueue = new List<string>();

                        Command.Investor.ClientCommandQueue.Add(Message);

                        Result.isDeal = false;
                        Result.Error = "Can't Find Symbol Investor Or Type Command";
                        Result.Command = objCommand;

                        #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                        content = content + " unsuccessful [can't find symbol investor or type command]";
                        TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[can't find symbol investor or type command]", objCommand.IpAddress, Command.Investor.Code);
                        #endregion

                        return Result;
                    }
                    #endregion
                }   //END IF CHECK SYMBOL, INVESTOR , TYPE, IGROUPSECURITY IS NULL
                else
                {
                    #region Set Property IsBuy And CommandType Send To Client
                    bool IsBuy = false;
                    if (Command.Type.ID == 1 || Command.Type.ID == 7 || Command.Type.ID == 9 || Command.Type.ID == 11 ||
                        Command.Type.ID == 17 || Command.Type.ID == 19)
                        IsBuy = true;
                    #endregion

                    #region Check Lots Minimum And Maximum In IGroupSecurity And Check IsTrade In IGroupSecurity
                    bool IsTrade = false;
                    double Minimum = -1;
                    double Maximum = -1;
                    double Step = -1;
                    bool ResultCheckStepLots = false;

                    #region Get Config IGroupSecurity
                    if (Command.IGroupSecurity.IGroupSecurityConfig != null)
                    {
                        int countIGroupSecurityConfig = Command.IGroupSecurity.IGroupSecurityConfig.Count;
                        for (int i = 0; i < countIGroupSecurityConfig; i++)
                        {
                            if (Command.IGroupSecurity.IGroupSecurityConfig[i].Code == "B01")
                            {
                                if (Command.IGroupSecurity.IGroupSecurityConfig[i].BoolValue == 1)
                                    IsTrade = true;
                            }

                            if (Command.IGroupSecurity.IGroupSecurityConfig[i].Code == "B11")
                            {
                                double.TryParse(Command.IGroupSecurity.IGroupSecurityConfig[i].NumValue, out Minimum);
                            }

                            if (Command.IGroupSecurity.IGroupSecurityConfig[i].Code == "B12")
                            {
                                double.TryParse(Command.IGroupSecurity.IGroupSecurityConfig[i].NumValue, out Maximum);
                            }

                            if (Command.IGroupSecurity.IGroupSecurityConfig[i].Code == "B13")
                            {
                                double.TryParse(Command.IGroupSecurity.IGroupSecurityConfig[i].NumValue, out Step);
                            }
                        }
                    }
                    #endregion

                    if (IsTrade == true)
                    {
                        ResultCheckStepLots = Command.IGroupSecurity.CheckStepLots(Minimum, Maximum, Step, Command.Size);

                        #region If Check Step Lots False Return Client
                        if (ResultCheckStepLots == false)
                        {
                            string Message = "AddCommand$False,WRONG VOLUME MINIMUM : " + Minimum + " LOT " + "MAXIMUM " + Maximum + " LOT," + Command.ID + "," + Command.Investor.InvestorID + "," +
                                    Command.Symbol.Name + "," + Command.Size + "," + IsBuy + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                        Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                        CommandType + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                            if (Command.Investor.ClientCommandQueue == null)
                                Command.Investor.ClientCommandQueue = new List<string>();

                            int countInvestorOnline = Command.Investor.CountInvestorOnline(Command.Investor.InvestorID);
                            if (countInvestorOnline > 0)
                                Command.Investor.ClientCommandQueue.Add(Message);

                            Result.isDeal = false;
                            Result.Error = "WRONG VOLUME";
                            Result.Command = objCommand;

                            #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                            content = content + " unsuccessful [wrong volume minimum]";
                            TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[wrong volume minimum]", objCommand.IpAddress, Command.Investor.Code);
                            #endregion

                            return Result;
                        }   //END IF CHECK STEP LOTS OF SYMBOL
                        #endregion
                    }   //END IF CHECK IS TRADE OF SYMBOL
                    else
                    {
                        string Message = "AddCommand$False,SYMBOL CANNOT BE TRADED," + Command.ID + "," + Command.Investor.InvestorID + "," +
                                    Command.Symbol.Name + "," + Command.Size + "," + IsBuy + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                        Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                        CommandType + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                        if (Command.Investor.ClientCommandQueue == null)
                            Command.Investor.ClientCommandQueue = new List<string>();

                        int countInvestorOnline = Command.Investor.CountInvestorOnline(Command.Investor.InvestorID);
                        if (countInvestorOnline > 0)
                            Command.Investor.ClientCommandQueue.Add(Message);

                        Result.isDeal = false;
                        Result.Error = "SYMBOL CANNOT BE TRADED";
                        Result.Command = objCommand;

                        #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                        content = content + " unsuccessful [symbol cannot be trade]";
                        TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[symbol cannot be traded]", objCommand.IpAddress, Command.Investor.Code);
                        #endregion

                        return Result;
                    }   //END ELSE CHECK IS TRADE OF SYMBOL
                    #endregion

                    #region Check Status Trade Of Symbol(Full Access,Close Only, No)
                    if (Command.Symbol.Trade.ToUpper() != "FULL ACCESS")
                    {
                        string Message = "AddCommand$False,ACTION NOT ALLOWED," + Command.ID + "," + Command.Investor.InvestorID + "," +
                                Command.Symbol.Name + "," + Command.Size + "," + IsBuy + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                    Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                    CommandType + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                        if (Command.Investor.ClientCommandQueue == null)
                            Command.Investor.ClientCommandQueue = new List<string>();

                        int countInvestorOnline = Command.Investor.CountInvestorOnline(Command.Investor.InvestorID);
                        if (countInvestorOnline > 0)
                            Command.Investor.ClientCommandQueue.Add(Message);

                        Result.isDeal = false;
                        Result.Error = "ACTION NOT ALLOWED";
                        Result.Command = objCommand;

                        #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                        content = content + " unsuccessful [symbol close only]";
                        TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[symbol close only]", objCommand.IpAddress, Command.Investor.Code);
                        #endregion

                        return Result;
                    }   //END IF CHECK STATUS OF SYMBOL(FULL ACCESS, CLOSE ONLY, NO TRADE)
                    #endregion

                    #region Check Stop Loss And Take Profit
                    if (Command.StopLoss > 0 || Command.TakeProfit > 0)
                    {
                        if (Command.Type.ID == 1 || Command.Type.ID == 2 || Command.Type.ID == 11 || Command.Type.ID == 12)
                        {
                            #region Check Limit And Stop Of Open Trade
                            bool ResultCheckLimit = false;

                            ResultCheckLimit = Command.Symbol.CheckLimitAndStop(Command.Symbol.Name, Command.Type.ID, Command.StopLoss, Command.TakeProfit,
                                                                Command.Symbol.StopLossTakeProfitLevel, Command.Symbol.Digit,
                                                                int.Parse(Command.SpreaDifferenceInOpenTrade.ToString()));

                            if (ResultCheckLimit == false)
                            {
                                string Message = "AddCommand$False,MARKET PRICE TOO CLOSE ACTION NOT ALLOWED," + Command.ID + "," + Command.Investor.InvestorID + "," +
                                    Command.Symbol.Name + "," + Command.Size + "," + IsBuy + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                        Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                        CommandType + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                                if (Command.Investor.ClientCommandQueue == null)
                                    Command.Investor.ClientCommandQueue = new List<string>();

                                int countInvestorOnline = Command.Investor.CountInvestorOnline(Command.Investor.InvestorID);
                                if (countInvestorOnline > 0)
                                    Command.Investor.ClientCommandQueue.Add(Message);

                                Result.isDeal = false;
                                Result.Error = "MARKET PRICE TOO CLOSE ACTION NOT ALLOWED";
                                Result.Command = objCommand;

                                #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                                content = content + " unsuccessful [invalid limit and stop]";
                                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[invalid limit and stop]", objCommand.IpAddress, Command.Investor.Code);
                                #endregion

                                return Result;
                            }
                            #endregion
                        }   //END IF CHECK COMMAND IS SPOT COMMAND
                        else if (Command.Type.ID == 7 || Command.Type.ID == 8 || Command.Type.ID == 9 || Command.Type.ID == 10 ||
                            Command.Type.ID == 17 || Command.Type.ID == 18 || Command.Type.ID == 19 || Command.Type.ID == 20 )
                        {
                            #region Check Limit And Stop Of Pending Order
                            bool ResultCheckLimit = false;
                            ResultCheckLimit = Command.Symbol.CheckLimitAndStopPendingOrder(Command.Symbol.Name, Command.Type.ID, Command.OpenPrice,
                                Command.StopLoss, Command.TakeProfit, Command.Symbol.StopLossTakeProfitLevel, Command.Symbol.Digit);

                            if (ResultCheckLimit == false)
                            {
                                string Message = "AddCommand$False,MARKET PRICE TOO CLOSE ACTION NOT ALLOWED," + Command.ID + "," + Command.Investor.InvestorID + "," +
                                    Command.Symbol.Name + "," + Command.Size + "," + IsBuy + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                        Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                        CommandType + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                                if (Command.Investor.ClientCommandQueue == null)
                                    Command.Investor.ClientCommandQueue = new List<string>();

                                int countInvestorOnline = Command.Investor.CountInvestorOnline(Command.Investor.InvestorID);
                                if (countInvestorOnline > 0)
                                    Command.Investor.ClientCommandQueue.Add(Message);

                                Result.isDeal = false;
                                Result.Error = "MARKET PRICE TOO CLOSE ACTION NOT ALLOWED";
                                Result.Command = objCommand;

                                #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                                content = content + " unsuccessful [invalid limit and stop]";
                                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[invalid limit and stop]", objCommand.IpAddress, Command.Investor.Code);
                                #endregion

                                return Result;
                            }
                            #endregion
                        }   //END IF CHECK COMMAND IS PENDING ORDER
                    }   //END IF CHECK STOP LOSS AND TAKE PROFIT
                    #endregion

                    #region Check Setting IsLong
                    switch (Command.Type.ID)
                    {
                        #region Case Sell
                        case 2:
                            {
                                if (Command.Symbol.LongOnly == true)
                                {
                                    string Message = "AddCommand$False,ONLY LONG POSITION ALLOWED," + Command.ID + "," + Command.Investor.InvestorID + "," +
                                    Command.Symbol.Name + "," + Command.Size + "," + IsBuy + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                        Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                        CommandType + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                                    if (Command.Investor.ClientCommandQueue == null)
                                        Command.Investor.ClientCommandQueue = new List<string>();

                                    Command.Investor.ClientCommandQueue.Add(Message);

                                    Result.isDeal = false;
                                    Result.Error = "ONLY LONG POSITION ALLOWED";
                                    Result.Command = objCommand;

                                    #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                                    content = content + " unsuccessful [only long position]";
                                    TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[only long position]", objCommand.IpAddress, Command.Investor.Code);
                                    #endregion

                                    return Result;
                                }
                            }
                            break;
                        #endregion

                        #region Case Sell Limit
                        case 8:
                            {
                                if (Command.Symbol.LongOnly == true)
                                {
                                    string Message = "AddCommand$False,ONLY LONG POSITION ALLOWED," + Command.ID + "," + Command.Investor.InvestorID + "," +
                                    Command.Symbol.Name + "," + Command.Size + "," + IsBuy + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                        Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                        CommandType + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                                    if (Command.Investor.ClientCommandQueue == null)
                                        Command.Investor.ClientCommandQueue = new List<string>();

                                    Command.Investor.ClientCommandQueue.Add(Message);

                                    Result.isDeal = false;
                                    Result.Error = "ONLY LONG POSITION ALLOWED";
                                    Result.Command = objCommand;

                                    #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                                    content = content + " unsuccessful [only long position]";
                                    TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[only long position]", objCommand.IpAddress, Command.Investor.Code);
                                    #endregion

                                    return Result;
                                }
                            }
                            break;
                        #endregion

                        #region Case Sell Stop
                        case 10:
                            {
                                if (Command.Symbol.LongOnly == true)
                                {
                                    string Message = "AddCommand$False,ONLY LONG POSITION ALLOWED," + Command.ID + "," + Command.Investor.InvestorID + "," +
                                    Command.Symbol.Name + "," + Command.Size + "," + IsBuy + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                        Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                        CommandType + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                                    if (Command.Investor.ClientCommandQueue == null)
                                        Command.Investor.ClientCommandQueue = new List<string>();

                                    Command.Investor.ClientCommandQueue.Add(Message);

                                    Result.isDeal = false;
                                    Result.Error = "ONLY LONG POSITION ALLOWED";
                                    Result.Command = objCommand;

                                    #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                                    content = content + " unsuccessful [only long position]";
                                    TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[only long position]", objCommand.IpAddress, Command.Investor.Code);
                                    #endregion

                                    return Result;
                                }
                            }
                            break;
                        #endregion

                        #region SELL FUTURE
                        case 12:
                            {
                                if (Command.Symbol.LongOnly)
                                {
                                    string Message = "AddCommand$False,ONLY LONG POSITION ALLOWED," + Command.ID + "," + Command.Investor.InvestorID + "," +
                                    Command.Symbol.Name + "," + Command.Size + "," + IsBuy + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                        Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                        CommandType + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                                    if (Command.Investor.ClientCommandQueue == null)
                                        Command.Investor.ClientCommandQueue = new List<string>();

                                    Command.Investor.ClientCommandQueue.Add(Message);

                                    Result.isDeal = false;
                                    Result.Error = "ONLY LONG POSITION ALLOWED";
                                    Result.Command = objCommand;

                                    #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                                    content = content + " unsuccessful [only long position]";
                                    TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[only long position]", objCommand.IpAddress, Command.Investor.Code);
                                    #endregion

                                    return Result;
                                }
                            }
                            break;
                        #endregion

                        #region SELL STOP FUTURE
                        case 18:
                            {
                                if (Command.Symbol.LongOnly)
                                {
                                    string Message = "AddCommand$False,ONLY LONG POSITION ALLOWED," + Command.ID + "," + Command.Investor.InvestorID + "," +
                                    Command.Symbol.Name + "," + Command.Size + "," + IsBuy + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                        Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                        CommandType + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                                    if (Command.Investor.ClientCommandQueue == null)
                                        Command.Investor.ClientCommandQueue = new List<string>();

                                    Command.Investor.ClientCommandQueue.Add(Message);

                                    Result.isDeal = false;
                                    Result.Error = "ONLY LONG POSITION ALLOWED";
                                    Result.Command = objCommand;

                                    #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                                    content = content + " unsuccessful [only long position]";
                                    TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[only long position]", objCommand.IpAddress, Command.Investor.Code);
                                    #endregion

                                    return Result;
                                }
                            }
                            break;
                        #endregion

                        #region SELL LIMIT FUTURE
                        case 20:
                            {
                                if (Command.Symbol.LongOnly)
                                {
                                    string Message = "AddCommand$False,ONLY LONG POSITION ALLOWED," + Command.ID + "," + Command.Investor.InvestorID + "," +
                                    Command.Symbol.Name + "," + Command.Size + "," + IsBuy + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                        Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                        CommandType + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                                    if (Command.Investor.ClientCommandQueue == null)
                                        Command.Investor.ClientCommandQueue = new List<string>();

                                    Command.Investor.ClientCommandQueue.Add(Message);

                                    Result.isDeal = false;
                                    Result.Error = "ONLY LONG POSITION ALLOWED";
                                    Result.Command = objCommand;

                                    #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                                    content = content + " unsuccessful [only long position]";
                                    TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[only long position]", objCommand.IpAddress, Command.Investor.Code);
                                    #endregion

                                    return Result;
                                }
                            }
                            break;
                        #endregion
                    }
                    #endregion

                    #region Find Price Close Of Symbol
                    switch (Command.Type.ID)
                    {
                        case 1:
                            Command.ClosePrice = Command.Symbol.TickValue.Bid;
                            break;
                        case 2:
                            Command.ClosePrice = Command.Symbol.TickValue.Ask;
                            break;

                        #region BUY LIMIT SPOT
                        case 7: //BUY LIMIT
                            Command.ClosePrice = Command.Symbol.TickValue.Bid;
                            if (Command.OpenPrice > Command.Symbol.TickValue.Ask)
                            {
                                string Message = "AddCommand$False,INVALID OPEN PRICE," + Result + "," + Command.Investor.InvestorID + "," +
                                Command.Symbol.Name + "," + Command.Size + "," + IsBuy + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                    Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                    CommandType + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0" + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                                Command.Investor.ClientCommandQueue.Add(Message);

                                Result.isDeal = false;
                                Result.Command = objCommand;
                                Result.Error = "INVALID OPEN PRICE";

                                #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                                content = content + " unsuccessful [invalid open price] (" + Command.OpenPrice + " > " + Command.Symbol.TickValue.Ask + ")";
                                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[invalid open price]", objCommand.IpAddress, Command.Investor.Code);
                                #endregion
                            }
                            break;
                        #endregion

                        #region SELL LIMIT SPOT
                        case 8: //SELL LIMIT
                            Command.ClosePrice = Command.Symbol.TickValue.Ask;
                            if (Command.OpenPrice < Command.Symbol.TickValue.Bid)
                            {
                                string Message = "AddCommand$False,INVALID OPEN PRICE," + Result + "," + Command.Investor.InvestorID + "," +
                                Command.Symbol.Name + "," + Command.Size + "," + IsBuy + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                    Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                    CommandType + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0" + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                                Command.Investor.ClientCommandQueue.Add(Message);

                                Result.isDeal = false;
                                Result.Command = objCommand;
                                Result.Error = "INVALID OPEN PRICE";

                                #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                                content = content + " unsuccessful [invalid open price] (" + Command.OpenPrice + " < " + Command.Symbol.TickValue.Ask + ")";
                                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[invalid open price]", objCommand.IpAddress, Command.Investor.Code);
                                #endregion
                            }
                            break;
                        #endregion

                        #region BUY STOP SPOT
                        case 9: //BUY STOP
                            Command.ClosePrice = Command.Symbol.TickValue.Bid;
                            if (Command.OpenPrice < Command.Symbol.TickValue.Ask)
                            {
                                string Message = "AddCommand$False,INVALID OPEN PRICE," + Result + "," + Command.Investor.InvestorID + "," +
                                Command.Symbol.Name + "," + Command.Size + "," + IsBuy + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                    Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                    CommandType + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0" + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                                Command.Investor.ClientCommandQueue.Add(Message);

                                Result.isDeal = false;
                                Result.Command = objCommand;
                                Result.Error = "INVALID OPEN PRICE";

                                #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                                content = content + " unsuccessful [invalid open price] (" + Command.OpenPrice + " < " + Command.Symbol.TickValue.Ask + ")";
                                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[invalid open price]", objCommand.IpAddress, Command.Investor.Code);
                                #endregion
                            }
                            break;
                        #endregion

                        #region SELL STOP SPOT
                        case 10:    //SELL STOP
                            Command.ClosePrice = Command.Symbol.TickValue.Ask;

                            if (Command.OpenPrice > Command.Symbol.TickValue.Bid)
                            {
                                string Message = "AddCommand$False,INVALID OPEN PRICE," + Result + "," + Command.Investor.InvestorID + "," +
                                Command.Symbol.Name + "," + Command.Size + "," + IsBuy + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                    Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                    CommandType + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0" + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                                Command.Investor.ClientCommandQueue.Add(Message);

                                Result.isDeal = false;
                                Result.Command = objCommand;
                                Result.Error = "INVALID OPEN PRICE";

                                #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                                content = content + " unsuccessful [invalid open price] (" + Command.OpenPrice + " > " + Command.Symbol.TickValue.Ask + ")";
                                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[invalid open price]", objCommand.IpAddress, Command.Investor.Code);
                                #endregion
                            }
                            break;
                        #endregion

                        case 11:
                            Command.ClosePrice = Command.Symbol.TickValue.Bid;
                            break;
                        case 12:
                            Command.ClosePrice = Command.Symbol.TickValue.Ask;
                            break;

                        #region BUY STOP FUTURE
                        case 17:    //BUY STOP
                            Command.ClosePrice = Command.Symbol.TickValue.Bid;

                            if (Command.OpenPrice < Command.Symbol.TickValue.Ask)
                            {
                                string Message = "AddCommand$False,INVALID OPEN PRICE," + Result + "," + Command.Investor.InvestorID + "," +
                                Command.Symbol.Name + "," + Command.Size + "," + IsBuy + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                    Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                    CommandType + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0" + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                                Command.Investor.ClientCommandQueue.Add(Message);

                                Result.isDeal = false;
                                Result.Command = objCommand;
                                Result.Error = "INVALID OPEN PRICE";

                                #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                                content = content + " unsuccessful [invalid open price] (" + Command.OpenPrice + " > " + Command.Symbol.TickValue.Ask + ")";
                                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[invalid open price]", objCommand.IpAddress, Command.Investor.Code);
                                #endregion
                            }
                            break;
                        #endregion

                        #region SELL STOP FUTURE
                        case 18:    //SELL STOP
                            Command.ClosePrice = Command.Symbol.TickValue.Ask;

                            if (Command.OpenPrice > Command.Symbol.TickValue.Bid)
                            {
                                string Message = "AddCommand$False,INVALID OPEN PRICE," + Result + "," + Command.Investor.InvestorID + "," +
                                Command.Symbol.Name + "," + Command.Size + "," + IsBuy + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                    Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                    CommandType + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0" + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                                Command.Investor.ClientCommandQueue.Add(Message);

                                Result.isDeal = false;
                                Result.Command = objCommand;
                                Result.Error = "INVALID OPEN PRICE";

                                #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                                content = content + " unsuccessful [invalid open price] (" + Command.OpenPrice + " > " + Command.Symbol.TickValue.Ask + ")";
                                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[invalid open price]", objCommand.IpAddress, Command.Investor.Code);
                                #endregion
                            }
                            break;
                        #endregion

                        #region BUY LIMIT FUTURE
                        case 19:    //BUY LIMIT
                            Command.ClosePrice = Command.Symbol.TickValue.Bid;
                            if (Command.OpenPrice > Command.Symbol.TickValue.Ask)
                            {
                                string Message = "AddCommand$False,INVALID OPEN PRICE," + Result + "," + Command.Investor.InvestorID + "," +
                                Command.Symbol.Name + "," + Command.Size + "," + IsBuy + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                    Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                    CommandType + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0" + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                                Command.Investor.ClientCommandQueue.Add(Message);

                                Result.isDeal = false;
                                Result.Command = objCommand;
                                Result.Error = "INVALID OPEN PRICE";

                                #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                                content = content + " unsuccessful [invalid open price] (" + Command.OpenPrice + " > " + Command.Symbol.TickValue.Ask + ")";
                                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[invalid open price]", objCommand.IpAddress, Command.Investor.Code);
                                #endregion
                            }
                            break;
                        #endregion

                        #region SELL LIMIT FUTURE
                        case 20:    //SELL LIMIT
                            Command.ClosePrice = Command.Symbol.TickValue.Ask;
                            if (Command.OpenPrice < Command.Symbol.TickValue.Bid)
                            {
                                string Message = "AddCommand$False,INVALID OPEN PRICE," + Result + "," + Command.Investor.InvestorID + "," +
                                Command.Symbol.Name + "," + Command.Size + "," + IsBuy + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                    Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                    CommandType + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0" + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                                Command.Investor.ClientCommandQueue.Add(Message);

                                Result.isDeal = false;
                                Result.Command = objCommand;
                                Result.Error = "INVALID OPEN PRICE";

                                #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                                content = content + " unsuccessful [invalid open price] (" + Command.OpenPrice + " > " + Command.Symbol.TickValue.Ask + ")";
                                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[invalid open price]", objCommand.IpAddress, Command.Investor.Code);
                                #endregion
                            }
                            break;
                        #endregion
                    }
                    #endregion

                    #region CHECK VALID ACCOUNT OF INVESTOR
                    bool checkValidAccount = false;
                    //Call Function Check Account Of Investor
                    checkValidAccount = Command.CheckValidAccountInvestor(Command);

                    if (!checkValidAccount)
                    {
                        #region Reurn Error Invalid Account For Client
                        //Add Result To Client Command Queue Of Investor
                        string Message = "AddCommand$False,NOT ENOUGH MONEY," + Command.ID + "," + Command.Investor.InvestorID + "," +
                                Command.Symbol.Name + "," + Command.Size + "," + IsBuy + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                    Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                    CommandType + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                        if (Command.Investor.ClientCommandQueue == null)
                            Command.Investor.ClientCommandQueue = new List<string>();

                        Command.Investor.ClientCommandQueue.Add(Message);
                        #endregion

                        Result.isDeal = false;
                        Result.Command = objCommand;
                        Result.Error = "NOT ENOUGH MONEY";

                        #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                        content = content + " unsuccessful [not enough money]";
                        TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[not enough money]", objCommand.IpAddress, Command.Investor.Code);
                        #endregion

                        return Result;
                    }
                    #endregion

                    if (Command.Type.ID == 1 || Command.Type.ID == 2 || Command.Type.ID == 11 || Command.Type.ID == 12)
                    {
                        //Call Dealer
                        Business.RequestDealer newRequestDealer = new Business.RequestDealer();
                        newRequestDealer.InvestorID = Command.Investor.InvestorID;
                        newRequestDealer.MaxDev = Command.MaxDev;
                        newRequestDealer.Name = "Open";
                        newRequestDealer.Request = Command;
                        newRequestDealer.TimeClientRequest = DateTime.Now;

                        TradingServer.Facade.FacadeSendRequestToDealer(newRequestDealer);
                    }
                    else
                    {
                        //Name: OpenPending
                        //Call Dealer
                        //Business.RequestDealer newRequestDealer = new Business.RequestDealer();
                        //newRequestDealer.InvestorID = Command.Investor.InvestorID;
                        //newRequestDealer.MaxDev = Command.MaxDev;
                        //newRequestDealer.Name = "OpenPending";
                        //newRequestDealer.Request = Command;
                        //newRequestDealer.TimeClientRequest = DateTime.Now;

                        //TradingServer.Facade.FacadeSendRequestToDealer(newRequestDealer);

                        Command.Symbol.MarketAreaRef.AddCommand(Command);
                    }

                    Result.Command = objCommand;
                    Result.isDeal = true;
                }
            }
            else
            {
                if (Command.Investor != null)
                {
                    //Add Result To Client Command Queue Of Investor
                    string Message = "AddCommand$False,ACTION NOT ALLOWED," + Result + "," + Command.Investor.InvestorID + "," +
                            Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                                Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                                "Open" + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                    if (Command.Investor.ClientCommandQueue == null)
                        Command.Investor.ClientCommandQueue = new List<string>();

                    Command.Investor.ClientCommandQueue.Add(Message);

                    #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                    content = content + " unsuccessful [trade is disable]";
                    TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[trade is disable]", objCommand.IpAddress, Command.Investor.Code);
                    #endregion
                }
            }

            return Result;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// CLOSE SPOT COMMAND
        /// </summary>
        /// <param name="Command"></param>
        /// <returns></returns>
        public static ClientBusiness.DealMessage FacadeCloseSpotCommand(TradingServer.ClientBusiness.Command objCommand)
        {
            ClientBusiness.DealMessage Result = new ClientBusiness.DealMessage();

            Result.isDeal = false;

            Business.OpenTrade Command = new Business.OpenTrade();

            #region Find In Symbol List And Remove Command
            Command = TradingServer.Facade.FacadeFindOpenTradeInCommandList(objCommand.CommandID);

            if (Command.Investor == null || Command.Type == null || Command.Symbol == null)
                return null;

            Command.Investor.IpAddress = objCommand.IpAddress;

            bool isRequest = false;
            if (Business.Market.marketInstance.MQLCommands != null)
            {
                int count = Business.Market.marketInstance.MQLCommands.Count;
                for (int i = 0; i < count; i++)
                {
                    if (Business.Market.marketInstance.MQLCommands[i].ClientCode == objCommand.ClientCode)
                    {
                        isRequest = true;
                        break;
                    }
                }

                if (!isRequest)
                {
                    NJ4XConnectSocket.MQLCommand newMQLCommand = new NJ4XConnectSocket.MQLCommand();
                    newMQLCommand.ClientCode = objCommand.ClientCode;
                    newMQLCommand.InvestorCode = Command.Investor.Code;
                    newMQLCommand.IpAddress = objCommand.IpAddress;

                    Business.Market.marketInstance.MQLCommands.Add(newMQLCommand);
                }
            }

            #region CHECK VOLUME < 0
            //if (objCommand.Size < 0)
            //{
            //    //Add Result To Client Command Queue Of Investor
            //    string Message = "CloseCommand$False,INVALID VOLUME.," + Command.ID + "," + Command.Investor.InvestorID + "," +
            //            Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," +
            //            Command.StopLoss + "," + Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," +
            //            Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + "BuySpotCommand" + "," + 1 + "," +
            //            Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," +
            //            Command.Margin + ",Open," + DateTime.Now;

            //    if (Command.Investor.ClientCommandQueue == null)
            //        Command.Investor.ClientCommandQueue = new List<string>();

            //    Command.Investor.ClientCommandQueue.Add(Message);

            //    Result.isDeal = false;
            //    Result.Error = "INVALID VOLUME.";
            //    Result.Command = objCommand;

            //    return Result;
            //}
            #endregion

            string size = TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Command.Size.ToString(), 2);
            string openPrice = TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Command.OpenPrice.ToString(), Command.Symbol.Digit);
            string takeProfit = TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Command.TakeProfit.ToString(), Command.Symbol.Digit);
            string stopLoss = TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Command.StopLoss.ToString(), Command.Symbol.Digit);
            string bid = TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Command.Symbol.TickValue.Bid.ToString(), Command.Symbol.Digit);
            string ask = TradingServer.Model.TradingCalculate.Instance.BuildStringWithDigit(Command.Symbol.TickValue.Ask.ToString(), Command.Symbol.Digit);

            string mode = string.Empty;
            string content = string.Empty;
            string comment = string.Empty;

            #region REND CONTENT SYSTEM LOG AND INSERT SYSTEM LOG
            switch (Command.Type.ID)
            {
                case 1:
                    {
                        content = "'" + Command.Investor.Code + "': close instant order #" + Command.CommandCode + " buy " + size + " " + Command.Symbol.Name + " at " + openPrice +
                            " sl: " + stopLoss + " tp: " + takeProfit + " (" + bid + "/" + ask + ")";
                        comment = "[close instant buy]";
                    }
                    break;
                case 2:
                    {
                        content = "'" + Command.Investor.Code + "': close instant order #" + Command.CommandCode + " sell " + size + " " + Command.Symbol.Name + " at " + openPrice +
                                " sl: " + stopLoss + " tp: " + takeProfit + " (" + bid + "/" + ask + ")";
                        comment = "[close instant sell]";
                    }
                    break;
                case 7:
                    {
                        content = "'" + Command.Investor.Code + "': close buy limit order #" + Command.CommandCode + " buy limit " + size + " " + Command.Symbol.Name + " at " + openPrice +
                                " sl: " + stopLoss + " tp: " + takeProfit + " (" + bid + "/" + ask + ")" + " exp " + Command.ExpTime;
                        comment = "[order buy limit]";
                    }
                    break;
                case 8:
                    {
                        content = "'" + Command.Investor.Code + "': close sell limit order #" + Command.CommandCode + " sell limit " + size + " " + Command.Symbol.Name + " at " + openPrice +
                                " sl: " + stopLoss + " tp: " + takeProfit + " (" + bid + "/" + ask + ")" + " exp " + Command.ExpTime;
                        comment = "[order sell limit]";
                    }
                    break;
                case 9:
                    {
                        content = "'" + Command.Investor.Code + "': close buy stop order #" + Command.CommandCode + " buy stop " + size + " " + Command.Symbol.Name + " at " + openPrice +
                            " sl: " + stopLoss + " tp: " + takeProfit + " (" + bid + "/" + ask + ")" + " exp " + Command.ExpTime;
                        comment = "[order buy stop]";
                    }
                    break;
                case 10:
                    {
                        content = "'" + Command.Investor.Code + "': close sell stop order #" + Command.CommandCode + " sell stop " + size + " " + Command.Symbol.Name + " at " + openPrice +
                            " sl: " + stopLoss + " tp: " + takeProfit + " (" + bid + "/" + ask + ")" + " exp " + Command.ExpTime;
                        comment = "[order sell stop]";
                    }
                    break;
                case 11:
                    {
                        content = "'" + Command.Investor.Code + "': close future order #" + Command.CommandCode + " future buy " + size + " " + Command.Symbol.Name + " at " + openPrice +
                                " sl: " + stopLoss + " tp: " + takeProfit + " (" + bid + "/" + ask + ")" + " exp " + Command.ExpTime;
                        comment = "[future buy]";
                    }
                    break;
                case 12:
                    {
                        content = "'" + Command.Investor.Code + "': close future order #" + Command.CommandCode + " future sell " + size + " " + Command.Symbol.Name + " at " + openPrice +
                                " sl: " + stopLoss + " tp: " + takeProfit + " (" + bid + "/" + ask + ")" + " exp " + Command.ExpTime;
                        comment = "[future sell]";
                    }
                    break;
            }

            if (!isRequest)
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, comment, objCommand.IpAddress, Command.Investor.Code);
            #endregion

            #region CHECK INVESTOR ONLINE(CHECK ACCOUNT IS PRIMARY)
            bool _checkOnline = TradingServer.Business.Investor.investorInstance.CheckPrimaryInvestorOnline(objCommand.InvestorID, TradingServer.Business.TypeLogin.Primary, objCommand.LoginKey);
            if (!_checkOnline)
            {
                Result.isDeal = false;
                Result.Command = objCommand;
                Result.Error = "ACCOUNT READ ONLY";

                string message = "AddCommand$False,ACCOUNT READ ONLY," + Command.ID + "," + Command.Investor.InvestorID + "," + Command.Symbol.Name + "," +
                            Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," + Command.TakeProfit + "," +
                            Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + Command.Type.Name + "," +
                            1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + Command.CommandCode + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Close," +
                            DateTime.Now;

                Command.Investor.ClientCommandQueue.Add(message);

                if (Command.Investor.IsOnline == false)
                {
                    Business.Investor.investorInstance.SendCommandToInvestorOnline(Command.Investor.InvestorID, Business.TypeLogin.ReadOnly, message);
                }

                #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                content = content + " unsuccessful [account read only]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[account read only]", objCommand.IpAddress, Command.Investor.Code);
                #endregion

                return Result;
            }
            #endregion

            #region CHECK MANUAL DEALERS OR AUTOMATIC
            string executionType = Business.Market.marketInstance.GetExecutionType(Command.IGroupSecurity, "B03");

            if (executionType == "manual only- no automation" ||
                executionType == "manual- but automatic if no dealer online" ||
                executionType == "automatic only")
            {
                Command.ClosePrice = objCommand.ClosePrice;
                if (objCommand.Size > 0)
                    Command.Size = objCommand.Size;

                Command.Symbol.MarketAreaRef.CloseCommand(Command);
                Result.Command = objCommand;
                Result.isDeal = true;
                return Result;
            }
            #endregion

            //==============================================================================================================================================================

            if (Command == null)
            {
                TradingServer.Facade.FacadeAddNewSystemLog(1, "command is empty" + objCommand.CommandID, "Check Null Close Command", "", "");
                return Result;
            }

            if (Command.Investor == null || Command.Symbol == null || Command.Type == null || Command.IGroupSecurity == null)
            {
                TradingServer.Facade.FacadeAddNewSystemLog(1, "symbol investor or type command empty" + objCommand.CommandID, "Check Null Close Command", "", "");
                return null;
            }

            #region CHECK SYMBOL ON HOLD
            if (!Command.Symbol.CheckTimeTick())
            {
                if (Command.Investor != null)
                {
                    //Add Result To Client Command Queue Of Investor
                    string Message = "CloseCommand$False,MARKET ON HOLD," + Command.ID + "," + Command.Investor.InvestorID + "," +
                            Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," +
                            Command.StopLoss + "," + Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," +
                            Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + "BuySpotCommand" + "," + 1 + "," +
                            Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," +
                            Command.Margin + ",Open," + DateTime.Now;

                    if (Command.Investor.ClientCommandQueue == null)
                        Command.Investor.ClientCommandQueue = new List<string>();

                    Command.Investor.ClientCommandQueue.Add(Message);
                }

                Result.isDeal = false;
                Result.Error = "MARKET ON HOLD";
                Result.Command = objCommand;

                #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                string tempContent = "close command";
                tempContent = tempContent + " unsuccessful [symbol on hold]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, tempContent, "[symbol on hold]", objCommand.IpAddress, Command.Investor.Code);
                #endregion

                return Result;
            }
            #endregion

            Command.Investor.IpAddress = objCommand.IpAddress;
            #endregion

            #region CALCULATION LOTS OF COMMAND(08/07/2011)
            if (objCommand.Size > 0)
            {
                if (objCommand.Size > Command.Size)
                {
                    //Business.Market.SendNotifyToClient("CMD2343344", 3, Command.Investor.InvestorID);

                    if (Command.Investor != null)
                    {
                        //Add Result To Client Command Queue Of Investor
                        string Message = "CloseCommand$False,INVALID LOTS," + Command.ID + "," + Command.Investor.InvestorID + "," +
                                Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," +
                                Command.StopLoss + "," + Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," +
                                Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + "BuySpotCommand" + "," + 1 + "," +
                                Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," +
                                Command.Margin + ",Open," + DateTime.Now;

                        if (Command.Investor.ClientCommandQueue == null)
                            Command.Investor.ClientCommandQueue = new List<string>();

                        Command.Investor.ClientCommandQueue.Add(Message);
                    }

                    Result.isDeal = false;
                    Result.Command = objCommand;
                    Result.Error = "INVALID LOTS";

                    return Result;
                }
                else
                {
                    Command.Size = objCommand.Size;
                }
            }
            #endregion

            #region CHECK IPADDRESS
            bool checkIP = TradingServer.Business.ValidIPAddress.Instance.ValidIpAddress(Command.Investor.InvestorID, objCommand.IpAddress);
            if (!checkIP)
            {
                Result.isDeal = false;
                Result.Command = objCommand;
                Result.Error = "INVALID IP ADDRESS";

                #region INSERT LOG
                content = content + " unsuccessful [invalid ip address]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[invalid ip address]", objCommand.IpAddress, Command.Investor.Code);
                #endregion

                string message = "CloseCommand$False,INVALID IP ADDRESS," + Command.ID + "," + Command.Investor.InvestorID + "," + Command.Symbol.Name + "," +
                            Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," + Command.TakeProfit + "," +
                            Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + Command.Type.Name + "," +
                            1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + Command.CommandCode + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Close," +
                            DateTime.Now;

                Command.Investor.ClientCommandQueue.Add(message);

                return Result;
            }
            #endregion

            bool isOnline = TradingServer.Business.Investor.investorInstance.CheckInvestorOnline(objCommand.InvestorID, objCommand.LoginKey);
            if (!isOnline)
            {
                //ADD INVESTOR TO LIST ONLINE IF CLIENT TIMEOUT
                TradingServer.Business.Investor.investorInstance.CheckOnlineInvestor(objCommand.InvestorID, objCommand.LoginKey);
            }

            #region CHECK INVESTOR ONLINE(CHECK READ ONLY)
            bool checkOnline = TradingServer.Business.Investor.investorInstance.CheckPrimaryInvestorOnline(Command.Investor.InvestorID, TradingServer.Business.TypeLogin.Primary, objCommand.LoginKey);
            if (!checkOnline)
            {
                Result.isDeal = false;
                Result.Command = objCommand;
                Result.Error = "ACCOUNT READ ONLY";

                #region INSERT LOG
                content = content + " unsuccessful [account read only]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[account read only]", objCommand.IpAddress, Command.Investor.Code);
                #endregion

                string message = "CloseCommand$False,ACCOUNT READ ONLY," + Command.ID + "," + Command.Investor.InvestorID + "," + Command.Symbol.Name + "," +
                            Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," + Command.TakeProfit + "," +
                            Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + Command.Type.Name + "," +
                            1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + Command.CommandCode + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Close," +
                            DateTime.Now;

                Command.Investor.ClientCommandQueue.Add(message);

                return Result;
            }
            #endregion

            #region CHECK INVESTOR LOGIN WITH PASSWORD READ ONLY
            if (Command.Investor.IsReadOnly)
            {
                string Message = "CloseCommand$False,TRADE IS DISABLED," + Command.ID + "," + Command.Investor.InvestorID + "," + Command.Symbol.Name + "," +
                            Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," + Command.TakeProfit + "," +
                            Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + Command.Type.Name + "," +
                            1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + Command.CommandCode + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Close," +
                            DateTime.Now;

                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();

                Command.Investor.ClientCommandQueue.Add(Message);

                Result.isDeal = false;
                Result.Error = "TRADE IS DISABLED";
                Result.Command = objCommand;

                content = content + " unsuccessful [login password read only]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[login password read only]", objCommand.IpAddress, Command.Investor.Code);

                return Result;
            }
            #endregion

            #region CHECK SYMBOL EXISTS IN SECURITY
            bool isExists = Business.Market.marketInstance.IsExistsSymbolInSecurity(Command);
            if (!isExists)
            {
                //Add Result To Client Command Queue Of Investor
                string Message = "AddCommand$False,ACTION NOT ALLOW," + Command.ID + "," + Command.Investor.InvestorID + "," +
                        Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                            Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                            "Open" + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin + ",Open";

                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();

                Command.Investor.ClientCommandQueue.Add(Message);

                Result.isDeal = false;
                Result.Error = "ACTION NOT ALLOW";
                Result.Command = objCommand;

                #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                content = content + " unsuccessful [symbol don't exits in security]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[symbol don't exits in security]", objCommand.IpAddress, Command.Investor.Code);
                #endregion

                return Result;
            }
            #endregion

            #region CHECK TIME MARKET
            if (!Business.Market.IsOpen)
            {
                string Message = "CloseCommand$False,MARKET IS CLOSE," + Command.ID + "," + Command.Investor.InvestorID + "," +
                            Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," +
                            Command.StopLoss + "," + Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," +
                            Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + "BuySpotCommand" + "," + 1 + "," +
                            Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," +
                            Command.Margin + ",Open," + DateTime.Now;

                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();

                Command.Investor.ClientCommandQueue.Add(Message);

                Result.isDeal = false;
                Result.Error = "MARKET IS CLOSE";
                Result.Command = objCommand;

                #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                content = content + " unsuccessful [market is close]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[market is close]", objCommand.IpAddress, Command.Investor.Code);
                #endregion

                return Result;
            }
            #endregion

            #region CHECK IS TRADE OF SYMBOL
            if (!Command.Symbol.IsTrade)
            {
                string Message = "CloseCommand$False,SYMBOL IS CLOSE," + Command.ID + "," + Command.Investor.InvestorID + "," +
                                Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," +
                                Command.StopLoss + "," + Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," +
                                Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + "BuySpotCommand" + "," + 1 + "," +
                                Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," +
                                Command.Margin + ",Open," + DateTime.Now;

                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();

                Command.Investor.ClientCommandQueue.Add(Message);

                Result.isDeal = false;
                Result.Error = "SYMBOL IS CLOSE";
                Result.Command = objCommand;

                content = content + " unsuccessful [symbol is close]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[symbol is close]", objCommand.IpAddress, Command.Investor.Code);

                return Result;
            }
            #endregion

            #region CHECK HOLIDAY OF SERVER
            if (Command.Symbol.IsHoliday)
            {
                string Message = "CloseCommand$False,MARKET IS HOLIDAY," + Command.ID + "," + Command.Investor.InvestorID + "," +
                               Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," +
                               Command.StopLoss + "," + Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," +
                               Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + Command.Type.Name + "," + 1 + "," +
                               Command.ExpTime + "," + Command.ClientCode + "," + "0000000," + Command.IsHedged + "," + Command.Type.ID + "," +
                               Command.Margin + ",Open," + DateTime.Now;

                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();

                Command.Investor.ClientCommandQueue.Add(Message);

                Result.isDeal = false;
                Result.Error = "MARKET IS HOLIDAY";
                Result.Command = objCommand;

                content = content + " unsuccessful [market is holiday]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[market is holiday]", objCommand.IpAddress, Command.Investor.Code);

                return Result;
            }
            #endregion

            #region Get Setting IsTrade In Group
            bool IsTradeGroup = false;
            if (Business.Market.InvestorGroupList != null)
            {
                int count = Business.Market.InvestorGroupList.Count;
                for (int i = 0; i < count; i++)
                {
                    if (Business.Market.InvestorGroupList[i].InvestorGroupID == Command.Investor.InvestorGroupInstance.InvestorGroupID)
                    {
                        if (Business.Market.InvestorGroupList[i].ParameterItems != null)
                        {
                            int countParameter = Business.Market.InvestorGroupList[i].ParameterItems.Count;
                            for (int j = 0; j < countParameter; j++)
                            {
                                if (Business.Market.InvestorGroupList[i].ParameterItems[j].Code == "G01")
                                {
                                    if (Business.Market.InvestorGroupList[i].ParameterItems[j].BoolValue == 1)
                                        IsTradeGroup = true;

                                    break;
                                }
                            }
                        }
                        break;
                    }
                }
            }
            #endregion

            #region CHECK IN TRADE IN GROUP
            if (!IsTradeGroup)
            {
                string Message = "CloseCommand$False,GROUP IS DISABLED," + Command.ID + "," + Command.Investor.InvestorID + "," + Command.Symbol.Name + "," +
                                    Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," + Command.TakeProfit + "," +
                                    Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + Command.Type.Name + "," +
                                    1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + Command.CommandCode + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin +
                                    ",Close," + DateTime.Now;

                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();

                Command.Investor.ClientCommandQueue.Add(Message);

                Result.isDeal = false;
                Result.Error = "GROUP IS DISABLED";
                Result.Command = objCommand;

                content = content + " unsuccessful [group is disable]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[group is disable]", objCommand.IpAddress, Command.Investor.Code);

                return Result;
            }
            #endregion

            if (Command.Investor != null)
            {
                #region CHECK ISDISABLE OF INVESTOR
                if (Command.Investor.IsDisable)
                {
                    string Message = "CloseCommand$False,ACCOUNT IS DISABLED," + Command.ID + "," + Command.Investor.InvestorID + "," + Command.Symbol.Name + "," +
                                Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," + Command.TakeProfit + "," +
                                Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + Command.Type.Name + "," +
                                1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + Command.CommandCode + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin +
                                ",Close," + DateTime.Now;

                    if (Command.Investor.ClientCommandQueue == null)
                        Command.Investor.ClientCommandQueue = new List<string>();

                    Command.Investor.ClientCommandQueue.Add(Message);

                    Result.isDeal = false;
                    Result.Error = "ACCOUNT IS DISABLED";
                    Result.Command = objCommand;

                    content = content + " unsuccessful [account is disable]";
                    TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[account is disable]", objCommand.IpAddress, Command.Investor.Code);

                    return Result;
                }
                #endregion

                #region CHECK READ ONLY OF INVESTOR
                if (Command.Investor.ReadOnly)
                {
                    string Message = "CloseCommand$False,TRADE IS DISABLED," + Command.ID + "," + Command.Investor.InvestorID + "," + Command.Symbol.Name + "," +
                            Command.Size + "," + false + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," + Command.TakeProfit + "," +
                            Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + Command.Type.Name + "," +
                            1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + Command.CommandCode + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin +
                            ",Close," + DateTime.Now;

                    if (Command.Investor.ClientCommandQueue == null)
                        Command.Investor.ClientCommandQueue = new List<string>();

                    Command.Investor.ClientCommandQueue.Add(Message);

                    Result.isDeal = false;
                    Result.Error = "TRADE IS DISABLED";
                    Result.Command = objCommand;

                    content = content + " unsuccessful [account read only]";
                    TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[account read only]", objCommand.IpAddress, Command.Investor.Code);

                    return Result;
                }

                #endregion
            }

            #region CHECK MIN MAX AND STEP LOTS
            double Minimum = -1;
            double Maximum = -1;
            double Step = -1;
            bool ResultCheckStepLots = false;

            #region Get Config IGroupSecurity
            if (Command.IGroupSecurity.IGroupSecurityConfig != null)
            {
                int countIGroupSecurityConfig = Command.IGroupSecurity.IGroupSecurityConfig.Count;
                for (int i = 0; i < countIGroupSecurityConfig; i++)
                {
                    if (Command.IGroupSecurity.IGroupSecurityConfig[i].Code == "B11")
                    {
                        double.TryParse(Command.IGroupSecurity.IGroupSecurityConfig[i].NumValue, out Minimum);
                    }

                    if (Command.IGroupSecurity.IGroupSecurityConfig[i].Code == "B12")
                    {
                        double.TryParse(Command.IGroupSecurity.IGroupSecurityConfig[i].NumValue, out Maximum);
                    }

                    if (Command.IGroupSecurity.IGroupSecurityConfig[i].Code == "B13")
                    {
                        double.TryParse(Command.IGroupSecurity.IGroupSecurityConfig[i].NumValue, out Step);
                    }
                }
            }
            #endregion

            ResultCheckStepLots = Command.IGroupSecurity.CheckStepLots(Minimum, Maximum, Step, Command.Size);

            #region If Check Step Lots False Return Client
            if (ResultCheckStepLots == false)
            {
                string Message = "CloseCommand$False,WRONG VOLUME MINIMUM : " + Minimum + " LOT " + "MAXIMUM " + Maximum + " LOT," + Command.ID + "," +
                                    Command.Investor.InvestorID + "," + Command.Symbol.Name + "," + Command.Size + "," + false + "," + Command.OpenTime + "," +
                                    Command.OpenPrice + "," + Command.StopLoss + "," + Command.TakeProfit + "," + Command.ClosePrice + "," +
                                    Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," + Command.Type.Name + "," +
                                    1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + Command.CommandCode + "," + Command.IsHedged + "," + Command.Type.ID +
                                    "," + Command.Margin + ",Close," + DateTime.Now;

                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();

                Command.Investor.ClientCommandQueue.Add(Message);

                Result.isDeal = false;
                Result.Error = "WRONG VOLUME";
                Result.Command = objCommand;

                #region INSERT SYSTEM LOG EVENT MAKE COMMAND
                content = content + " unsuccessful [wrong volume minimum]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[wrong volume minimum]", objCommand.IpAddress, Command.Investor.Code);
                #endregion

                return Result;
            }   //END IF CHECK STEP LOTS OF SYMBOL
            #endregion
            #endregion

            //SET ISSERVER = FALSE
            Command.IsServer = false;

            //Set Close Price Command
            Command.ClosePrice = objCommand.ClosePrice;

            //set close time
            Command.CloseTime = DateTime.Now;

            //set ipaddress to investor
            Command.Investor.IpAddress = objCommand.IpAddress;

            #region Check Status Trade Of Symbol(Full Access,Close Only, No)
            if (Command.Symbol.Trade == "No")
            {
                bool IsBuy = false;
                if (Command.Type.ID == 1 || Command.Type.ID == 7 || Command.Type.ID == 9 || Command.Type.ID == 11)
                    IsBuy = true;

                string Message = "CloseCommand$False,ACTION NOT ALLOWED," + Command.ID + "," + Command.Investor.InvestorID + "," +
                        Command.Symbol.Name + "," + Command.Size + "," + IsBuy + "," + Command.OpenTime + "," + Command.OpenPrice + "," +
                        Command.StopLoss + "," + Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," +
                        Command.Profit + "," + "Comment," + Command.ID + "," + Command.Type.Name + "," + 1 + "," + Command.ExpTime + "," +
                        Command.ClientCode + "," + Command.CommandCode + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin +
                        ",Close," + DateTime.Now;

                if (Command.Investor.ClientCommandQueue == null)
                    Command.Investor.ClientCommandQueue = new List<string>();

                Command.Investor.ClientCommandQueue.Add(Message);

                Result.isDeal = false;
                Result.Error = "ACTION NOT ALLOWED";

                content = content + " unsuccessful [status trade no]";
                TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[status trade no]", objCommand.IpAddress, Command.Investor.Code);

                return Result;
            }
            #endregion

            if (Command.Symbol != null && Command.Investor != null && Command.Type != null && Command.IGroupSecurity != null)
            {
                if (Command.Type.ID == 1 || Command.Type.ID == 2 || Command.Type.ID == 11 || Command.Type.ID == 12)
                {
                    //Call Dealer
                    Business.RequestDealer newRequestDealer = new Business.RequestDealer();
                    newRequestDealer.InvestorID = Command.Investor.InvestorID;
                    newRequestDealer.MaxDev = Command.MaxDev;
                    newRequestDealer.Name = "Close";
                    newRequestDealer.Request = Command;
                    newRequestDealer.TimeClientRequest = DateTime.Now;

                    TradingServer.Facade.FacadeSendRequestToDealer(newRequestDealer);
                }
                else
                {
                    //Call Dealer
                    //Business.RequestDealer newRequestDealer = new Business.RequestDealer();
                    //newRequestDealer.InvestorID = Command.Investor.InvestorID;
                    //newRequestDealer.MaxDev = Command.MaxDev;
                    //newRequestDealer.Name = "ClosePending";
                    //newRequestDealer.Request = Command;
                    //newRequestDealer.TimeClientRequest = DateTime.Now;

                    //TradingServer.Facade.FacadeSendRequestToDealer(newRequestDealer);

                    Command.Symbol.MarketAreaRef.CloseCommand(Command);
                }

                Result.isDeal = true;
                Result.Error = "Close Command Complete" + Command.Symbol.MarketAreaRef.IMarketAreaName;
                return Result;
            }
            else
            {
                #region COMMENT CODE(DAY: 15 MONTH : 06 YEAR 2011
                //Command = TradingServer.Facade.FacadeFindOpenTradeInInvestorList(objCommand.CommandID);

                ////Set Close Command
                //Command.ClosePrice = objCommand.ClosePrice;

                //#region Check Status Trade Of Symbol(Full Access,Close Only, No)
                //if (Command.Symbol.Trade == "No")
                //{
                //    bool IsBuy = false;
                //    if (Command.Type.ID == 1 || Command.Type.ID == 7 || Command.Type.ID == 9 || Command.Type.ID == 11)
                //        IsBuy = true;

                //    string Message = "CloseCommand$False,ACTION NOT ALLOWED," + Command.ID + "," + Command.Investor.InvestorID + "," +
                //            Command.Symbol.Name + "," + Command.Size + "," + IsBuy + "," + Command.OpenTime + "," + Command.OpenPrice + "," + Command.StopLoss + "," +
                //                Command.TakeProfit + "," + Command.ClosePrice + "," + Command.Commission + "," + Command.Swap + "," + Command.Profit + "," + "Comment," + Command.ID + "," +
                //                Command.Type.Name + "," + 1 + "," + Command.ExpTime + "," + Command.ClientCode + "," + Command.CommandCode + "," + Command.IsHedged + "," + Command.Type.ID + "," + Command.Margin +
                //                ",Close," + DateTime.Now;

                //    if (Command.Investor.ClientCommandQueue == null)
                //        Command.Investor.ClientCommandQueue = new List<string>();

                //    Command.Investor.ClientCommandQueue.Add(Message);

                //    Result.isDeal = false;
                //    Result.Error = "ACTION NOT ALLOWED";

                //    content = content + " [unsuccessful]";
                //    TradingServer.Facade.FacadeAddNewSystemLog(5, content, "[status trade no]", objCommand.IpAddress, Command.Investor.Code);

                //    return Result;
                //}
                //#endregion

                //if (Command.Symbol != null && Command.Investor != null && Command.Type != null && Command.IGroupSecurity != null)
                //{
                //    if (Command.Type.ID == 1 || Command.Type.ID == 2 || Command.Type.ID == 11 || Command.Type.ID == 12)
                //    {
                //        //Call Dealer
                //        Business.RequestDealer newRequestDealer = new Business.RequestDealer();
                //        newRequestDealer.InvestorID = Command.Investor.InvestorID;
                //        newRequestDealer.MaxDev = Command.MaxDev;
                //        newRequestDealer.Name = "Close";
                //        newRequestDealer.Request = Command;
                //        newRequestDealer.TimeClientRequest = DateTime.Now;

                //        TradingServer.Facade.FacadeSendRequestToDealer(newRequestDealer);
                //    }
                //    else
                //    {
                //        Command.Symbol.MarketAreaRef.CloseCommand(Command);
                //    }

                //    //Command.Symbol.MarketAreaRef.CloseCommand(Command);
                //    Result.isDeal = true;
                //    Result.Error = "Close Command Of Investor Complete " + Command.Symbol.MarketAreaRef.IMarketAreaName;

                //    return Result;
                //}
                //else
                //{
                //    if (Command.Investor != null)
                //    {
                //        //Add Result To Client Command Queue Of Investor
                //        string Message = "CloseCommand$False,Can't Find Symbol Investor Or Type Command," + "0" + "," + "-1" + "," +
                //                "NaN" + "," + "-1" + "," + false + "," + DateTime.Now + "," + "-1" + "," + "-1" + "," +
                //                    "-1" + "," + "-1" + "," + "-1" + "," + "-1" + "," + "-1" + "," + "Comment," + "-1" + "," +
                //                    "Open" + "," + 1 + "," + DateTime.Now + "," + "-1" + "," + "0000000," + false + "," + "0" + "," + "0" + ",Open," + DateTime.Now;

                //        if (Command.Investor.ClientCommandQueue == null)
                //            Command.Investor.ClientCommandQueue = new List<string>();

                //        Command.Investor.ClientCommandQueue.Add(Message);
                //    }

                //    Result.isDeal = false;
                //    Result.Error = "Can't Find Symbol Investor Or Type Command";

                //    return Result;
                //}
                #endregion

                content = "some one info empty(symbol, investor ,type, or igroupsecurity)";
                TradingServer.Facade.FacadeAddNewSystemLog(1, content, "[info empty]", objCommand.IpAddress, Command.Investor.Code);
            }

            return Result;
        }