/// <summary>
        /// ADD NEW MARKET CONFIG
        /// </summary>
        /// <param name="CollectionValue"></param>
        /// <param name="Name"></param>
        /// <param name="Code"></param>
        /// <param name="BoolValue"></param>
        /// <param name="StringValue"></param>
        /// <param name="NumValue"></param>
        /// <param name="DateValue"></param>
        /// <returns></returns>
        internal int AddNewMarketConfig(int CollectionValue, string Name, string Code, int BoolValue,
                                            string StringValue, string NumValue, DateTime DateValue)
        {
            int Result = -1;

            Business.ParameterItem newParameter = new ParameterItem();
            newParameter.BoolValue = BoolValue;
            newParameter.Code = Code;
            newParameter.CollectionValue = new List<ParameterItem>();
            newParameter.DateValue = DateValue;
            newParameter.Name = Name;
            newParameter.NumValue = NumValue;
            newParameter.StringValue = StringValue;

            Result = ParameterItem.DBWMarketConfig.AddNewMarketConfig(CollectionValue, Name, Code, BoolValue, StringValue, NumValue, DateValue);

            newParameter.ParameterItemID = Result;

            if (Result > 0)
            {
                if (Business.Market.MarketConfig != null)
                {
                    Business.Market.MarketConfig.Add(newParameter);
                }
                else
                {
                    Business.Market.MarketConfig = new List<ParameterItem>();
                    Business.Market.MarketConfig.Add(newParameter);
                }

                if (Code == "C34")
                {
                    string[] subValue = StringValue.Split('`');
                    if (subValue.Length == 2)
                    {
                        Business.GroupDefault newGroupDefault = new GroupDefault();
                        newGroupDefault.DomainName = subValue[0];
                        newGroupDefault.GroupDefaultName = subValue[1];
                        newGroupDefault.GroupDefaultID = Result;

                        Business.Market.ListGroupDefault.Add(newGroupDefault);
                    }

                    return Result;
                }
            }

            Business.Market.marketInstance.InitTimeEventInSymbol();

            Business.Market.marketInstance.InitTimeEventServer();

            return Result;
        }
        /// <summary>
        /// Extract String Command To List Parameter Object
        /// </summary>
        /// <param name="Cmd">String Cmd</param>
        /// <returns>List<Business.ParameterItem></returns>
        internal List<Business.ParameterItem> ExtractParameterItemOne(string Cmd)
        {
            List<Business.ParameterItem> Result = new List<ParameterItem>();
            if (!string.IsNullOrEmpty(Cmd))
            {
                string[] subParameter = Cmd.Split('|');
                if (subParameter.Length > 0)
                {
                    int count = subParameter.Length;
                    for (int i = 0; i < count; i++)
                    {
                        string[] subList = subParameter[i].Split(',');
                        if (subList.Length > 0)
                        {
                            int secondParameterId = 0;
                            int collectionValue = 0;
                            int boolValue = 0;
                            DateTime dateValue = new DateTime();

                            Business.ParameterItem newParameterItem = new ParameterItem();
                            int.TryParse(subList[0], out secondParameterId);
                            int.TryParse(subList[1], out collectionValue);
                            int.TryParse(subList[4], out boolValue);
                            DateTime.TryParse(subList[7], out dateValue);

                            newParameterItem.ParameterItemID = secondParameterId;
                            newParameterItem.SecondParameterID = secondParameterId;
                            newParameterItem.CollectionValue = new List<ParameterItem>();
                            newParameterItem.Name = subList[2];
                            newParameterItem.Code = subList[3];
                            newParameterItem.BoolValue = boolValue;
                            newParameterItem.StringValue = subList[5];
                            newParameterItem.NumValue = subList[6];
                            newParameterItem.DateValue = dateValue;

                            Result.Add(newParameterItem);
                        }
                    }
                }
            }

            return Result;
        }
        /// <summary>
        /// GetAllSymbol$symbol{source{digits{description{typeSecurity{tradeMode{margin_currency{instant_max_volume{
        /// gtc_pendings{spread{long_only{stops_level{spread_balance{freeze_level{contract_size{margin_initial{
        /// margin_maintenance{margin_hedged{tick_size{tick_value{margin_mode{profit_mode{margin_hedged_strong{realtime{
        /// starting{expiration{open_hour[open_min[close_hour[close_min]|open_hour[open_min[close_hour[close_min]^
        /// open_hour[open_min[close_hour[close_min]|open_hour[open_min[close_hour[close_min]^
        /// 
        /// </summary>
        /// <param name="value"></param>
        public void ReceiveSymbolNotify(List<string> value)
        {
            if (value != null)
            {
                Business.Market.SymbolList = new List<Symbol>();
                int count = value.Count;
                for (int i = 0; i < count; i++)
                {
                    if (!string.IsNullOrEmpty(value[i]))
                    {
                        string[] subValue = value[i].Split('{');
                        Business.Symbol newSymbol = new Symbol();
                        newSymbol.MarketAreaRef = Business.Market.MarketArea[0];
                        if (Business.Market.SecurityList != null)
                        {
                            int countSecurity = Business.Market.SecurityList.Count;
                            for (int j = 0; j < countSecurity; j++)
                            {
                                if (Business.Market.SecurityList[j].SecurityID == int.Parse(subValue[4]))
                                {
                                    newSymbol.SecurityID = Business.Market.SecurityList[j].SecurityID;
                                    break;
                                }
                            }
                        }

                        newSymbol.Name = subValue[0];
                        newSymbol.IsQuote = true;
                        newSymbol.IsTrade = true;
                        newSymbol.TimeOnHold = 500000;
                        //source
                        newSymbol.Digit = int.Parse(subValue[2]);
                        //description
                        //type
                        //execution_mode
                        EnumMT4.Execution enuExecutionTrade = (EnumMT4.Execution)(Enum.Parse(typeof(EnumMT4.Execution), subValue[5]));
                        newSymbol.ExecutionTrade = enuExecutionTrade;

                        newSymbol.Currency = subValue[6];

                        EnumMT4.Trade enuTrade = (EnumMT4.Trade)(Enum.Parse(typeof(EnumMT4.Trade), subValue[7]));
                        switch (enuTrade)
                        {
                            case EnumMT4.Trade.CLOSE_ONLY:
                                newSymbol.Trade = "Close Only";
                                break;

                            case EnumMT4.Trade.FULL_ACCESS:
                                newSymbol.Trade = "Full Access";
                                break;

                            case EnumMT4.Trade.NO:
                                newSymbol.Trade = "No";
                                break;
                        }

                        //newSymbol.Trade = subValue[7];
                        //margin_currency
                        //instant_max_volume
                        //gtc_pendings
                        newSymbol.SpreadByDefault = double.Parse(subValue[11]);
                        int _isLongOnly = int.Parse(subValue[12]);
                        if (_isLongOnly == 1)
                            newSymbol.LongOnly = true;
                        else
                            newSymbol.LongOnly = false;

                        newSymbol.StopLevel = int.Parse(subValue[13]);
                        newSymbol.SpreadBalace = double.Parse(subValue[14]) - 1;
                        newSymbol.FreezeLevel = int.Parse(subValue[15]);
                        newSymbol.ContractSize = double.Parse(subValue[16]);
                        newSymbol.InitialMargin = double.Parse(subValue[17]);
                        //margin_maintenance
                        newSymbol.MarginHedged = double.Parse(subValue[19]);
                        newSymbol.TickSize = double.Parse(subValue[20]);
                        newSymbol.TickPrice = double.Parse(subValue[21]);
                        //tick_value
                        //margin_mode

                        EnumMT4.ProfitCal enuProfitCal = (EnumMT4.ProfitCal)(Enum.Parse(typeof(EnumMT4.ProfitCal), subValue[23]));
                        switch (enuProfitCal)
                        {
                            case EnumMT4.ProfitCal.CFD:
                                newSymbol.ProfitCalculation = "CFD [ (close_price - open_price) * contract_size * lots ]";
                                break;

                            case EnumMT4.ProfitCal.FOREX:
                                newSymbol.ProfitCalculation = "Forex [ (close_price - open_price) * contract_size * lots ]";
                                break;

                            case EnumMT4.ProfitCal.FUTURES:
                                newSymbol.ProfitCalculation = "Futures [ (close_price - open_price) * tick_price / tick_size * lots ]";
                                break;
                        }
                        //margin_hedged_strong
                        //realtime
                        //starting
                        //expiration

                        newSymbol.TickValue = new Tick();
                        newSymbol.TickValue.Bid = 0;
                        newSymbol.TickValue.Ask = 0;
                        newSymbol.TickValue.SymbolName = newSymbol.Name;
                        newSymbol.TickValue.Status = "down";

                        newSymbol.ParameterItems = new List<ParameterItem>();

                        Business.ParameterItem newParameterItem = new ParameterItem();
                        newParameterItem.Code = "S004";
                        newParameterItem.BoolValue = -1;
                        newParameterItem.DateValue = DateTime.Parse("1753-01-01 00:00:00.000");
                        newParameterItem.Name = "Description";
                        newParameterItem.NumValue = "-1";
                        newParameterItem.SecondParameterID = i;
                        newParameterItem.StringValue = subValue[3];
                        newSymbol.ParameterItems.Add(newParameterItem);

                        newParameterItem = new ParameterItem();
                        newParameterItem.Code = "S006";
                        newParameterItem.BoolValue = -1;
                        newParameterItem.DateValue = DateTime.Parse("1753-01-01 00:00:00.000");
                        newParameterItem.Name = "Trade Execution";
                        newParameterItem.NumValue = subValue[5];
                        newParameterItem.SecondParameterID = i;
                        newParameterItem.StringValue = "NaN";
                        newSymbol.ParameterItems.Add(newParameterItem);

                        newParameterItem = new ParameterItem();
                        newParameterItem.Code = "S048";
                        newParameterItem.BoolValue = -1;
                        newParameterItem.DateValue = DateTime.Parse("1753-01-01 00:00:00.000");
                        newParameterItem.Name = "Start Digit";
                        newParameterItem.NumValue = "0";
                        newParameterItem.SecondParameterID = i;
                        newParameterItem.StringValue = "NaN";
                        newSymbol.ParameterItems.Add(newParameterItem);

                        newParameterItem = new ParameterItem();
                        newParameterItem.Code = "S049";
                        newParameterItem.BoolValue = -1;
                        newParameterItem.DateValue = DateTime.Parse("1753-01-01 00:00:00.000");
                        newParameterItem.Name = "End Digit";
                        newParameterItem.NumValue = "0";
                        newParameterItem.SecondParameterID = i;
                        newParameterItem.StringValue = "NaN";
                        newSymbol.ParameterItems.Add(newParameterItem);

                        newParameterItem = new ParameterItem();
                        newParameterItem.Code = "S054";
                        newParameterItem.BoolValue = -1;
                        newParameterItem.DateValue = DateTime.Parse("1753-01-01 00:00:00.000");
                        newParameterItem.Name = "Description";
                        newParameterItem.NumValue = "500000";
                        newParameterItem.SecondParameterID = i;
                        newParameterItem.StringValue = "NaN";
                        newSymbol.ParameterItems.Add(newParameterItem);

                        Business.Market.SymbolList.Add(newSymbol);

                        if (Business.Market.Symbols.ContainsKey(newSymbol.Name))
                            Business.Market.Symbols[newSymbol.Name] = newSymbol;
                        else
                            Business.Market.Symbols.Add(newSymbol.Name, newSymbol);

                        #region SESSION
                        string strSession = subValue[subValue.Length - 1];
                        string[] subSession = strSession.Split('^');
                        if (subSession.Length > 0)
                        {
                            int countSession = subSession.Length;
                            for (int j = 0; j < countSession; j++)
                            {
                                if (!string.IsNullOrEmpty(subSession[j]))
                                {
                                    string[] subQuoteTrade = subSession[j].Split('|');
                                    if (subQuoteTrade.Length > 0)
                                    {
                                        string[] subQuote = subQuoteTrade[0].Split(']');
                                        if (subQuote.Length > 0)
                                        {
                                            int countSubQuote = subQuote.Length;
                                            for (int n = 0; n < countSubQuote; n++)
                                            {
                                                if (!string.IsNullOrEmpty(subQuote[n]))
                                                {
                                                    string[] subQuotePara = subQuote[n].Split('[');
                                                    //OPEN_HOUR
                                                    //OPEN_MIN
                                                    //CLOSE_HOUR
                                                    //CLOSE_MIN
                                                }
                                            }
                                        }

                                        string[] subTrade = subQuoteTrade[1].Split(']');
                                        if (subTrade.Length > 0)
                                        {
                                            int countSubTrade = subTrade.Length;
                                            for (int n = 0; n < countSubTrade; n++)
                                            {
                                                if (!string.IsNullOrEmpty(subTrade[n]))
                                                {
                                                    string[] subTradePara = subTrade[n].Split('[');
                                                    //OPEN_HOUR
                                                    //OPEN_MIN
                                                    //CLOSE_HOUR
                                                    //CLOSE_MIN
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        #endregion
                    }
                }
            }

            if (Business.Market.IsFirstStart)
            {
                Business.Market.IsProcessNotifyTick = true;
                Business.Market.ThreadProcessNotifyTickMT4 = new System.Threading.Thread(new System.Threading.ThreadStart(ProcessNotifyTickMT4));
                Business.Market.ThreadProcessNotifyTickMT4.Start();

                Business.Market.IsFirstStart = false;
            }

            //this.LoopGetCandlesManagerAPI();

            Business.Market.IsOpen = true;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        public void ReceiveGroupNotify(List<string> value)
        {
            if (value != null)
            {
                Business.Market.InvestorGroupList = new List<InvestorGroup>();
                Business.Market.IGroupSecurityList = new List<IGroupSecurity>();
                int count = value.Count;
                for (int i = 0; i < count; i++)
                {
                    if (!string.IsNullOrEmpty(value[i]))
                    {
                        string[] subValue = value[i].Split('{');
                        if (subValue.Length > 0)
                        {
                            Business.InvestorGroup newGroup = new InvestorGroup();
                            newGroup.InvestorGroupID = i;
                            newGroup.Name = subValue[0];//Name
                            //company
                            newGroup.DefautDeposite = double.Parse(subValue[2]);//deposit
                            int _isEnable = int.Parse(subValue[3]);
                            if (_isEnable == 1)
                                newGroup.IsEnable = true;
                            else
                                newGroup.IsEnable = false;

                            // = bool.Parse(subValue[3]);//enable
                            newGroup.MarginCall = double.Parse(subValue[4]);//margincall
                            newGroup.MarginStopOut = double.Parse(subValue[5]);//margin_stopout
                            //default_leverage-G02
                            //interestrate-none
                            //timeout
                            //maxsecurities;
                            //maxpositions
                            //news
                            //support_email-G08
                            //use_swap
                            //hedge_prohibited
                            //close_fifo
                            //close_reopen
                            //archive_period
                            //archive_max_balance
                            //archive_pending_period
                            //margin_mode
                            //credit
                            //stoput_skip_hedged

                            newGroup.ParameterItems = new List<ParameterItem>();

                            ParameterItem newGroupConfig = new ParameterItem();
                            newGroupConfig.Code = "G01";
                            newGroupConfig.BoolValue = 1;
                            newGroupConfig.SecondParameterID = i;
                            newGroupConfig.Name = "Enable";
                            newGroupConfig.StringValue = "NaN";
                            newGroupConfig.NumValue = "NaN";
                            newGroupConfig.DateValue = DateTime.Parse("1753-01-01 00:00:00.000");
                            newGroup.ParameterItems.Add(newGroupConfig);

                            newGroupConfig = new ParameterItem();
                            newGroupConfig.Code = "G02";
                            newGroupConfig.BoolValue = -1;
                            newGroupConfig.SecondParameterID = i;
                            newGroupConfig.Name = "Default Leverag";
                            newGroupConfig.StringValue = "NaN";
                            newGroupConfig.NumValue = subValue[6];
                            newGroupConfig.DateValue = DateTime.Parse("1753-01-01 00:00:00.000");
                            newGroup.ParameterItems.Add(newGroupConfig);

                            newGroupConfig = new ParameterItem();
                            newGroupConfig.Code = "G04";
                            newGroupConfig.BoolValue = -1;
                            newGroupConfig.SecondParameterID = i;
                            newGroupConfig.Name = "TimeOut";
                            newGroupConfig.StringValue = "NaN";
                            newGroupConfig.NumValue = subValue[8];
                            newGroupConfig.DateValue = DateTime.Parse("1753-01-01 00:00:00.000");
                            newGroup.ParameterItems.Add(newGroupConfig);

                            newGroupConfig = new ParameterItem();
                            newGroupConfig.Code = "G19";
                            newGroupConfig.BoolValue = -1;
                            newGroupConfig.SecondParameterID = i;
                            newGroupConfig.Name = "Margin Call";
                            newGroupConfig.StringValue = "NaN";
                            newGroupConfig.NumValue = subValue[4];
                            newGroupConfig.DateValue = DateTime.Parse("1753-01-01 00:00:00.000");
                            newGroup.ParameterItems.Add(newGroupConfig);

                            newGroupConfig = new ParameterItem();
                            newGroupConfig.Code = "G20";
                            newGroupConfig.BoolValue = -1;
                            newGroupConfig.SecondParameterID = i;
                            newGroupConfig.Name = "StopOut";
                            newGroupConfig.StringValue = "NaN";
                            newGroupConfig.NumValue = subValue[5];
                            newGroupConfig.DateValue = DateTime.Parse("1753-01-01 00:00:00.000");
                            newGroup.ParameterItems.Add(newGroupConfig);

                            newGroupConfig = new ParameterItem();
                            newGroupConfig.Code = "G26";
                            newGroupConfig.BoolValue = -1;
                            newGroupConfig.SecondParameterID = i;
                            newGroupConfig.Name = "Margin Mode";
                            EnumMT4.MarginGroupCal enuFreeMargin = (EnumMT4.MarginGroupCal)Enum.Parse(typeof(EnumMT4.MarginGroupCal), subValue[20]);
                            switch (enuFreeMargin)
                            {
                                case EnumMT4.MarginGroupCal.DO_NOT_USE_UNREALIZED_PROFIT_LOSS:
                                    newGroupConfig.StringValue = "do not use unrealized profit/loss";
                                    break;

                                case EnumMT4.MarginGroupCal.USE_UNREALIZED_PROFIT_LOSS:
                                    newGroupConfig.StringValue = "use unrealized profit/loss";
                                    break;

                                case EnumMT4.MarginGroupCal.USE_UNREALIZED_LOSS_ONLY:
                                    newGroupConfig.StringValue = "use unrealized profit only";
                                    break;

                                case EnumMT4.MarginGroupCal.USE_UNREALIZED_PROFIT_ONLY:
                                    newGroupConfig.StringValue = "use unrealized loss only";
                                    break;
                            }

                            newGroupConfig.NumValue = "NaN";
                            newGroupConfig.DateValue = DateTime.Parse("1753-01-01 00:00:00.000");
                            newGroup.ParameterItems.Add(newGroupConfig);

                            newGroup.FreeMargin = newGroupConfig.StringValue;

                            Business.Market.InvestorGroupList.Add(newGroup);

                            #region IGROUPSECURITY
                            //IGROUPSECURITY
                            string strGroupSecurity = subValue[subValue.Length - 1];
                            string[] subGroupSecurity = strGroupSecurity.Split(']');
                            if (subGroupSecurity.Length > 0)
                            {
                                int countGroupSecurity = subGroupSecurity.Length;
                                for (int j = 0; j < countGroupSecurity; j++)
                                {
                                    if (!string.IsNullOrEmpty(subGroupSecurity[j]))
                                    {
                                        string[] subGroupSec = subGroupSecurity[j].Split('[');

                                        if (int.Parse(subGroupSec[0]) == 1)
                                        {
                                            Business.IGroupSecurity newIGroupSecurity = new IGroupSecurity();
                                            newIGroupSecurity.IGroupSecurityID = j;
                                            newIGroupSecurity.InvestorGroupID = newGroup.InvestorGroupID;
                                            newIGroupSecurity.SecurityID = j;
                                            newIGroupSecurity.IGroupSecurityConfig = new List<ParameterItem>();

                                            Business.ParameterItem newParameterItem = new ParameterItem();
                                            newParameterItem.Code = "B01";
                                            newParameterItem.BoolValue = int.Parse(subGroupSec[2]);
                                            newParameterItem.SecondParameterID = j;
                                            newParameterItem.Name = "Trade";
                                            newParameterItem.StringValue = "NaN";
                                            newParameterItem.NumValue = "NaN";
                                            newParameterItem.DateValue = DateTime.Parse("1753-01-01 00:00:00.000");
                                            newIGroupSecurity.IGroupSecurityConfig.Add(newParameterItem);

                                            newParameterItem = new ParameterItem();
                                            newParameterItem.Code = "B03";
                                            newParameterItem.BoolValue = -1;
                                            newParameterItem.SecondParameterID = j;
                                            newParameterItem.Name = "Execution";

                                            EnumMT4.IGroupSecurityExecution enuExecution = (EnumMT4.IGroupSecurityExecution)Enum.Parse(typeof(EnumMT4.IGroupSecurityExecution), subGroupSec[4]);
                                            switch (enuExecution)
                                            {
                                                case EnumMT4.IGroupSecurityExecution.AUTOMATIC_ONLY:
                                                    newParameterItem.StringValue = "automatic only";
                                                    break;

                                                case EnumMT4.IGroupSecurityExecution.MANUAL_BUT_AUTOMATIC_IF_NO_DEALERS_ONLINE:
                                                    newParameterItem.StringValue = "manual- but automatic if no dealer online";
                                                    break;

                                                case EnumMT4.IGroupSecurityExecution.MANUAL_ONLY_NO_AUTOMATIC:
                                                    newParameterItem.StringValue = "manual only- no automation";
                                                    break;
                                            }

                                            newParameterItem.NumValue = "NaN";
                                            newParameterItem.DateValue = DateTime.Parse("1753-01-01 00:00:00.000");
                                            newIGroupSecurity.IGroupSecurityConfig.Add(newParameterItem);

                                            newParameterItem = new ParameterItem();
                                            newParameterItem.Code = "B04";
                                            newParameterItem.BoolValue = -1;
                                            newParameterItem.SecondParameterID = j;
                                            newParameterItem.Name = "Spared Diffirence";
                                            newParameterItem.StringValue = "NaN";
                                            newParameterItem.NumValue = subGroupSec[5];
                                            newParameterItem.DateValue = DateTime.Parse("1753-01-01 00:00:00.000");
                                            newIGroupSecurity.IGroupSecurityConfig.Add(newParameterItem);

                                            newParameterItem = new ParameterItem();
                                            newParameterItem.Code = "B11";
                                            newParameterItem.BoolValue = -1;
                                            newParameterItem.SecondParameterID = j;
                                            newParameterItem.Name = "Lot Min";
                                            newParameterItem.StringValue = "NaN";
                                            double tempMin = double.Parse(subGroupSec[8]);
                                            tempMin = tempMin / 100;
                                            newParameterItem.NumValue = tempMin.ToString();
                                            newParameterItem.DateValue = DateTime.Parse("1753-01-01 00:00:00.000");
                                            newIGroupSecurity.IGroupSecurityConfig.Add(newParameterItem);

                                            newParameterItem = new ParameterItem();
                                            newParameterItem.Code = "B12";
                                            newParameterItem.BoolValue = -1;
                                            newParameterItem.SecondParameterID = j;
                                            newParameterItem.Name = "Lot Max";
                                            newParameterItem.StringValue = "NaN";
                                            double tempMax = double.Parse(subGroupSec[9]);
                                            tempMax = tempMax / 100;
                                            newParameterItem.NumValue = tempMax.ToString();
                                            newParameterItem.DateValue = DateTime.Parse("1753-01-01 00:00:00.000");
                                            newIGroupSecurity.IGroupSecurityConfig.Add(newParameterItem);

                                            newParameterItem = new ParameterItem();
                                            newParameterItem.Code = "B13";
                                            newParameterItem.BoolValue = -1;
                                            newParameterItem.SecondParameterID = j;
                                            newParameterItem.Name = "Step";
                                            newParameterItem.StringValue = "NaN";
                                            double tempStep = double.Parse(subGroupSec[10]);
                                            tempStep = tempStep / 100;
                                            newParameterItem.NumValue = tempStep.ToString();
                                            newParameterItem.DateValue = DateTime.Parse("1753-01-01 00:00:00.000");
                                            newIGroupSecurity.IGroupSecurityConfig.Add(newParameterItem);

                                            Business.Market.IGroupSecurityList.Add(newIGroupSecurity);
                                            //trade_rights
                                            //trade
                                            //confirmation
                                            //execution
                                            //spread_diff;
                                            //freemargin_mode
                                            //ie_deviation
                                            //lot_min;
                                            //lot_max
                                            //lot_step
                                        }
                                    }
                                }
                            }
                            #endregion
                        }
                    }
                }
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool MapSymbol(string value)
        {
            bool result = false;

            if (!string.IsNullOrEmpty(value))
            {
                string[] subValue = value.Split('{');
                if (subValue.Length > 0)
                {
                    if (Business.Market.SymbolList != null)
                    {
                        int count = Business.Market.SymbolList.Count;
                        for (int i = 0; i < count; i++)
                        {
                            if (Business.Market.SymbolList[i].Name == subValue[0])
                            {
                                #region update symbol
                                Business.Symbol newSymbol = Business.Market.SymbolList[i];
                                newSymbol.MarketAreaRef = Business.Market.MarketArea[0];
                                if (Business.Market.SecurityList != null)
                                {
                                    int countSecurity = Business.Market.SecurityList.Count;
                                    for (int j = 0; j < countSecurity; j++)
                                    {
                                        if (Business.Market.SecurityList[j].SecurityID == int.Parse(subValue[4]))
                                        {
                                            newSymbol.SecurityID = Business.Market.SecurityList[j].SecurityID;
                                            break;
                                        }
                                    }
                                }

                                newSymbol.Name = subValue[0];
                                newSymbol.IsQuote = true;
                                newSymbol.IsTrade = true;
                                newSymbol.TimeOnHold = 500000;
                                //source
                                newSymbol.Digit = int.Parse(subValue[2]);
                                //description
                                //type
                                //execution_mode
                                EnumMT4.Execution enuExecutionTrade = (EnumMT4.Execution)(Enum.Parse(typeof(EnumMT4.Execution), subValue[5]));
                                newSymbol.ExecutionTrade = enuExecutionTrade;

                                newSymbol.Currency = subValue[6];

                                EnumMT4.Trade enuTrade = (EnumMT4.Trade)(Enum.Parse(typeof(EnumMT4.Trade), subValue[7]));
                                switch (enuTrade)
                                {
                                    case EnumMT4.Trade.CLOSE_ONLY:
                                        newSymbol.Trade = "Close Only";
                                        break;

                                    case EnumMT4.Trade.FULL_ACCESS:
                                        newSymbol.Trade = "Full Access";
                                        break;

                                    case EnumMT4.Trade.NO:
                                        newSymbol.Trade = "No";
                                        break;
                                }

                                //newSymbol.Trade = subValue[7];
                                //margin_currency
                                //instant_max_volume
                                //gtc_pendings
                                newSymbol.SpreadByDefault = double.Parse(subValue[11]);
                                int _isLongOnly = int.Parse(subValue[12]);
                                if (_isLongOnly == 1)
                                    newSymbol.LongOnly = true;
                                else
                                    newSymbol.LongOnly = false;

                                newSymbol.StopLevel = int.Parse(subValue[13]);
                                newSymbol.SpreadBalace = double.Parse(subValue[14]) - 1;
                                newSymbol.FreezeLevel = int.Parse(subValue[15]);
                                newSymbol.ContractSize = double.Parse(subValue[16]);
                                newSymbol.InitialMargin = double.Parse(subValue[17]);
                                //margin_maintenance
                                newSymbol.MarginHedged = double.Parse(subValue[19]);
                                newSymbol.TickSize = double.Parse(subValue[20]);
                                newSymbol.TickPrice = double.Parse(subValue[21]);
                                //tick_value
                                //margin_mode

                                EnumMT4.ProfitCal enuProfitCal = (EnumMT4.ProfitCal)(Enum.Parse(typeof(EnumMT4.ProfitCal), subValue[23]));
                                switch (enuProfitCal)
                                {
                                    case EnumMT4.ProfitCal.CFD:
                                        newSymbol.ProfitCalculation = "CFD [ (close_price - open_price) * contract_size * lots ]";
                                        break;

                                    case EnumMT4.ProfitCal.FOREX:
                                        newSymbol.ProfitCalculation = "Forex [ (close_price - open_price) * contract_size * lots ]";
                                        break;

                                    case EnumMT4.ProfitCal.FUTURES:
                                        newSymbol.ProfitCalculation = "Futures [ (close_price - open_price) * tick_price / tick_size * lots ]";
                                        break;
                                }
                                //margin_hedged_strong
                                //realtime
                                //starting
                                //expiration

                                newSymbol.TickValue = new Tick();
                                newSymbol.TickValue.Bid = 0;
                                newSymbol.TickValue.Ask = 0;
                                newSymbol.TickValue.SymbolName = newSymbol.Name;
                                newSymbol.TickValue.Status = "down";

                                newSymbol.ParameterItems = new List<ParameterItem>();

                                Business.ParameterItem newParameterItem = new ParameterItem();
                                newParameterItem.Code = "S004";
                                newParameterItem.BoolValue = -1;
                                newParameterItem.DateValue = DateTime.Parse("1753-01-01 00:00:00.000");
                                newParameterItem.Name = "Description";
                                newParameterItem.NumValue = "-1";
                                newParameterItem.SecondParameterID = newSymbol.SymbolID;
                                newParameterItem.StringValue = subValue[3];
                                newSymbol.ParameterItems.Add(newParameterItem);

                                newParameterItem = new ParameterItem();
                                newParameterItem.Code = "S006";
                                newParameterItem.BoolValue = -1;
                                newParameterItem.DateValue = DateTime.Parse("1753-01-01 00:00:00.000");
                                newParameterItem.Name = "Trade Execution";
                                newParameterItem.NumValue = subValue[5];
                                newParameterItem.SecondParameterID = newSymbol.SymbolID;
                                newParameterItem.StringValue = "NaN";
                                newSymbol.ParameterItems.Add(newParameterItem);

                                newParameterItem = new ParameterItem();
                                newParameterItem.Code = "S048";
                                newParameterItem.BoolValue = -1;
                                newParameterItem.DateValue = DateTime.Parse("1753-01-01 00:00:00.000");
                                newParameterItem.Name = "Start Digit";
                                newParameterItem.NumValue = "0";
                                newParameterItem.SecondParameterID = newSymbol.SymbolID;
                                newParameterItem.StringValue = "NaN";
                                newSymbol.ParameterItems.Add(newParameterItem);

                                newParameterItem = new ParameterItem();
                                newParameterItem.Code = "S049";
                                newParameterItem.BoolValue = -1;
                                newParameterItem.DateValue = DateTime.Parse("1753-01-01 00:00:00.000");
                                newParameterItem.Name = "End Digit";
                                newParameterItem.NumValue = "0";
                                newParameterItem.SecondParameterID = newSymbol.SymbolID;
                                newParameterItem.StringValue = "NaN";
                                newSymbol.ParameterItems.Add(newParameterItem);

                                newParameterItem = new ParameterItem();
                                newParameterItem.Code = "S054";
                                newParameterItem.BoolValue = -1;
                                newParameterItem.DateValue = DateTime.Parse("1753-01-01 00:00:00.000");
                                newParameterItem.Name = "Description";
                                newParameterItem.NumValue = "500000";
                                newParameterItem.SecondParameterID = newSymbol.SymbolID;
                                newParameterItem.StringValue = "NaN";
                                newSymbol.ParameterItems.Add(newParameterItem);

                                if (Business.Market.Symbols.ContainsKey(newSymbol.Name))
                                    Business.Market.Symbols[newSymbol.Name] = newSymbol;
                                else
                                    Business.Market.Symbols.Add(newSymbol.Name, newSymbol);

                                result = true;
                                break;
                                #endregion
                            }
                        }
                    }
                }
            }

            return result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="cmde"></param>
        /// <param name="ipAddress"></param>
        /// <param name="code"></param>
        public void AgentPort(string cmd, string ipAddress, string code)
        {
            string result = string.Empty;
            string Command = string.Empty;
            string Value = string.Empty;

            if (!string.IsNullOrEmpty(cmd))
            {
                string[] subValue = cmd.Split('$');
                //TradingServer.Facade.FacadeAddNewSystemLog(1, subValue[0], "[SA]", ipAddress, code);
                switch (subValue[0])
                {
                    #region ADD ADMIN AGENT CONFIG
                    case "AddIAdminAgent":
                        {
                            if (TradingServer.Business.Market.ListAgentConfig != null)
                            {
                                int count = Business.Market.ListAgentConfig.Count;
                                for (int i = 0; i < count; i++)
                                {
                                    if (Business.Market.ListAgentConfig[i].AgentName.ToUpper().Trim() == code.ToUpper().Trim())
                                    {
                                        Business.Market.ListAgentConfig[i].ListIAdminAgent = new List<TradingServer.Agent.IAdminAgent>();
                                        TradingServer.Agent.IAdminAgent newIAdminAgent = null;

                                        string[] subCommand = subValue[1].Split('[');
                                        if (subCommand.Length > 2)
                                        {
                                            int countCommand = subCommand.Length;
                                            for (int j = 0; j < countCommand; j++)
                                            {
                                                if (string.IsNullOrEmpty(subCommand[j]))
                                                    continue;

                                                string[] subParameter = subCommand[j].Split('{');
                                                if (subParameter.Length > 0)
                                                {
                                                    newIAdminAgent = new TradingServer.Agent.IAdminAgent();

                                                    newIAdminAgent.IAdminAgentID = int.Parse(subParameter[0]);
                                                    newIAdminAgent.AdminID = int.Parse(subParameter[1]);
                                                    newIAdminAgent.AgentID = int.Parse(subParameter[2]);
                                                    newIAdminAgent.SymbolID = int.Parse(subParameter[3]);
                                                    newIAdminAgent.DefaultPL = double.Parse(subParameter[4]);
                                                    newIAdminAgent.IsDelete = bool.Parse(subParameter[5]);
                                                    newIAdminAgent.PercentPL = double.Parse(subParameter[6]);
                                                    newIAdminAgent.IsSkipRisk = bool.Parse(subParameter[7]);

                                                    Business.Market.ListAgentConfig[i].ListIAdminAgent.Add(newIAdminAgent);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    #endregion

                    #region INSERT IADMINAGENT FOR PL SYMBOL
                    case "InsertIAdminAgent":
                        {
                            if (TradingServer.Business.Market.ListAgentConfig != null)
                            {
                                int count = Business.Market.ListAgentConfig.Count;
                                for (int i = 0; i < count; i++)
                                {
                                    if (Business.Market.ListAgentConfig[i].AgentName.ToUpper().Trim() == code.ToUpper().Trim())
                                    {
                                        //Business.Market.ListAgentConfig[i].ListIAdminAgent = new List<TradingServer.Agent.IAdminAgent>();
                                        TradingServer.Agent.IAdminAgent newIAdminAgent = null;

                                        string[] subCommand = subValue[1].Split('[');
                                        if (subCommand.Length > 2)
                                        {
                                            int countCommand = subCommand.Length;
                                            for (int j = 0; j < countCommand; j++)
                                            {
                                                if (string.IsNullOrEmpty(subCommand[j]))
                                                    continue;

                                                string[] subParameter = subCommand[j].Split('{');
                                                if (subParameter.Length > 0)
                                                {
                                                    newIAdminAgent = new TradingServer.Agent.IAdminAgent();

                                                    newIAdminAgent.IAdminAgentID = int.Parse(subParameter[0]);
                                                    newIAdminAgent.AdminID = int.Parse(subParameter[1]);
                                                    newIAdminAgent.AgentID = int.Parse(subParameter[2]);
                                                    newIAdminAgent.SymbolID = int.Parse(subParameter[3]);
                                                    newIAdminAgent.DefaultPL = double.Parse(subParameter[4]);
                                                    newIAdminAgent.IsDelete = bool.Parse(subParameter[5]);
                                                    newIAdminAgent.PercentPL = double.Parse(subParameter[6]);
                                                    newIAdminAgent.IsSkipRisk = bool.Parse(subParameter[7]);

                                                    Business.Market.ListAgentConfig[i].ListIAdminAgent.Add(newIAdminAgent);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    #endregion

                    #region REMOVE IADMINAGENT PL IN SYMBOL
                    case "RemoveIAdminAgent":
                        {
                            if (TradingServer.Business.Market.ListAgentConfig != null)
                            {
                                int count = TradingServer.Business.Market.ListAgentConfig.Count;
                                for (int i = 0; i < count; i++)
                                {
                                    if (TradingServer.Business.Market.ListAgentConfig[i].AgentName.ToUpper().Trim() == code.ToUpper().Trim())
                                    {
                                        string[] subCommand = subValue[1].Split('[');
                                        if (subCommand.Length > 0)
                                        {
                                            int countCommand = subCommand.Length;
                                            for (int j = 0; j < countCommand; j++)
                                            {
                                                if (string.IsNullOrEmpty(subCommand[j]))
                                                    continue;

                                                int IAdminAgentID = 0;
                                                bool isParse = int.TryParse(subCommand[j], out IAdminAgentID);

                                                if (isParse)
                                                {
                                                    if (TradingServer.Business.Market.ListAgentConfig[i].ListIAdminAgent != null)
                                                    {
                                                        int countIAdminAgent = TradingServer.Business.Market.ListAgentConfig[i].ListIAdminAgent.Count;
                                                        for (int n = 0; n < countIAdminAgent; n++)
                                                        {
                                                            if (TradingServer.Business.Market.ListAgentConfig[i].ListIAdminAgent[n].IAdminAgentID == IAdminAgentID)
                                                            {
                                                                TradingServer.Business.Market.ListAgentConfig[i].ListIAdminAgent.RemoveAt(n);
                                                                break;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                        break;
                    #endregion

                    #region ADD AGENT WITH AGENT
                    case "AddAgentWithAgent":
                        {
                            if (TradingServer.Business.Market.ListAgentConfig != null)
                            {
                                int count = Business.Market.ListAgentConfig.Count;
                                for (int i = 0; i < count; i++)
                                {
                                    if (Business.Market.ListAgentConfig[i].AgentName.ToUpper().Trim() == code.ToUpper().Trim())
                                    {
                                        Business.Market.ListAgentConfig[i].ListIAgentWithAgent = new List<TradingServer.Agent.IAgentWithAgent>();

                                        TradingServer.Agent.IAgentWithAgent newIAgentWithAgent = null;

                                         string[] subParameter = subValue[1].Split('{');
                                                    if (subParameter.Length > 0)
                                                    {
                                                        newIAgentWithAgent = new TradingServer.Agent.IAgentWithAgent();
                                                        newIAgentWithAgent.IAgentWithAgentID = int.Parse(subParameter[0]);
                                                        newIAgentWithAgent.AgentID = int.Parse(subParameter[1]);
                                                        newIAgentWithAgent.AgentRefID = int.Parse(subParameter[2]);
                                                        newIAgentWithAgent.SymbolID = int.Parse(subParameter[3]);
                                                        newIAgentWithAgent.DefaultPL = double.Parse(subParameter[4]);
                                                        newIAgentWithAgent.DefaultPLParent = double.Parse(subParameter[5]);
                                                        newIAgentWithAgent.PercentPLParent = double.Parse(subParameter[6]);
                                                        newIAgentWithAgent.IsDelete = bool.Parse(subParameter[7]);
                                                        newIAgentWithAgent.PercentPL = double.Parse(subParameter[8]);
                                                        newIAgentWithAgent.IsSkipRisk = bool.Parse(subParameter[9]);
                                                        newIAgentWithAgent.PercentPLChild = double.Parse(subParameter[10]);
                                                        newIAgentWithAgent.IsSkipRiskChild = bool.Parse(subParameter[11]);

                                                        Business.Market.ListAgentConfig[i].ListIAgentWithAgent.Add(newIAgentWithAgent);
                                                    }
                                        break;
                                    }
                                }
                            }
                        }
                        break;
                    #endregion

                    #region REMOVE IAGENTWITHAGENT FOR PL SYMBOL
                    case "RemoveIAgentWithAgent":
                        {
                            if (TradingServer.Business.Market.ListAgentConfig != null)
                            {
                                int count = TradingServer.Business.Market.ListAgentConfig.Count;
                                for (int i = 0; i < count; i++)
                                {
                                    if (TradingServer.Business.Market.ListAgentConfig[i].AgentName.ToUpper().Trim() == code.ToUpper().Trim())
                                    {
                                        string[] subCommand = subValue[1].Split('[');
                                        if (subCommand.Length > 0)
                                        {
                                            int countCommand = subCommand.Length;
                                            for (int j = 0; j < countCommand; j++)
                                            {
                                                int IAgentWithAgentID = 0;
                                                bool isParse = int.TryParse(subCommand[j], out IAgentWithAgentID);

                                                if (isParse)
                                                {
                                                    if (TradingServer.Business.Market.ListAgentConfig[i].ListIAgentWithAgent != null)
                                                    {
                                                        int countIAgentWithAgent = TradingServer.Business.Market.ListAgentConfig[i].ListIAgentWithAgent.Count;
                                                        for (int n = 0; n < countIAgentWithAgent; n++)
                                                        {
                                                            if (TradingServer.Business.Market.ListAgentConfig[i].ListIAgentWithAgent[n].IAgentWithAgentID == IAgentWithAgentID)
                                                            {
                                                                TradingServer.Business.Market.ListAgentConfig[i].ListIAgentWithAgent.RemoveAt(n);
                                                                break;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }

                                        break;
                                    }
                                }
                            }
                        }
                        break;
                    #endregion

                    #region ADD AGENT INVESTOR CONFIG
                    case "AddAgentInvestorConfig":
                        {
                            //Check IP VALID
                            if (TradingServer.Business.Market.ListAgentConfig != null)
                            {
                                int count = Business.Market.ListAgentConfig.Count;
                                for (int i = 0; i < count; i++)
                                {
                                    if (Business.Market.ListAgentConfig[i].AgentName.ToUpper().Trim() == code.ToUpper().Trim())
                                    {
                                        if (Business.Market.ListAgentConfig[i].ListIAgentInvestor == null)
                                            Business.Market.ListAgentConfig[i].ListIAgentInvestor = new List<TradingServer.Agent.IAgentInvestorSymbol>();

                                        TradingServer.Agent.IAgentInvestorSymbol newIAgentInvestor = null;

                                        string[] subParameter = subValue[1].Split(']');
                                        if (subParameter.Length == 2)
                                        {
                                            if (string.IsNullOrEmpty(subParameter[0]))
                                                continue;

                                            string[] subData = subParameter[0].Split('{');
                                            newIAgentInvestor = new TradingServer.Agent.IAgentInvestorSymbol();
                                            newIAgentInvestor.IAgentInvestorSymbolID = int.Parse(subData[0]);
                                            newIAgentInvestor.AgentID = int.Parse(subData[1]);
                                            newIAgentInvestor.InvestorID = int.Parse(subData[2]);
                                            newIAgentInvestor.SymbolID = int.Parse(subData[3]);
                                            newIAgentInvestor.PercentAgent = double.Parse(subData[4]);

                                            newIAgentInvestor.IAgentInvestorSymbolConfig = new List<ParameterItem>();
                                        }

                                        Business.Market.ListAgentConfig[i].ListIAgentInvestor.Add(newIAgentInvestor);

                                    }
                                }
                            }
                        }
                        break;
                    #endregion

                    #region UPDATE ADMIN AGENT CONFIG
                    case "UpdateIAdminAgent":
                        {
                            //IAdminMaster]IAdminMasterConfig|IAdminMasterConfig
                            string[] subParameter = subValue[1].Split('[');
                            if (subParameter.Length > 0)
                            {
                                int countIAgentWithAdmin = subParameter.Length;
                                for (int n = 0; n < countIAgentWithAdmin; n++)
                                {
                                    if (!string.IsNullOrEmpty(subParameter[n]))
                                    {
                                        string[] subIAdminMaster = subParameter[n].Split('{');
                                        TradingServer.Agent.IAdminAgent newIAdminAgent = new TradingServer.Agent.IAdminAgent();

                                        newIAdminAgent.IAdminAgentID = int.Parse(subIAdminMaster[0]);
                                        newIAdminAgent.AdminID = int.Parse(subIAdminMaster[1]);
                                        newIAdminAgent.AgentID = int.Parse(subIAdminMaster[2]);
                                        newIAdminAgent.SymbolID = int.Parse(subIAdminMaster[3]);
                                        newIAdminAgent.DefaultPL = double.Parse(subIAdminMaster[4]);
                                        newIAdminAgent.IsDelete = bool.Parse(subIAdminMaster[5]);
                                        newIAdminAgent.PercentPL = double.Parse(subIAdminMaster[6]);
                                        newIAdminAgent.IsSkipRisk = bool.Parse(subIAdminMaster[7]);

                                        newIAdminAgent.IAdminAgentConfig = new List<ParameterItem>();

                                        #region UPDATE IADMINMASTER
                                        bool isExits = false;
                                        if (Business.Market.ListAgentConfig != null)
                                        {
                                            int count = Business.Market.ListAgentConfig.Count;
                                            for (int i = 0; i < count; i++)
                                            {
                                                if (Business.Market.ListAgentConfig[i].AgentName.ToUpper().Trim() == code.ToUpper().Trim())
                                                {
                                                    if (Business.Market.ListAgentConfig[i].ListIAdminAgent != null)
                                                    {
                                                        int countIAdminMaster = Business.Market.ListAgentConfig[i].ListIAdminAgent.Count;
                                                        for (int j = 0; j < countIAdminMaster; j++)
                                                        {
                                                            if (Business.Market.ListAgentConfig[i].ListIAdminAgent[j].IAdminAgentID == newIAdminAgent.IAdminAgentID)
                                                            {
                                                                Business.Market.ListAgentConfig[i].ListIAdminAgent[j] = newIAdminAgent;
                                                                isExits = true;
                                                                break;
                                                            }
                                                        }
                                                    }

                                                    if (!isExits)
                                                    {
                                                        if (Business.Market.ListAgentConfig[i].ListIAdminAgent == null)
                                                            Business.Market.ListAgentConfig[i].ListIAdminAgent = new List<TradingServer.Agent.IAdminAgent>();

                                                        Business.Market.ListAgentConfig[i].ListIAdminAgent.Add(newIAdminAgent);
                                                    }
                                                    break;
                                                }
                                            }
                                        }
                                        #endregion
                                    }
                                }
                            }
                        }
                        break;
                    #endregion

                    #region UPDATE AGENT WITH AGENT CONFIG
                    case "UpdateIAgentWithAgent":
                        {
                            //TradingServer.Facade.FacadeAddNewSystemLog(1, subValue[1], "[UpdateIAgentWithAgent]", ipAddress, code);
                            //UpdateIAgentWithAgent$93{235{233{-1{30{20{30{False{0{False[
                            string[] subParameter = subValue[1].Split('[');
                            if (subParameter.Length > 0)
                            {
                                int countIAgentWithAgent = subParameter.Length;
                                for (int n = 0; n < countIAgentWithAgent; n++)
                                {
                                    if (!string.IsNullOrEmpty(subParameter[n]))
                                    {
                                        string[] subIMasterAgent = subParameter[n].Split('{');
                                        TradingServer.Agent.IAgentWithAgent newIAgentWithAgent = new TradingServer.Agent.IAgentWithAgent();

                                        newIAgentWithAgent.IAgentWithAgentID = int.Parse(subIMasterAgent[0]);
                                        newIAgentWithAgent.AgentID = int.Parse(subIMasterAgent[1]);
                                        newIAgentWithAgent.AgentRefID = int.Parse(subIMasterAgent[2]);
                                        newIAgentWithAgent.SymbolID = int.Parse(subIMasterAgent[3]);
                                        newIAgentWithAgent.DefaultPL = double.Parse(subIMasterAgent[4]);
                                        newIAgentWithAgent.DefaultPLParent = double.Parse(subIMasterAgent[5]);
                                        newIAgentWithAgent.PercentPLParent = double.Parse(subIMasterAgent[6]);
                                        newIAgentWithAgent.IsDelete = bool.Parse(subIMasterAgent[7]);
                                        newIAgentWithAgent.PercentPL = double.Parse(subIMasterAgent[8]);
                                        newIAgentWithAgent.IsSkipRisk = bool.Parse(subIMasterAgent[9]);
                                        newIAgentWithAgent.PercentPLChild = double.Parse(subIMasterAgent[10]);
                                        newIAgentWithAgent.IsSkipRiskChild = bool.Parse(subIMasterAgent[11]);

                                        newIAgentWithAgent.IAgentWithAgentConfig = new List<ParameterItem>();

                                        #region UPDATE IMASTERAGENT
                                        bool isExits = false;
                                        if (Business.Market.ListAgentConfig != null)
                                        {
                                            int count = Business.Market.ListAgentConfig.Count;
                                            for (int i = 0; i < count; i++)
                                            {
                                                if (Business.Market.ListAgentConfig[i].AgentName.ToUpper().Trim() == code.ToUpper().Trim())
                                                {
                                                    if (Business.Market.ListAgentConfig[i].ListIAgentWithAgent != null)
                                                    {
                                                        int countIMasterAgent = Business.Market.ListAgentConfig[i].ListIAgentWithAgent.Count;
                                                        for (int j = 0; j < countIMasterAgent; j++)
                                                        {
                                                            if (Business.Market.ListAgentConfig[i].ListIAgentWithAgent[j].IAgentWithAgentID == newIAgentWithAgent.IAgentWithAgentID)
                                                            {
                                                                //TradingServer.Facade.FacadeAddNewSystemLog(1, newIAgentWithAgent.IAgentWithAgentID + "-" + newIAgentWithAgent.AgentID + "-" +
                                                                //                                            newIAgentWithAgent.AgentRefID + "-" + newIAgentWithAgent.SymbolID + "-" +
                                                                //                                            newIAgentWithAgent.DefaultPL + "-" + newIAgentWithAgent.DefaultPLParent + "-" +
                                                                //                                            newIAgentWithAgent.PercentPLParent + "-" + newIAgentWithAgent.PercentPLParent + "-" +
                                                                //                                            newIAgentWithAgent.IsDelete + "-" + newIAgentWithAgent.PercentPL + "-" +
                                                                //                                            newIAgentWithAgent.IsSkipRisk + "-" + newIAgentWithAgent.PercentPLChild + "-" +
                                                                //                                            newIAgentWithAgent.IsSkipRiskChild, "[UpdateIAgentWithAgent]", ipAddress, code);
                                                                Business.Market.ListAgentConfig[i].ListIAgentWithAgent[j] = newIAgentWithAgent;
                                                                isExits = true;
                                                                break;
                                                            }
                                                        }
                                                    }

                                                    if (!isExits)
                                                    {
                                                        if (Business.Market.ListAgentConfig[i].ListIAgentWithAgent == null)
                                                            Business.Market.ListAgentConfig[i].ListIAgentWithAgent = new List<TradingServer.Agent.IAgentWithAgent>();

                                                        Business.Market.ListAgentConfig[i].ListIAgentWithAgent.Add(newIAgentWithAgent);
                                                    }
                                                    break;
                                                }
                                            }
                                        }
                                        #endregion
                                    }
                                }
                            }
                        }
                        break;
                    #endregion

                    #region UPDATE AGENT INVESTOR CONFIG
                    case "UpdateIAgentInvestor":
                        {
                            string[] subParameter = subValue[1].Split('[');
                            if (subParameter.Length > 0)
                            {
                                string[] subIAgentInvestor = subParameter[0].Split('{');
                                TradingServer.Agent.IAgentInvestorSymbol newIAgentInvestor = new TradingServer.Agent.IAgentInvestorSymbol();
                                newIAgentInvestor.IAgentInvestorSymbolID = int.Parse(subIAgentInvestor[0]);
                                newIAgentInvestor.AgentID = int.Parse(subIAgentInvestor[1]);
                                newIAgentInvestor.InvestorID = int.Parse(subIAgentInvestor[2]);
                                newIAgentInvestor.SymbolID = int.Parse(subIAgentInvestor[3]);
                                newIAgentInvestor.PercentAgent = double.Parse(subIAgentInvestor[4]);

                                newIAgentInvestor.IAgentInvestorSymbolConfig = new List<ParameterItem>();

                                #region MAP IAGENTINVESTOR CONFIG
                                if (!string.IsNullOrEmpty(subParameter[1]))
                                {
                                    string[] subIAgentInvestorConfig = subParameter[1].Split('|');
                                    if (subIAgentInvestorConfig.Length > 0)
                                    {
                                        int count = subIAgentInvestorConfig.Length;
                                        for (int i = 0; i < count; i++)
                                        {
                                            string[] subData = subIAgentInvestorConfig[i].Split('{');
                                            if (subData.Length > 0)
                                            {
                                                Business.ParameterItem newParameterItem = new ParameterItem();
                                                newParameterItem.ParameterItemID = int.Parse(subData[0]);
                                                newParameterItem.SecondParameterID = int.Parse(subData[1]);
                                                newParameterItem.Name = subData[2];
                                                newParameterItem.Code = subData[3];
                                                newParameterItem.BoolValue = int.Parse(subData[4]);
                                                newParameterItem.DateValue = DateTime.Parse(subData[5]);
                                                newParameterItem.NumValue = subData[6];
                                                newParameterItem.StringValue = subData[7];

                                                newIAgentInvestor.IAgentInvestorSymbolConfig.Add(newParameterItem);
                                            }
                                        }
                                    }
                                }
                                #endregion

                                #region UPDATE IAGENTINVESTOR
                                if (Business.Market.ListAgentConfig != null)
                                {
                                    int count = Business.Market.ListAgentConfig.Count;
                                    for (int i = 0; i < count; i++)
                                    {
                                        if (Business.Market.ListAgentConfig[i].AgentName.ToUpper().Trim() == code.ToUpper().Trim())
                                        {
                                            if (Business.Market.ListAgentConfig[i].ListIAgentInvestor != null)
                                            {
                                                int countIAgentInvestor = Business.Market.ListAgentConfig[i].ListIAgentInvestor.Count;
                                                for (int j = 0; j < countIAgentInvestor; j++)
                                                {
                                                    if (Business.Market.ListAgentConfig[i].ListIAgentInvestor[j].IAgentInvestorSymbolID == newIAgentInvestor.IAgentInvestorSymbolID)
                                                    {
                                                        Business.Market.ListAgentConfig[i].ListIAgentInvestor[j] = newIAgentInvestor;
                                                        break;
                                                    }
                                                }
                                            }
                                            break;
                                        }
                                    }
                                }
                                #endregion
                            }
                        }
                        break;
                    #endregion

                    #region INSERT IADMIN AGENT CONFIG
                    case "InsertIAdminAgentConfig":
                        {
                            string[] subParameter = subValue[1].Split('[');
                            if (subParameter.Length > 0)
                            {
                                if (!string.IsNullOrEmpty(subParameter[0]))
                                {
                                    string[] subIAdminMaster = subParameter[0].Split('{');
                                    TradingServer.Agent.IAdminAgent newIAdminAgent = new TradingServer.Agent.IAdminAgent();
                                    newIAdminAgent.IAdminAgentID = int.Parse(subIAdminMaster[0]);
                                    newIAdminAgent.AdminID = int.Parse(subIAdminMaster[1]);
                                    newIAdminAgent.AgentID = int.Parse(subIAdminMaster[2]);
                                    newIAdminAgent.SymbolID = int.Parse(subIAdminMaster[3]);
                                    newIAdminAgent.DefaultPL = double.Parse(subIAdminMaster[4]);
                                    newIAdminAgent.IsDelete = bool.Parse(subIAdminMaster[5]);
                                    newIAdminAgent.PercentPL = double.Parse(subIAdminMaster[6]);
                                    newIAdminAgent.IsSkipRisk = bool.Parse(subIAdminMaster[7]);

                                    newIAdminAgent.IAdminAgentConfig = new List<ParameterItem>();

                                    if (Business.Market.ListAgentConfig != null)
                                    {
                                        int count = Business.Market.ListAgentConfig.Count;
                                        for (int i = 0; i < count; i++)
                                        {
                                            if (Business.Market.ListAgentConfig[i].AgentName.ToUpper().Trim() == code.ToUpper().Trim())
                                            {
                                                bool flag = false;
                                                if (Business.Market.ListAgentConfig[i].ListIAdminAgent != null)
                                                {
                                                    int countIAdminMaster = Business.Market.ListAgentConfig[i].ListIAdminAgent.Count;
                                                    for (int j = 0; j < countIAdminMaster; j++)
                                                    {
                                                        if (Business.Market.ListAgentConfig[i].ListIAdminAgent[j].AdminID == newIAdminAgent.AdminID &&
                                                            Business.Market.ListAgentConfig[i].ListIAdminAgent[j].AgentID == newIAdminAgent.AgentID)
                                                        {
                                                            if (newIAdminAgent.IAdminAgentConfig != null)
                                                            {
                                                                int countConfig = newIAdminAgent.IAdminAgentConfig.Count;
                                                                //Business.Market.ListAgentConfig[i].ListIAdminAgent[j].IAdminAgentConfig = newIAdminAgent.IAdminAgentConfig;
                                                            }

                                                            flag = true;

                                                            break;
                                                        }
                                                    }
                                                }

                                                if (!flag)
                                                {
                                                    Business.Market.ListAgentConfig[i].ListIAdminAgent.Add(newIAdminAgent);
                                                }

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

                    #region INSERT IAGENT WITH AGENT CONFIG
                    case "InsertIAgentWithAgent":
                        {
                            string[] subParameter = subValue[1].Split('[');
                            if (subParameter.Length > 0)
                            {
                                if (!string.IsNullOrEmpty(subParameter[0]))
                                {
                                    string[] subIMasterAgent = subParameter[0].Split('{');
                                    TradingServer.Agent.IAgentWithAgent newIAgentWithAgent = new TradingServer.Agent.IAgentWithAgent();
                                    newIAgentWithAgent.IAgentWithAgentID = int.Parse(subIMasterAgent[0]);
                                    newIAgentWithAgent.AgentID = int.Parse(subIMasterAgent[1]);
                                    newIAgentWithAgent.AgentRefID = int.Parse(subIMasterAgent[2]);
                                    newIAgentWithAgent.SymbolID = int.Parse(subIMasterAgent[3]);
                                    newIAgentWithAgent.DefaultPL = double.Parse(subIMasterAgent[4]);
                                    newIAgentWithAgent.DefaultPLParent = double.Parse(subIMasterAgent[5]);

                                    newIAgentWithAgent.IsDelete = bool.Parse(subIMasterAgent[7]);
                                    newIAgentWithAgent.PercentPL = double.Parse(subIMasterAgent[8]);
                                    newIAgentWithAgent.IsSkipRisk = bool.Parse(subIMasterAgent[9]);
                                    newIAgentWithAgent.PercentPLChild = double.Parse(subIMasterAgent[10]);
                                    newIAgentWithAgent.IsSkipRiskChild = bool.Parse(subIMasterAgent[11]);

                                    newIAgentWithAgent.IAgentWithAgentConfig = new List<ParameterItem>();

                                    if (Business.Market.ListAgentConfig != null)
                                    {
                                        int count = Business.Market.ListAgentConfig.Count;
                                        for (int i = 0; i < count; i++)
                                        {
                                            if (Business.Market.ListAgentConfig[i].AgentName.ToUpper().Trim() == code.ToUpper().Trim())
                                            {
                                                bool flag = false;
                                                if (Business.Market.ListAgentConfig[i].ListIAgentWithAgent != null)
                                                {
                                                    int countIMasterAgent = Business.Market.ListAgentConfig[i].ListIAgentWithAgent.Count;
                                                    for (int j = 0; j < countIMasterAgent; j++)
                                                    {
                                                        if (Business.Market.ListAgentConfig[i].ListIAgentWithAgent[j].AgentID == newIAgentWithAgent.AgentID &&
                                                            Business.Market.ListAgentConfig[i].ListIAgentWithAgent[j].AgentRefID == newIAgentWithAgent.AgentRefID &&
                                                            Business.Market.ListAgentConfig[i].ListIAgentWithAgent[j].SymbolID == newIAgentWithAgent.SymbolID)
                                                        {
                                                            if (newIAgentWithAgent.IAgentWithAgentConfig != null)
                                                            {
                                                                int countConfig = newIAgentWithAgent.IAgentWithAgentConfig.Count;
                                                                //Business.Market.ListAgentConfig[i].ListIAgentWithAgent[j].IAgentWithAgentConfig = newIAgentWithAgent.IAgentWithAgentConfig;
                                                            }

                                                            flag = true;

                                                            break;
                                                        }
                                                    }
                                                }

                                                if (!flag)
                                                {
                                                    Business.Market.ListAgentConfig[i].ListIAgentWithAgent.Add(newIAgentWithAgent);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    #endregion

                    #region INSERT IAGENT INVESTOR CONFIG
                    case "InsertAgentInvestor":
                        {
                            string[] subParameter = subValue[1].Split('[');
                            if (subParameter.Length > 0)
                            {
                                string[] subIAgentInvestor = subParameter[0].Split('{');
                                TradingServer.Agent.IAgentInvestorSymbol newIAgentInvestor = new TradingServer.Agent.IAgentInvestorSymbol();
                                newIAgentInvestor.IAgentInvestorSymbolID = int.Parse(subIAgentInvestor[0]);
                                newIAgentInvestor.AgentID = int.Parse(subIAgentInvestor[1]);
                                newIAgentInvestor.InvestorID = int.Parse(subIAgentInvestor[2]);
                                newIAgentInvestor.SymbolID = int.Parse(subIAgentInvestor[3]);
                                newIAgentInvestor.PercentAgent = double.Parse(subIAgentInvestor[4]);

                                newIAgentInvestor.IAgentInvestorSymbolConfig = new List<ParameterItem>();

                                if (Business.Market.ListAgentConfig != null)
                                {
                                    int count = Business.Market.ListAgentConfig.Count;
                                    for (int i = 0; i < count; i++)
                                    {
                                        if (Business.Market.ListAgentConfig[i].AgentName.ToUpper().Trim() == code.ToUpper().Trim())
                                        {
                                            bool flag = false;
                                            if (Business.Market.ListAgentConfig[i].ListIAgentInvestor != null)
                                            {
                                                int countIAgentInvestorConfig = Business.Market.ListAgentConfig[i].ListIAgentInvestor.Count;
                                                for (int j = 0; j < countIAgentInvestorConfig; j++)
                                                {
                                                    if (Business.Market.ListAgentConfig[i].ListIAgentInvestor[j] == null)
                                                    {
                                                        Business.Market.ListAgentConfig[i].ListIAgentInvestor.RemoveAt(j);
                                                        j--;
                                                        countIAgentInvestorConfig = Business.Market.ListAgentConfig[i].ListIAgentInvestor.Count;
                                                        continue;
                                                    }

                                                    if (Business.Market.ListAgentConfig[i].ListIAgentInvestor[j].AgentID == newIAgentInvestor.AgentID &&
                                                        Business.Market.ListAgentConfig[i].ListIAgentInvestor[j].InvestorID == newIAgentInvestor.InvestorID)
                                                    {
                                                        flag = true;

                                                        break;
                                                    }
                                                }

                                                if (!flag)
                                                {
                                                    Business.Market.ListAgentConfig[i].ListIAgentInvestor.Add(newIAgentInvestor);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    #endregion

                    #region INSERT LIST IAGENT INVESTOR
                    case "InsertListIAgentInvestor":
                        {
                            //InsertListIAgentInvestor$IAgentInvestorID{AgentID{InvestorID{SymbolID{PercentPL[ParameterID{SecondParameterID{Name{Code{
                            //                                            BoolValue{DateValue{NumValue{StringValue{|.....
                            string[] subRoot = subValue[1].Split('|');
                            if (subRoot.Length > 0)
                            {
                                int countRoot = subRoot.Length;
                                for (int n = 0; n < countRoot; n++)
                                {
                                    if (!string.IsNullOrEmpty(subRoot[n]))
                                    {
                                        string[] subParameter = subRoot[n].Split('[');
                                        if (subParameter.Length > 0)
                                        {
                                            string[] subIAgentInvestor = subParameter[0].Split('{');
                                            TradingServer.Agent.IAgentInvestorSymbol newIAgentInvestor = new TradingServer.Agent.IAgentInvestorSymbol();
                                            newIAgentInvestor.IAgentInvestorSymbolID = int.Parse(subIAgentInvestor[0]);
                                            newIAgentInvestor.AgentID = int.Parse(subIAgentInvestor[1]);
                                            newIAgentInvestor.InvestorID = int.Parse(subIAgentInvestor[2]);
                                            newIAgentInvestor.SymbolID = int.Parse(subIAgentInvestor[3]);
                                            newIAgentInvestor.PercentAgent = double.Parse(subIAgentInvestor[4]);

                                            newIAgentInvestor.IAgentInvestorSymbolConfig = new List<ParameterItem>();

                                            #region ADD TO LISTAGENTCONFIG
                                            if (Business.Market.ListAgentConfig != null)
                                            {
                                                int count = Business.Market.ListAgentConfig.Count;
                                                for (int i = 0; i < count; i++)
                                                {
                                                    if (Business.Market.ListAgentConfig[i].AgentName.ToUpper().Trim() == code.ToUpper().Trim())
                                                    {
                                                        bool flag = false;
                                                        if (Business.Market.ListAgentConfig[i].ListIAgentInvestor != null)
                                                        {
                                                            int countIAgentInvestorConfig = Business.Market.ListAgentConfig[i].ListIAgentInvestor.Count;
                                                            for (int j = 0; j < countIAgentInvestorConfig; j++)
                                                            {
                                                                if (Business.Market.ListAgentConfig[i].ListIAgentInvestor[j] == null)
                                                                {
                                                                    Business.Market.ListAgentConfig[i].ListIAgentInvestor.RemoveAt(j);
                                                                    j--;
                                                                    countIAgentInvestorConfig = Business.Market.ListAgentConfig[i].ListIAgentInvestor.Count;
                                                                    continue;
                                                                }

                                                                if (Business.Market.ListAgentConfig[i].ListIAgentInvestor[j].AgentID == newIAgentInvestor.AgentID &&
                                                                    Business.Market.ListAgentConfig[i].ListIAgentInvestor[j].InvestorID == newIAgentInvestor.InvestorID)
                                                                {
                                                                    flag = true;

                                                                    break;
                                                                }
                                                                //if (Business.Market.ListAgentConfig[i].ListIAgentInvestor[j].IAgentInvestorSymbolID == newIAgentInvestor.IAgentInvestorSymbolID)
                                                                //{
                                                                //    flag = true;
                                                                //    break;
                                                                //}
                                                            }

                                                            if (!flag)
                                                            {
                                                                Business.Market.ListAgentConfig[i].ListIAgentInvestor.Add(newIAgentInvestor);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            #endregion
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    #endregion

                    #region ADD ADMIN AGENT COMMISSION
                    case "AddAdminAgentCommission":
                        {
                            //TradingServer.Facade.FacadeAddNewSystemLog(1, "Begin AddAdminAgentComm" + code, "[AddAdminAgentComm]", "", "");
                            if (TradingServer.Business.Market.ListAgentConfig != null)
                            {
                                 int count = Business.Market.ListAgentConfig.Count;
                                 for (int i = 0; i < count; i++)
                                 {
                                     if (Business.Market.ListAgentConfig[i].AgentName.ToUpper().Trim() == code.ToUpper().Trim())
                                     {
                                         string[] subRoot = subValue[1].Split('>');

                                         if (bool.Parse(subRoot[1]))
                                             Business.Market.ListAgentConfig[i].ListIAdminAgentCommission = new List<TradingServer.Agent.IParameterCommission>();

                                         TradingServer.Agent.IParameterCommission newAdminAgentCommission = null;

                                         string[] subCommand = subRoot[0].Split('[');
                                         if (subCommand.Length > 0)
                                         {
                                             int countCommand = subCommand.Length;
                                             for (int j = 0; j < countCommand; j++)
                                             {
                                                 if (!string.IsNullOrEmpty(subCommand[j]))
                                                 {
                                                     string[] subParameter = subCommand[j].Split('{');
                                                     if (subParameter.Length > 0)
                                                     {
                                                         newAdminAgentCommission = new TradingServer.Agent.IParameterCommission();

                                                         newAdminAgentCommission.IParameterID = int.Parse(subParameter[0]);
                                                         newAdminAgentCommission.FirstParameterID = int.Parse(subParameter[1]);
                                                         newAdminAgentCommission.SecondParameterID = int.Parse(subParameter[2]);
                                                         newAdminAgentCommission.GroupID = int.Parse(subParameter[3]);
                                                         newAdminAgentCommission.SymbolID = int.Parse(subParameter[4]);
                                                         newAdminAgentCommission.Comission = double.Parse(subParameter[5]);
                                                         newAdminAgentCommission.IsDelete = bool.Parse(subParameter[6]);
                                                         newAdminAgentCommission.ParentCommission = double.Parse(subParameter[7]);
                                                         newAdminAgentCommission.ChildCommission = double.Parse(subParameter[8]);
                                                         newAdminAgentCommission.ParentPipReBate = double.Parse(subParameter[9]);
                                                         newAdminAgentCommission.ChildPipReBate = double.Parse(subParameter[10]);

                                                         Business.Market.ListAgentConfig[i].ListIAdminAgentCommission.Add(newAdminAgentCommission);
                                                     }
                                                 }
                                             }
                                         }

                                         //TradingServer.Facade.FacadeAddNewSystemLog(1, Business.Market.ListAgentConfig[i].ListIAdminAgentCommission.Count.ToString(), "[TotalAdminAgentComm]", "", "");
                                     }
                                 }
                            }

                            //TradingServer.Facade.FacadeAddNewSystemLog(1, "End AddAdminAgentComm", "[AddAdminAgentComm]", "", "");
                        }
                        break;
                    #endregion

                    #region ADD AGENT WITH AGENT COMMISSION
                    case "AddAgentWithAgentCommission":
                        {
                            if (TradingServer.Business.Market.ListAgentConfig != null)
                            {
                                int count = Business.Market.ListAgentConfig.Count;
                                for (int i = 0; i < count; i++)
                                {
                                    if (Business.Market.ListAgentConfig[i].AgentName.ToUpper().Trim() == code.ToUpper().Trim())
                                    {
                                        string[] subRoot = subValue[1].Split('>');

                                        if (bool.Parse(subRoot[1]))
                                            Business.Market.ListAgentConfig[i].ListIAgentWithAgentCommission = new List<TradingServer.Agent.IParameterCommission>();

                                        TradingServer.Agent.IParameterCommission newAdminAgentCommission = null;

                                        string[] subCommand = subRoot[0].Split('[');
                                        if (subCommand.Length > 0)
                                        {
                                            int countCommand = subCommand.Length;
                                            for (int j = 0; j < countCommand; j++)
                                            {
                                                if (!string.IsNullOrEmpty(subCommand[j]))
                                                {
                                                    string[] subParameter = subCommand[j].Split('{');
                                                    if (subParameter.Length > 0)
                                                    {
                                                        newAdminAgentCommission = new TradingServer.Agent.IParameterCommission();

                                                        newAdminAgentCommission.IParameterID = int.Parse(subParameter[0]);
                                                        newAdminAgentCommission.FirstParameterID = int.Parse(subParameter[1]);
                                                        newAdminAgentCommission.SecondParameterID = int.Parse(subParameter[2]);
                                                        newAdminAgentCommission.GroupID = int.Parse(subParameter[3]);
                                                        newAdminAgentCommission.SymbolID = int.Parse(subParameter[4]);
                                                        newAdminAgentCommission.Comission = double.Parse(subParameter[5]);
                                                        newAdminAgentCommission.IsDelete = bool.Parse(subParameter[6]);
                                                        newAdminAgentCommission.ParentCommission = double.Parse(subParameter[7]);
                                                        newAdminAgentCommission.ChildCommission = double.Parse(subParameter[8]);
                                                        newAdminAgentCommission.ParentPipReBate = double.Parse(subParameter[9]);
                                                        newAdminAgentCommission.ChildPipReBate = double.Parse(subParameter[10]);

                                                        Business.Market.ListAgentConfig[i].ListIAgentWithAgentCommission.Add(newAdminAgentCommission);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    #endregion

                    #region UPDATE ADMIN AGENT COMMISSION
                    case "UpdateIAdminAgentCommission":
                        {
                            string[] subParameter = subValue[1].Split('[');
                            if (subParameter.Length > 0)
                            {
                                int countPara = subParameter.Length;
                                for (int n = 0; n < countPara; n++)
                                {
                                    if (!string.IsNullOrEmpty(subParameter[n]))
                                    {
                                        string[] subIAdminAgent = subParameter[n].Split('{');
                                        if (subIAdminAgent.Length > 0)
                                        {
                                            TradingServer.Agent.IParameterCommission newIAdminAgentCommission = new TradingServer.Agent.IParameterCommission();
                                            newIAdminAgentCommission.IParameterID = int.Parse(subIAdminAgent[0]);
                                            newIAdminAgentCommission.FirstParameterID = int.Parse(subIAdminAgent[1]);
                                            newIAdminAgentCommission.SecondParameterID = int.Parse(subIAdminAgent[2]);
                                            newIAdminAgentCommission.GroupID = int.Parse(subIAdminAgent[3]);
                                            newIAdminAgentCommission.SymbolID = int.Parse(subIAdminAgent[4]);
                                            newIAdminAgentCommission.Comission = double.Parse(subIAdminAgent[5]);
                                            newIAdminAgentCommission.IsDelete = bool.Parse(subIAdminAgent[6]);
                                            newIAdminAgentCommission.ParentCommission = double.Parse(subIAdminAgent[7]);
                                            newIAdminAgentCommission.ChildCommission = double.Parse(subIAdminAgent[8]);
                                            newIAdminAgentCommission.ParentPipReBate = double.Parse(subIAdminAgent[9]);
                                            newIAdminAgentCommission.ChildPipReBate = double.Parse(subIAdminAgent[10]);

                                            #region UPDATE IADMINAGENT COMMISSION
                                            if (Business.Market.ListAgentConfig != null)
                                            {
                                                int count = Business.Market.ListAgentConfig.Count;
                                                for (int i = 0; i < count; i++)
                                                {
                                                    if (Business.Market.ListAgentConfig[i].AgentName.ToUpper().Trim() == code.ToUpper().Trim())
                                                    {
                                                        if (Business.Market.ListAgentConfig[i].ListIAdminAgentCommission != null)
                                                        {
                                                            int countIAdminAgentComm = Business.Market.ListAgentConfig[i].ListIAdminAgentCommission.Count;
                                                            for (int j = 0; j < countIAdminAgentComm; j++)
                                                            {
                                                                if (Business.Market.ListAgentConfig[i].ListIAdminAgentCommission[j].IParameterID ==
                                                                    newIAdminAgentCommission.IParameterID)
                                                                {
                                                                    Business.Market.ListAgentConfig[i].ListIAdminAgentCommission[j] = newIAdminAgentCommission;
                                                                    break;
                                                                }
                                                            }
                                                        }
                                                        break;
                                                    }
                                                }
                                            }
                                            #endregion
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    #endregion

                    #region UPDATE AGENT WITH AGENT COMMISSION
                    case "UpdateIAgentWithAgentCommission":
                        {
                            string[] subParameter = subValue[1].Split('[');
                            if (subParameter.Length > 0)
                            {
                                int countPara = subParameter.Length;
                                for (int n = 0; n < countPara; n++)
                                {
                                    if (!string.IsNullOrEmpty(subParameter[n]))
                                    {
                                        string[] subIAdminAgent = subParameter[n].Split('{');
                                        if (subIAdminAgent.Length > 0)
                                        {
                                            TradingServer.Agent.IParameterCommission newIAdminAgentCommission = new TradingServer.Agent.IParameterCommission();
                                            newIAdminAgentCommission.IParameterID = int.Parse(subIAdminAgent[0]);
                                            newIAdminAgentCommission.FirstParameterID = int.Parse(subIAdminAgent[1]);
                                            newIAdminAgentCommission.SecondParameterID = int.Parse(subIAdminAgent[2]);
                                            newIAdminAgentCommission.GroupID = int.Parse(subIAdminAgent[3]);
                                            newIAdminAgentCommission.SymbolID = int.Parse(subIAdminAgent[4]);
                                            newIAdminAgentCommission.Comission = double.Parse(subIAdminAgent[5]);
                                            newIAdminAgentCommission.IsDelete = bool.Parse(subIAdminAgent[6]);
                                            newIAdminAgentCommission.ParentCommission = double.Parse(subIAdminAgent[7]);
                                            newIAdminAgentCommission.ChildCommission = double.Parse(subIAdminAgent[8]);
                                            newIAdminAgentCommission.ParentPipReBate = double.Parse(subIAdminAgent[9]);
                                            newIAdminAgentCommission.ChildPipReBate = double.Parse(subIAdminAgent[10]);

                                            #region UPDATE IADMINAGENT COMMISSION
                                            if (Business.Market.ListAgentConfig != null)
                                            {
                                                int count = Business.Market.ListAgentConfig.Count;
                                                for (int i = 0; i < count; i++)
                                                {
                                                    if (Business.Market.ListAgentConfig[i].AgentName.ToUpper().Trim() == code.ToUpper().Trim())
                                                    {
                                                        if (Business.Market.ListAgentConfig[i].ListIAgentWithAgentCommission != null)
                                                        {
                                                            int countIAdminAgentComm = Business.Market.ListAgentConfig[i].ListIAgentWithAgentCommission.Count;
                                                            for (int j = 0; j < countIAdminAgentComm; j++)
                                                            {
                                                                if (Business.Market.ListAgentConfig[i].ListIAgentWithAgentCommission[j].IParameterID ==
                                                                    newIAdminAgentCommission.IParameterID)
                                                                {
                                                                    Business.Market.ListAgentConfig[i].ListIAgentWithAgentCommission[j] = newIAdminAgentCommission;
                                                                    break;
                                                                }
                                                            }
                                                        }
                                                        break;
                                                    }
                                                }
                                            }
                                            #endregion
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    #endregion

                    #region INSERT ADMIN AGENT COMMISSION
                    case "InsertIAdminAgentCommission":
                        {
                            bool isUpdate = false;
                            string[] subParameter = subValue[1].Split('[');
                            if (subParameter.Length > 0)
                            {
                                int countPara = subParameter.Length;
                                for (int n = 0; n < countPara; n++)
                                {
                                    if (!string.IsNullOrEmpty(subParameter[n]))
                                    {
                                        string[] subIAdminAgentComm = subParameter[n].Split('{');
                                        if (subIAdminAgentComm.Length > 0)
                                        {
                                            TradingServer.Agent.IParameterCommission newIAdminAgentCommission = new TradingServer.Agent.IParameterCommission();
                                            newIAdminAgentCommission.IParameterID = int.Parse(subIAdminAgentComm[0]);
                                            newIAdminAgentCommission.FirstParameterID = int.Parse(subIAdminAgentComm[1]);
                                            newIAdminAgentCommission.SecondParameterID = int.Parse(subIAdminAgentComm[2]);
                                            newIAdminAgentCommission.GroupID = int.Parse(subIAdminAgentComm[3]);
                                            newIAdminAgentCommission.SymbolID = int.Parse(subIAdminAgentComm[4]);
                                            newIAdminAgentCommission.Comission = double.Parse(subIAdminAgentComm[5]);
                                            newIAdminAgentCommission.IsDelete = bool.Parse(subIAdminAgentComm[6]);
                                            newIAdminAgentCommission.ParentCommission = double.Parse(subIAdminAgentComm[7]);
                                            newIAdminAgentCommission.ChildCommission = double.Parse(subIAdminAgentComm[8]);
                                            newIAdminAgentCommission.ParentPipReBate = double.Parse(subIAdminAgentComm[9]);
                                            newIAdminAgentCommission.ChildPipReBate = double.Parse(subIAdminAgentComm[10]);

                                            #region UPDATE IADMINAGENT COMMISSION
                                            if (Business.Market.ListAgentConfig != null)
                                            {
                                                int count = Business.Market.ListAgentConfig.Count;
                                                for (int i = 0; i < count; i++)
                                                {
                                                    if (Business.Market.ListAgentConfig[i].AgentName.ToUpper().Trim() == code.ToUpper().Trim())
                                                    {
                                                        if (Business.Market.ListAgentConfig[i].ListIAdminAgentCommission != null)
                                                        {
                                                            int countIAdminAgentComm = Business.Market.ListAgentConfig[i].ListIAdminAgentCommission.Count;
                                                            for (int j = 0; j < countIAdminAgentComm; j++)
                                                            {
                                                                if (Business.Market.ListAgentConfig[i].ListIAdminAgentCommission[j].IParameterID ==
                                                                    newIAdminAgentCommission.IParameterID)
                                                                {
                                                                    Business.Market.ListAgentConfig[i].ListIAdminAgentCommission[j] = newIAdminAgentCommission;
                                                                    isUpdate = true;
                                                                    break;
                                                                }
                                                            }
                                                        }

                                                        if (!isUpdate)
                                                        {
                                                            if (Business.Market.ListAgentConfig[i].ListIAdminAgentCommission == null)
                                                                Business.Market.ListAgentConfig[i].ListIAdminAgentCommission = new List<TradingServer.Agent.IParameterCommission>();
                                                            Business.Market.ListAgentConfig[i].ListIAdminAgentCommission.Add(newIAdminAgentCommission);
                                                        }

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

                    #region INSERT AGENT WITH AGENT COMMISSION
                    case "InsertIAgentWithAgentCommission":
                        {
                            bool isUpdate = false;
                            string[] subParameter = subValue[1].Split('[');
                            if (subParameter.Length > 0)
                            {
                                int countPara = subParameter.Length;
                                for (int n = 0; n < countPara; n++)
                                {
                                    if (!string.IsNullOrEmpty(subParameter[n]))
                                    {
                                        string[] subIAdminAgentComm = subParameter[n].Split('{');
                                        if (subIAdminAgentComm.Length > 1)
                                        {
                                            TradingServer.Agent.IParameterCommission newIAdminAgentCommission = new TradingServer.Agent.IParameterCommission();
                                            newIAdminAgentCommission.IParameterID = int.Parse(subIAdminAgentComm[0]);
                                            newIAdminAgentCommission.FirstParameterID = int.Parse(subIAdminAgentComm[1]);
                                            newIAdminAgentCommission.SecondParameterID = int.Parse(subIAdminAgentComm[2]);
                                            newIAdminAgentCommission.GroupID = int.Parse(subIAdminAgentComm[3]);
                                            newIAdminAgentCommission.SymbolID = int.Parse(subIAdminAgentComm[4]);
                                            newIAdminAgentCommission.Comission = double.Parse(subIAdminAgentComm[5]);
                                            newIAdminAgentCommission.IsDelete = bool.Parse(subIAdminAgentComm[6]);
                                            newIAdminAgentCommission.ParentCommission = double.Parse(subIAdminAgentComm[7]);
                                            newIAdminAgentCommission.ChildCommission = double.Parse(subIAdminAgentComm[8]);
                                            newIAdminAgentCommission.ParentPipReBate = double.Parse(subIAdminAgentComm[9]);
                                            newIAdminAgentCommission.ChildPipReBate = double.Parse(subIAdminAgentComm[10]);

                                            #region UPDATE IADMINAGENT COMMISSION
                                            if (Business.Market.ListAgentConfig != null)
                                            {
                                                int count = Business.Market.ListAgentConfig.Count;
                                                for (int i = 0; i < count; i++)
                                                {
                                                    if (Business.Market.ListAgentConfig[i].AgentName.ToUpper().Trim() == code.ToUpper().Trim())
                                                    {
                                                        if (Business.Market.ListAgentConfig[i].ListIAgentWithAgentCommission != null)
                                                        {
                                                            int countIAdminAgentComm = Business.Market.ListAgentConfig[i].ListIAgentWithAgentCommission.Count;
                                                            for (int j = 0; j < countIAdminAgentComm; j++)
                                                            {
                                                                if (Business.Market.ListAgentConfig[i].ListIAgentWithAgentCommission[j].IParameterID ==
                                                                    newIAdminAgentCommission.IParameterID)
                                                                {
                                                                    Business.Market.ListAgentConfig[i].ListIAgentWithAgentCommission[j] = newIAdminAgentCommission;
                                                                    isUpdate = true;
                                                                    break;
                                                                }
                                                            }
                                                        }

                                                        if (!isUpdate)
                                                        {
                                                            if (Business.Market.ListAgentConfig[i].ListIAgentWithAgentCommission == null)
                                                                Business.Market.ListAgentConfig[i].ListIAgentWithAgentCommission = new List<TradingServer.Agent.IParameterCommission>();

                                                            Business.Market.ListAgentConfig[i].ListIAgentWithAgentCommission.Add(newIAdminAgentCommission);
                                                        }

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

                    #region REMOVE IADMINAGENT COMMISSION
                    case "RemoveIAdminAgentCommission":
                        {
                            string[] subParameter = subValue[1].Split('[');
                            if (subParameter.Length > 0)
                            {
                                if (Business.Market.ListAgentConfig != null)
                                {
                                    int count = Business.Market.ListAgentConfig.Count;
                                    for (int i = 0; i < count; i++)
                                    {
                                        if (Business.Market.ListAgentConfig[i].AgentName.ToUpper().Trim() == code.ToUpper().Trim())
                                        {
                                            int countPara = subParameter.Length;
                                            for (int j = 0; j < countPara; j++)
                                            {
                                                if (string.IsNullOrEmpty(subParameter[j]))
                                                    continue;

                                                string[] subIAdminAgentComm = subParameter[j].Split('{');
                                                if (Business.Market.ListAgentConfig[i].ListIAdminAgentCommission != null)
                                                {
                                                    int countIAdminAgentComm = Business.Market.ListAgentConfig[i].ListIAdminAgentCommission.Count;
                                                    for (int n = 0; n < countIAdminAgentComm; n++)
                                                    {
                                                        if (Business.Market.ListAgentConfig[i].ListIAdminAgentCommission[n].IParameterID == int.Parse(subIAdminAgentComm[0]) &&
                                                            Business.Market.ListAgentConfig[i].ListIAdminAgentCommission[n].FirstParameterID == int.Parse(subIAdminAgentComm[1]) &&
                                                            Business.Market.ListAgentConfig[i].ListIAdminAgentCommission[n].SecondParameterID == int.Parse(subIAdminAgentComm[2]) &&
                                                            Business.Market.ListAgentConfig[i].ListIAdminAgentCommission[n].GroupID == int.Parse(subIAdminAgentComm[3]) &&
                                                            Business.Market.ListAgentConfig[i].ListIAdminAgentCommission[n].SymbolID == int.Parse(subIAdminAgentComm[4]))
                                                        {
                                                            Business.Market.ListAgentConfig[i].ListIAdminAgentCommission.RemoveAt(n);
                                                            break;
                                                        }
                                                    }
                                                }
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    #endregion

                    #region REMOVE IAGENTWITHAGENT COMMISSION
                    case "RemoveIAgentWithAgentCommission":
                        {
                            string[] subParameter = subValue[1].Split('[');
                            if (subParameter.Length > 0)
                            {
                                if (Business.Market.ListAgentConfig != null)
                                {
                                    int count = Business.Market.ListAgentConfig.Count;
                                    for (int i = 0; i < count; i++)
                                    {
                                        if (Business.Market.ListAgentConfig[i].AgentName.ToUpper().Trim() == code.ToUpper().Trim())
                                        {
                                            int countPara = subParameter.Length;
                                            for (int j = 0; j < countPara; j++)
                                            {
                                                if (!string.IsNullOrEmpty(subParameter[j]))
                                                {
                                                    string[] subIAgentWithAgentComm = subParameter[j].Split('{');

                                                    if (Business.Market.ListAgentConfig[i].ListIAgentWithAgentCommission != null)
                                                    {
                                                        int countIAdminAgentComm = Business.Market.ListAgentConfig[i].ListIAgentWithAgentCommission.Count;
                                                        for (int n = 0; n < countIAdminAgentComm; n++)
                                                        {
                                                            if (Business.Market.ListAgentConfig[i].ListIAgentWithAgentCommission[n].IParameterID == int.Parse(subIAgentWithAgentComm[0]) &&
                                                                Business.Market.ListAgentConfig[i].ListIAgentWithAgentCommission[n].FirstParameterID == int.Parse(subIAgentWithAgentComm[1]) &&
                                                                Business.Market.ListAgentConfig[i].ListIAgentWithAgentCommission[n].SecondParameterID == int.Parse(subIAgentWithAgentComm[2]) &&
                                                                Business.Market.ListAgentConfig[i].ListIAgentWithAgentCommission[n].GroupID == int.Parse(subIAgentWithAgentComm[3]) &&
                                                                Business.Market.ListAgentConfig[i].ListIAgentWithAgentCommission[n].SymbolID == int.Parse(subIAgentWithAgentComm[4]))
                                                            {
                                                                Business.Market.ListAgentConfig[i].ListIAgentWithAgentCommission.RemoveAt(n);
                                                                break;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    #endregion

                    #region SET ISCONNECT AGENT
                    case "SetIsConnectAgent":
                        {
                            bool isConnect = bool.Parse(subValue[1]);
                            if (Business.Market.ListAgentConfig != null)
                            {
                                int count = Business.Market.ListAgentConfig.Count;
                                for (int i = 0; i < count; i++)
                                {
                                    if (Business.Market.ListAgentConfig[i].AgentName.ToUpper().Trim() == code.ToUpper().Trim())
                                    {
                                        Business.Market.ListAgentConfig[i].IsConnect = isConnect;
                                        break;
                                    }
                                }
                            }
                        }
                        break;
                    #endregion

                    case "AgentStop":
                        {
                            Business.Market.IsConnectAgent = false;
                            TradingServer.Facade.FacadeAddNewSystemLog(6, "Agent Stop", "[AgentStop]", "", "");
                        }
                        break;

                    #region UPDATE CITY OF INVESTOR
                    case "UpdateCityInvestor":
                        {
                            string[] subParameter = subValue[1].Split('|');

                            if (subParameter.Length == 2)
                            {
                                string[] subInvestor = subParameter[1].Split('{');
                                int countInvestor = subInvestor.Length;
                                for (int j = 0; j < countInvestor; j++)
                                {
                                    int investorID = int.Parse(subInvestor[j]);
                                    if (investorID > 0)
                                    {
                                        if (Business.Market.InvestorList != null)
                                        {
                                            int countInvestorMarket = Business.Market.InvestorList.Count;

                                            for (int n = 0; n < countInvestorMarket; n++)
                                            {
                                                if (Business.Market.InvestorList[n].InvestorID == investorID)
                                                {
                                                    Business.Market.InvestorList[n].City = subParameter[0];

                                                    Investor.DBWInvestorInstance.UpdateInvestor(Business.Market.InvestorList[n]);

                                                    //NOTIFY TO MANAGER THEN INVESTOR ACCOUNT UPDATE
                                                    TradingServer.Facade.FacadeSendNotifyManagerRequest(3, Business.Market.InvestorList[n]);
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    #endregion
                }
            }
        }