Example #1
0
        /// <summary>
        /// 初始化,入口
        /// </summary>
        /// <returns></returns>
        public static bool Initialize()
        {
            try
            {
                Common.Log(">>> Loading Configuration Settings...");
                //找配置文件
                if (!File.Exists(Common.Config()))
                {
                    Common.Log("Unaccessible Configuration File. [ " + Common.Config() + " ]");
                    return(false);
                }
                //加载交易开放时段配置
                if (!TimeSpan.TryParse(Common.Config("System", "BeginTimeAM"), out Common.BeginAMTS) ||
                    !TimeSpan.TryParse(Common.Config("System", "EndTimeAM"), out Common.EndAMTS) ||
                    !TimeSpan.TryParse(Common.Config("System", "BeginTimePM"), out Common.BeginPMTS) ||
                    !TimeSpan.TryParse(Common.Config("System", "EndTimePM"), out Common.EndPMTS) ||
                    Common.BeginAMTS >= Common.EndAMTS || Common.EndAMTS >= Common.BeginPMTS ||
                    Common.BeginPMTS >= Common.EndPMTS || Common.BeginAMTS.Hours < 1 || Common.EndPMTS.Hours > 22)
                {
                    Common.Log("<<< Illegal Configuration Settings [System:BeginTime/EndTime (01:00:00~22:59:59)].");
                    return(false);
                }
                else
                {
                    Common.Log("Stock Quotation Time: " + BeginAMTS.ToString() + " ~ " + EndAMTS.ToString()
                               + " / " + BeginPMTS.ToString() + " ~ " + EndPMTS.ToString());
                }
                //加载接口开放时段配置
                if (!TimeSpan.TryParse(Common.Config("System", "BeginInterface"), out Common.BeginTradingInterface) ||
                    !TimeSpan.TryParse(Common.Config("System", "EndInterface"), out Common.EndTradingInterface) ||
                    Common.BeginTradingInterface == Common.EndTradingInterface)
                {
                    Common.Log("<<< Illegal Configuration Settings [System:BeginInterface/EndInterface (00:00:00~23:59:59)].");
                    return(false);
                }
                else
                {
                    Common.Log("Interface Quotation Time: " + BeginTradingInterface.ToString() + " ~ " + EndTradingInterface.ToString());
                }
                //加载Debug日志开关配置
                string strDBG = Common.Config("System", "DebugLog").ToUpper().Trim();
                if (strDBG == "1" || strDBG == "TRUE" || strDBG == "T" ||
                    strDBG == "YES" || strDBG == "Y" || strDBG == "OPEN" || strDBG == "OPENED")
                {
                    Common.DbgLog = true;
                }
                //加载假日列表配置
                string   strHoliday = "";
                DateTime dtHoliday  = DateTime.MinValue;
                listHolidays.Clear();
                for (int i = 0; i < 100; i++)
                {
                    strHoliday = Common.Config("System", "Holiday-" + i.ToString("00").Trim());
                    if (strHoliday.Length > 0 && DateTime.TryParse(strHoliday, out dtHoliday))
                    {
                        listHolidays.Add(dtHoliday.Date);
                    }
                }
                //加载关联webService配置
                if (!int.TryParse(Common.Config("WebService", "WSPlayID"), out WebService_PlayID))
                {
                    WebService_PlayID = 0;
                }
                Common.OrderNotifier.Url = Common.Config("WebService", "OrderNotifier");
                Common.UserWealthSvc.Url = Common.Config("WebService", "UserWealthSvc");
                //加载数据库连接字串配置
                Common.strConn = Common.Config("Database", "Connection").Trim();
                if (Common.strConn.Length <= 0)
                {
                    Common.Log("<<< Illegal Configuration Settings [Database:Connection].");
                    return(false);
                }
                //加载上证、深证行情源配置
                Common.strSHQuotation = Common.Config("Quotation", "Shanghai");
                Common.strSZQuotation = Common.Config("Quotation", "Shenzhen");
                if (Common.strSHQuotation.Length <= 0 || !File.Exists(Common.strSHQuotation) ||
                    Common.strSZQuotation.Length <= 0 || !File.Exists(Common.strSZQuotation))
                {
                    Common.Log("<<< Illegal Configuration Settings [Quotation:Shanghai/Shenzhen].");
                    return(false);
                }
                //加载实时行情文件存放配置
                Common.strQuotationHistory = Common.Config("Quotation", "History");
                if (Common.strQuotationHistory.Length <= 0 || !Directory.Exists(Common.strQuotationHistory))
                {
                    Common.Log("<<< Illegal Configuration Settings [Quotation:History].");
                    return(false);
                }
                //加载最大订单数配置
                if (!short.TryParse(Common.Config("Trading", "MaxOrders"), out Common.MaxOrders) ||
                    Common.MaxOrders < 16 || Common.MaxOrders > 256)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:MaxOrders (16~256)].");
                    return(false);
                }
                //缓存构造初始化
                Common.stkBuffer = new StkBuffer();
                if (Common.stkBuffer.Initialize())
                {
                    Common.Log("Interface Buffer Initialized");
                }
                else
                {
                    Common.Log("Failed to Initialize The Interface Buffer");
                    return(false);
                }
                //交易系统构造
                Common.stkTrading = new TradingSystem();
                #region 加载初始资金配置
                double.TryParse(Common.Config("Trading", "InitAUD"), out Common.stkTrading.defaultAUD);
                if (Common.stkTrading.defaultAUD < 0 || Common.stkTrading.defaultAUD > (double)1000 * 1000 * 1000)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:InitAUD (0~1,000,000,000)].");
                    return(false);
                }
                double.TryParse(Common.Config("Trading", "InitCAD"), out Common.stkTrading.defaultCAD);
                if (Common.stkTrading.defaultCAD < 0 || Common.stkTrading.defaultCAD > (double)1000 * 1000 * 1000)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:InitCAD (0~1,000,000,000)].");
                    return(false);
                }
                double.TryParse(Common.Config("Trading", "InitCHF"), out Common.stkTrading.defaultCHF);
                if (Common.stkTrading.defaultCHF < 0 || Common.stkTrading.defaultCHF > (double)1000 * 1000 * 1000)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:InitCHF (0~1,000,000,000)].");
                    return(false);
                }
                double.TryParse(Common.Config("Trading", "InitEUR"), out Common.stkTrading.defaultEUR);
                if (Common.stkTrading.defaultEUR < 0 || Common.stkTrading.defaultEUR > (double)1000 * 1000 * 1000)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:InitEUR (0~1,000,000,000)].");
                    return(false);
                }
                double.TryParse(Common.Config("Trading", "InitGBP"), out Common.stkTrading.defaultGBP);
                if (Common.stkTrading.defaultGBP < 0 || Common.stkTrading.defaultGBP > (double)1000 * 1000 * 1000)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:InitGBP (0~1,000,000,000)].");
                    return(false);
                }
                double.TryParse(Common.Config("Trading", "InitHKD"), out Common.stkTrading.defaultHKD);
                if (Common.stkTrading.defaultHKD < 0 || Common.stkTrading.defaultHKD > (double)1000 * 1000 * 1000)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:InitHKD (0~1,000,000,000)].");
                    return(false);
                }
                double.TryParse(Common.Config("Trading", "InitJPY"), out Common.stkTrading.defaultJPY);
                if (Common.stkTrading.defaultJPY < 0 || Common.stkTrading.defaultJPY > (double)1000 * 1000 * 1000)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:InitJPY (0~1,000,000,000)].");
                    return(false);
                }
                double.TryParse(Common.Config("Trading", "InitNZD"), out Common.stkTrading.defaultNZD);
                if (Common.stkTrading.defaultNZD < 0 || Common.stkTrading.defaultNZD > (double)1000 * 1000 * 1000)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:InitNZD (0~1,000,000,000)].");
                    return(false);
                }
                double.TryParse(Common.Config("Trading", "InitRMB"), out Common.stkTrading.defaultRMB);
                if (Common.stkTrading.defaultRMB < 0 || Common.stkTrading.defaultRMB > (double)1000 * 1000 * 1000)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:InitRMB (0~1,000,000,000)].");
                    return(false);
                }
                double.TryParse(Common.Config("Trading", "InitUSD"), out Common.stkTrading.defaultUSD);
                if (Common.stkTrading.defaultUSD < 0 || Common.stkTrading.defaultUSD > (double)1000 * 1000 * 1000)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:InitUSD (0~1,000,000,000)].");
                    return(false);
                }

                if (Common.stkTrading.defaultAUD < 1000 && Common.stkTrading.defaultCAD < 1000 &&
                    Common.stkTrading.defaultCHF < 1000 && Common.stkTrading.defaultEUR < 1000 &&
                    Common.stkTrading.defaultGBP < 1000 && Common.stkTrading.defaultHKD < 1000 &&
                    Common.stkTrading.defaultJPY < 1000 && Common.stkTrading.defaultNZD < 1000 &&
                    Common.stkTrading.defaultRMB < 1000 && Common.stkTrading.defaultUSD < 1000)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:InitFund (1000~1,000,000,000)].");
                    return(false);
                }
                #endregion
                //加载买入手续费配置
                double.TryParse(Common.Config("Trading", "BuyTax"), out Common.stkTrading.defaultBuyTax);
                if (Common.stkTrading.defaultBuyTax < 0 || Common.stkTrading.defaultBuyTax > 0.5)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:BuyTax (0~0.5)].");
                    return(false);
                }
                //加载卖出手续费配置
                double.TryParse(Common.Config("Trading", "SellTax"), out Common.stkTrading.defaultSellTax);
                if (Common.stkTrading.defaultSellTax < 0 || Common.stkTrading.defaultSellTax > 0.5)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:SellTax (0~0.5)].");
                    return(false);
                }
                //加载单股比例上限配置
                double.TryParse(Common.Config("Trading", "SingleRate"), out Common.stkTrading.defaultSingleStockRate);
                if (Common.stkTrading.defaultSingleStockRate < 0.01 || Common.stkTrading.defaultSingleStockRate > 10)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:SingleRate (0.01~10)].");
                    return(false);
                }
                //加载订单ID配置
                if (!int.TryParse(Common.Config("Trading", "InitOrderID"), out Common.stkTrading.nLastOrderID))
                {
                    Common.stkTrading.nLastOrderID = 0;
                }
                //交易系统启动
                if (!Common.stkTrading.Initialize())
                {
                    return(false);
                }
                //行情系统启动
                Common.stkQuotation = new Quotation();
                if (!Common.stkQuotation.Initialize())
                {
                    return(false);
                }

                #region 接口开关
                #region 添加型
                //添加新用户开关
                string strReq = Common.Config("Interface", "NewUser").ToUpper().Trim();
                if (strReq == "0" || strReq == "FALSE" || strReq == "F" ||
                    strReq == "NO" || strReq == "N" || strReq == "CLOSE" || strReq == "CLOSED")
                {
                    if (Common.Switch_NewUser)
                    {
                        Common.Log(" *** Interface-NewUser [Closed] *** ");
                    }
                    Common.Switch_NewUser = false;
                }
                else
                {
                    if (!Common.Switch_NewUser)
                    {
                        Common.Log(" *** Interface-NewUser [Opened] *** ");
                    }
                    Common.Switch_NewUser = true;
                }
                //添加即时定单开关
                strReq = Common.Config("Interface", "ImmediateOrder").ToUpper().Trim();
                if (strReq == "0" || strReq == "FALSE" || strReq == "F" ||
                    strReq == "NO" || strReq == "N" || strReq == "CLOSE" || strReq == "CLOSED")
                {
                    if (Common.Switch_ImmediateOrder)
                    {
                        Common.Log(" *** Interface-ImmediateOrder [Closed] *** ");
                    }
                    Common.Switch_ImmediateOrder = false;
                }
                else
                {
                    if (!Common.Switch_ImmediateOrder)
                    {
                        Common.Log(" *** Interface-ImmediateOrder [Opened] *** ");
                    }
                    Common.Switch_ImmediateOrder = true;
                }
                //添加限价定单开关
                strReq = Common.Config("Interface", "LimitedOrder").ToUpper().Trim();
                if (strReq == "0" || strReq == "FALSE" || strReq == "F" ||
                    strReq == "NO" || strReq == "N" || strReq == "CLOSE" || strReq == "CLOSED")
                {
                    if (Common.Switch_LimitedOrder)
                    {
                        Common.Log(" *** Interface-LimitedOrder [Closed] *** ");
                    }
                    Common.Switch_LimitedOrder = false;
                }
                else
                {
                    if (!Common.Switch_LimitedOrder)
                    {
                        Common.Log(" *** Interface-LimitedOrder [Opened] *** ");
                    }
                    Common.Switch_LimitedOrder = true;
                }
                //添加取消定单开关
                strReq = Common.Config("Interface", "CancelOrder").ToUpper().Trim();
                if (strReq == "0" || strReq == "FALSE" || strReq == "F" ||
                    strReq == "NO" || strReq == "N" || strReq == "CLOSE" || strReq == "CLOSED")
                {
                    if (Common.Switch_CancelOrder)
                    {
                        Common.Log(" *** Interface-CancelOrder [Closed] *** ");
                    }
                    Common.Switch_CancelOrder = false;
                }
                else
                {
                    if (!Common.Switch_CancelOrder)
                    {
                        Common.Log(" *** Interface-CancelOrder [Opened] *** ");
                    }
                    Common.Switch_CancelOrder = true;
                }
                #endregion
                #region 请求型
                strReq = Common.Config("Interface", "UserFund").ToUpper().Trim();
                if (strReq == "0" || strReq == "FALSE" || strReq == "F" ||
                    strReq == "NO" || strReq == "N" || strReq == "CLOSE" || strReq == "CLOSED")
                {
                    if (Common.Switch_UserFund)
                    {
                        Common.Log(" *** Interface-UserFund [Closed] *** ");
                    }
                    Common.Switch_UserFund = false;
                }
                else
                {
                    if (!Common.Switch_UserFund)
                    {
                        Common.Log(" *** Interface-UserFund [Opened] *** ");
                    }
                    Common.Switch_UserFund = true;
                }

                strReq = Common.Config("Interface", "UserOrders").ToUpper().Trim();
                if (strReq == "0" || strReq == "FALSE" || strReq == "F" ||
                    strReq == "NO" || strReq == "N" || strReq == "CLOSE" || strReq == "CLOSED")
                {
                    if (Common.Switch_UserOrders)
                    {
                        Common.Log(" *** Interface-UserOrders [Closed] *** ");
                    }
                    Common.Switch_UserOrders = false;
                }
                else
                {
                    if (!Common.Switch_UserOrders)
                    {
                        Common.Log(" *** Interface-UserOrders [Opened] *** ");
                    }
                    Common.Switch_UserOrders = true;
                }

                strReq = Common.Config("Interface", "UserStocks").ToUpper().Trim();
                if (strReq == "0" || strReq == "FALSE" || strReq == "F" ||
                    strReq == "NO" || strReq == "N" || strReq == "CLOSE" || strReq == "CLOSED")
                {
                    if (Common.Switch_UserStocks)
                    {
                        Common.Log(" *** Interface-UserStocks [Closed] *** ");
                    }
                    Common.Switch_UserStocks = false;
                }
                else
                {
                    if (!Common.Switch_UserStocks)
                    {
                        Common.Log(" *** Interface-UserStocks [Opened] *** ");
                    }
                    Common.Switch_UserStocks = true;
                }

                strReq = Common.Config("Interface", "UserTrades").ToUpper().Trim();
                if (strReq == "0" || strReq == "FALSE" || strReq == "F" ||
                    strReq == "NO" || strReq == "N" || strReq == "CLOSE" || strReq == "CLOSED")
                {
                    if (Common.Switch_UserTrades)
                    {
                        Common.Log(" *** Interface-UserTrades [Closed] *** ");
                    }
                    Common.Switch_UserTrades = false;
                }
                else
                {
                    if (!Common.Switch_UserTrades)
                    {
                        Common.Log(" *** Interface-UserTrades [Opened] *** ");
                    }
                    Common.Switch_UserTrades = true;
                }

                strReq = Common.Config("Interface", "UserFundChanges").ToUpper().Trim();
                if (strReq == "0" || strReq == "FALSE" || strReq == "F" ||
                    strReq == "NO" || strReq == "N" || strReq == "CLOSE" || strReq == "CLOSED")
                {
                    if (Common.Switch_UserFundChanges)
                    {
                        Common.Log(" *** Interface-UserFundChanges [Closed] *** ");
                    }
                    Common.Switch_UserFundChanges = false;
                }
                else
                {
                    if (!Common.Switch_UserFundChanges)
                    {
                        Common.Log(" *** Interface-UserFundChanges [Opened] *** ");
                    }
                    Common.Switch_UserFundChanges = true;
                }
                #endregion
                #region 管理型
                strReq = Common.Config("Interface", "ServiceStatus").ToUpper().Trim();
                if (strReq == "0" || strReq == "FALSE" || strReq == "F" ||
                    strReq == "NO" || strReq == "N" || strReq == "CLOSE" || strReq == "CLOSED")
                {
                    if (Common.Switch_ServiceStatus)
                    {
                        Common.Log(" *** Interface-ServiceStatus [Closed] *** ");
                    }
                    Common.Switch_ServiceStatus = false;
                }
                else
                {
                    if (!Common.Switch_ServiceStatus)
                    {
                        Common.Log(" *** Interface-ServiceStatus [Opened] *** ");
                    }
                    Common.Switch_ServiceStatus = true;
                }

                strReq = Common.Config("Interface", "ServiceConfiguration").ToUpper().Trim();
                if (strReq == "0" || strReq == "FALSE" || strReq == "F" ||
                    strReq == "NO" || strReq == "N" || strReq == "CLOSE" || strReq == "CLOSED")
                {
                    if (Common.Switch_Configuration)
                    {
                        Common.Log(" *** Interface-ServiceConfiguration [Closed] *** ");
                    }
                    Common.Switch_Configuration = false;
                }
                else
                {
                    if (!Common.Switch_Configuration)
                    {
                        Common.Log(" *** Interface-ServiceConfiguration [Opened] *** ");
                    }
                    Common.Switch_Configuration = true;
                }

                strReq = Common.Config("Interface", "ServiceMaintain").ToUpper().Trim();
                if (strReq == "0" || strReq == "FALSE" || strReq == "F" ||
                    strReq == "NO" || strReq == "N" || strReq == "CLOSE" || strReq == "CLOSED")
                {
                    if (Common.Switch_Maintain)
                    {
                        Common.Log(" *** Interface-ServiceMaintain [Closed] *** ");
                    }
                    Common.Switch_Maintain = false;
                }
                else
                {
                    if (!Common.Switch_Maintain)
                    {
                        Common.Log(" *** Interface-ServiceMaintain [Opened] *** ");
                    }
                    Common.Switch_Maintain = true;
                }
                #endregion
                #endregion
                //加载remoting配置
                RemotingConfiguration.Configure(Process.GetCurrentProcess().MainModule.FileName + ".config", false);
                Common.Log("Interface System Created");

                try
                {
                    OrderNotifier.Clear(WebService_PlayID);
                }
                catch
                { }
                Common.Log("<<< Configuration Settings Loaded.");
                return(true);
            }
            catch (Exception err)
            {
                Common.Log(err);
                return(false);
            }
        }
Example #2
0
        /// <summary>
        /// ��ʼ�������
        /// </summary>
        /// <returns></returns>
        public static bool Initialize()
        {
            try
            {
                Common.Log(">>> Loading Configuration Settings...");
                //�������ļ�
                if (!File.Exists(Common.Config()))
                {
                    Common.Log("Unaccessible Configuration File. [ " + Common.Config() + " ]");
                    return false;
                }
                //���ؽ��׿���ʱ������
                if (!TimeSpan.TryParse(Common.Config("System", "BeginTimeAM"), out Common.BeginAMTS)
                    || !TimeSpan.TryParse(Common.Config("System", "EndTimeAM"), out Common.EndAMTS)
                    || !TimeSpan.TryParse(Common.Config("System", "BeginTimePM"), out Common.BeginPMTS)
                    || !TimeSpan.TryParse(Common.Config("System", "EndTimePM"), out Common.EndPMTS)
                    || Common.BeginAMTS >= Common.EndAMTS || Common.EndAMTS >= Common.BeginPMTS
                    || Common.BeginPMTS >= Common.EndPMTS || Common.BeginAMTS.Hours < 1 || Common.EndPMTS.Hours > 22)
                {
                    Common.Log("<<< Illegal Configuration Settings [System:BeginTime/EndTime (01:00:00~22:59:59)].");
                    return false;
                }
                else
                {
                    Common.Log("Stock Quotation Time: " + BeginAMTS.ToString() + " ~ " + EndAMTS.ToString()
                        + " / " + BeginPMTS.ToString() + " ~ " + EndPMTS.ToString());
                }
                //���ؽӿڿ���ʱ������
                if (!TimeSpan.TryParse(Common.Config("System", "BeginInterface"), out Common.BeginTradingInterface)
                    || !TimeSpan.TryParse(Common.Config("System", "EndInterface"), out Common.EndTradingInterface)
                    || Common.BeginTradingInterface == Common.EndTradingInterface)
                {
                    Common.Log("<<< Illegal Configuration Settings [System:BeginInterface/EndInterface (00:00:00~23:59:59)].");
                    return false;
                }
                else
                {
                    Common.Log("Interface Quotation Time: " + BeginTradingInterface.ToString() + " ~ " + EndTradingInterface.ToString());
                }
                //����Debug��־��������
                string strDBG = Common.Config("System", "DebugLog").ToUpper().Trim();
                if (strDBG == "1" || strDBG == "TRUE" || strDBG == "T" ||
                    strDBG == "YES" || strDBG == "Y" || strDBG == "OPEN" || strDBG == "OPENED")
                    Common.DbgLog = true;
                //���ؼ����б�����
                string strHoliday = "";
                DateTime dtHoliday = DateTime.MinValue;
                listHolidays.Clear();
                for (int i = 0; i < 100; i++)
                {
                    strHoliday = Common.Config("System", "Holiday-" + i.ToString("00").Trim());
                    if (strHoliday.Length > 0 && DateTime.TryParse(strHoliday, out dtHoliday))
                        listHolidays.Add(dtHoliday.Date);
                }
                //���ع���webService����
                if (!int.TryParse(Common.Config("WebService", "WSPlayID"), out WebService_PlayID))
                    WebService_PlayID = 0;
                Common.OrderNotifier.Url = Common.Config("WebService", "OrderNotifier");
                Common.UserWealthSvc.Url = Common.Config("WebService", "UserWealthSvc");
                //�������ݿ������ִ�����
                Common.strConn = Common.Config("Database", "Connection").Trim();
                if (Common.strConn.Length <= 0)
                {
                    Common.Log("<<< Illegal Configuration Settings [Database:Connection].");
                    return false;
                }
                //������֤����֤����Դ����
                Common.strSHQuotation = Common.Config("Quotation", "Shanghai");
                Common.strSZQuotation = Common.Config("Quotation", "Shenzhen");
                if (Common.strSHQuotation.Length <= 0 || !File.Exists(Common.strSHQuotation)
                    || Common.strSZQuotation.Length <= 0 || !File.Exists(Common.strSZQuotation))
                {
                    Common.Log("<<< Illegal Configuration Settings [Quotation:Shanghai/Shenzhen].");
                    return false;
                }
                //����ʵʱ�����ļ��������
                Common.strQuotationHistory = Common.Config("Quotation", "History");
                if (Common.strQuotationHistory.Length <= 0 || !Directory.Exists(Common.strQuotationHistory))
                {
                    Common.Log("<<< Illegal Configuration Settings [Quotation:History].");
                    return false;
                }
                //������󶩵�������
                if (!short.TryParse(Common.Config("Trading", "MaxOrders"), out Common.MaxOrders)
                    || Common.MaxOrders < 16 || Common.MaxOrders > 256)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:MaxOrders (16~256)].");
                    return false;
                }
                //���湹���ʼ��
                Common.stkBuffer = new StkBuffer();
                if (Common.stkBuffer.Initialize())
                {
                    Common.Log("Interface Buffer Initialized");
                }
                else
                {
                    Common.Log("Failed to Initialize The Interface Buffer");
                    return false;
                }
                //����ϵͳ����
                Common.stkTrading = new TradingSystem();
                #region ���س�ʼ�ʽ�����
                double.TryParse(Common.Config("Trading", "InitAUD"), out Common.stkTrading.defaultAUD);
                if (Common.stkTrading.defaultAUD < 0 || Common.stkTrading.defaultAUD > (double)1000 * 1000 * 1000)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:InitAUD (0~1,000,000,000)].");
                    return false;
                }
                double.TryParse(Common.Config("Trading", "InitCAD"), out Common.stkTrading.defaultCAD);
                if (Common.stkTrading.defaultCAD < 0 || Common.stkTrading.defaultCAD > (double)1000 * 1000 * 1000)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:InitCAD (0~1,000,000,000)].");
                    return false;
                }
                double.TryParse(Common.Config("Trading", "InitCHF"), out Common.stkTrading.defaultCHF);
                if (Common.stkTrading.defaultCHF < 0 || Common.stkTrading.defaultCHF > (double)1000 * 1000 * 1000)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:InitCHF (0~1,000,000,000)].");
                    return false;
                }
                double.TryParse(Common.Config("Trading", "InitEUR"), out Common.stkTrading.defaultEUR);
                if (Common.stkTrading.defaultEUR < 0 || Common.stkTrading.defaultEUR > (double)1000 * 1000 * 1000)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:InitEUR (0~1,000,000,000)].");
                    return false;
                }
                double.TryParse(Common.Config("Trading", "InitGBP"), out Common.stkTrading.defaultGBP);
                if (Common.stkTrading.defaultGBP < 0 || Common.stkTrading.defaultGBP > (double)1000 * 1000 * 1000)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:InitGBP (0~1,000,000,000)].");
                    return false;
                }
                double.TryParse(Common.Config("Trading", "InitHKD"), out Common.stkTrading.defaultHKD);
                if (Common.stkTrading.defaultHKD < 0 || Common.stkTrading.defaultHKD > (double)1000 * 1000 * 1000)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:InitHKD (0~1,000,000,000)].");
                    return false;
                }
                double.TryParse(Common.Config("Trading", "InitJPY"), out Common.stkTrading.defaultJPY);
                if (Common.stkTrading.defaultJPY < 0 || Common.stkTrading.defaultJPY > (double)1000 * 1000 * 1000)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:InitJPY (0~1,000,000,000)].");
                    return false;
                }
                double.TryParse(Common.Config("Trading", "InitNZD"), out Common.stkTrading.defaultNZD);
                if (Common.stkTrading.defaultNZD < 0 || Common.stkTrading.defaultNZD > (double)1000 * 1000 * 1000)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:InitNZD (0~1,000,000,000)].");
                    return false;
                }
                double.TryParse(Common.Config("Trading", "InitRMB"), out Common.stkTrading.defaultRMB);
                if (Common.stkTrading.defaultRMB < 0 || Common.stkTrading.defaultRMB > (double)1000 * 1000 * 1000)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:InitRMB (0~1,000,000,000)].");
                    return false;
                }
                double.TryParse(Common.Config("Trading", "InitUSD"), out Common.stkTrading.defaultUSD);
                if (Common.stkTrading.defaultUSD < 0 || Common.stkTrading.defaultUSD > (double)1000 * 1000 * 1000)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:InitUSD (0~1,000,000,000)].");
                    return false;
                }

                if (Common.stkTrading.defaultAUD < 1000 && Common.stkTrading.defaultCAD < 1000 &&
                    Common.stkTrading.defaultCHF < 1000 && Common.stkTrading.defaultEUR < 1000 &&
                    Common.stkTrading.defaultGBP < 1000 && Common.stkTrading.defaultHKD < 1000 &&
                    Common.stkTrading.defaultJPY < 1000 && Common.stkTrading.defaultNZD < 1000 &&
                    Common.stkTrading.defaultRMB < 1000 && Common.stkTrading.defaultUSD < 1000)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:InitFund (1000~1,000,000,000)].");
                    return false;
                }
                #endregion
                //������������������
                double.TryParse(Common.Config("Trading", "BuyTax"), out Common.stkTrading.defaultBuyTax);
                if (Common.stkTrading.defaultBuyTax < 0 || Common.stkTrading.defaultBuyTax > 0.5)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:BuyTax (0~0.5)].");
                    return false;
                }
                //�����������������
                double.TryParse(Common.Config("Trading", "SellTax"), out Common.stkTrading.defaultSellTax);
                if (Common.stkTrading.defaultSellTax < 0 || Common.stkTrading.defaultSellTax > 0.5)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:SellTax (0~0.5)].");
                    return false;
                }
                //���ص��ɱ�����������
                double.TryParse(Common.Config("Trading", "SingleRate"), out Common.stkTrading.defaultSingleStockRate);
                if (Common.stkTrading.defaultSingleStockRate < 0.01 || Common.stkTrading.defaultSingleStockRate > 10)
                {
                    Common.Log("<<< Illegal Configuration Settings [Trading:SingleRate (0.01~10)].");
                    return false;
                }
                //���ض���ID����
                if (!int.TryParse(Common.Config("Trading", "InitOrderID"), out Common.stkTrading.nLastOrderID))
                    Common.stkTrading.nLastOrderID = 0;
                //����ϵͳ���
                if (!Common.stkTrading.Initialize())
                {
                    return false;
                }
                //����ϵͳ���
                Common.stkQuotation = new Quotation();
                if (!Common.stkQuotation.Initialize())
                {
                    return false;
                }

                #region �ӿڿ���
                #region �����
                //������û�����
                string strReq = Common.Config("Interface", "NewUser").ToUpper().Trim();
                if (strReq == "0" || strReq == "FALSE" || strReq == "F" ||
                    strReq == "NO" || strReq == "N" || strReq == "CLOSE" || strReq == "CLOSED")
                {
                    if (Common.Switch_NewUser)
                        Common.Log(" *** Interface-NewUser [Closed] *** ");
                    Common.Switch_NewUser = false;
                }
                else
                {
                    if (!Common.Switch_NewUser)
                        Common.Log(" *** Interface-NewUser [Opened] *** ");
                    Common.Switch_NewUser = true;
                }
                //��Ӽ�ʱ��������
                strReq = Common.Config("Interface", "ImmediateOrder").ToUpper().Trim();
                if (strReq == "0" || strReq == "FALSE" || strReq == "F" ||
                    strReq == "NO" || strReq == "N" || strReq == "CLOSE" || strReq == "CLOSED")
                {
                    if (Common.Switch_ImmediateOrder)
                        Common.Log(" *** Interface-ImmediateOrder [Closed] *** ");
                    Common.Switch_ImmediateOrder = false;
                }
                else
                {
                    if (!Common.Switch_ImmediateOrder)
                        Common.Log(" *** Interface-ImmediateOrder [Opened] *** ");
                    Common.Switch_ImmediateOrder = true;
                }
                //����޼۶�������
                strReq = Common.Config("Interface", "LimitedOrder").ToUpper().Trim();
                if (strReq == "0" || strReq == "FALSE" || strReq == "F" ||
                    strReq == "NO" || strReq == "N" || strReq == "CLOSE" || strReq == "CLOSED")
                {
                    if (Common.Switch_LimitedOrder)
                        Common.Log(" *** Interface-LimitedOrder [Closed] *** ");
                    Common.Switch_LimitedOrder = false;
                }
                else
                {
                    if (!Common.Switch_LimitedOrder)
                        Common.Log(" *** Interface-LimitedOrder [Opened] *** ");
                    Common.Switch_LimitedOrder = true;
                }
                //���ȡ����������
                strReq = Common.Config("Interface", "CancelOrder").ToUpper().Trim();
                if (strReq == "0" || strReq == "FALSE" || strReq == "F" ||
                    strReq == "NO" || strReq == "N" || strReq == "CLOSE" || strReq == "CLOSED")
                {
                    if (Common.Switch_CancelOrder)
                        Common.Log(" *** Interface-CancelOrder [Closed] *** ");
                    Common.Switch_CancelOrder = false;
                }
                else
                {
                    if (!Common.Switch_CancelOrder)
                        Common.Log(" *** Interface-CancelOrder [Opened] *** ");
                    Common.Switch_CancelOrder = true;
                }
                #endregion
                #region ������
                strReq = Common.Config("Interface", "UserFund").ToUpper().Trim();
                if (strReq == "0" || strReq == "FALSE" || strReq == "F" ||
                    strReq == "NO" || strReq == "N" || strReq == "CLOSE" || strReq == "CLOSED")
                {
                    if (Common.Switch_UserFund)
                        Common.Log(" *** Interface-UserFund [Closed] *** ");
                    Common.Switch_UserFund = false;
                }
                else
                {
                    if (!Common.Switch_UserFund)
                        Common.Log(" *** Interface-UserFund [Opened] *** ");
                    Common.Switch_UserFund = true;
                }

                strReq = Common.Config("Interface", "UserOrders").ToUpper().Trim();
                if (strReq == "0" || strReq == "FALSE" || strReq == "F" ||
                    strReq == "NO" || strReq == "N" || strReq == "CLOSE" || strReq == "CLOSED")
                {
                    if (Common.Switch_UserOrders)
                        Common.Log(" *** Interface-UserOrders [Closed] *** ");
                    Common.Switch_UserOrders = false;
                }
                else
                {
                    if (!Common.Switch_UserOrders)
                        Common.Log(" *** Interface-UserOrders [Opened] *** ");
                    Common.Switch_UserOrders = true;
                }

                strReq = Common.Config("Interface", "UserStocks").ToUpper().Trim();
                if (strReq == "0" || strReq == "FALSE" || strReq == "F" ||
                    strReq == "NO" || strReq == "N" || strReq == "CLOSE" || strReq == "CLOSED")
                {
                    if (Common.Switch_UserStocks)
                        Common.Log(" *** Interface-UserStocks [Closed] *** ");
                    Common.Switch_UserStocks = false;
                }
                else
                {
                    if (!Common.Switch_UserStocks)
                        Common.Log(" *** Interface-UserStocks [Opened] *** ");
                    Common.Switch_UserStocks = true;
                }

                strReq = Common.Config("Interface", "UserTrades").ToUpper().Trim();
                if (strReq == "0" || strReq == "FALSE" || strReq == "F" ||
                    strReq == "NO" || strReq == "N" || strReq == "CLOSE" || strReq == "CLOSED")
                {
                    if (Common.Switch_UserTrades)
                        Common.Log(" *** Interface-UserTrades [Closed] *** ");
                    Common.Switch_UserTrades = false;
                }
                else
                {
                    if (!Common.Switch_UserTrades)
                        Common.Log(" *** Interface-UserTrades [Opened] *** ");
                    Common.Switch_UserTrades = true;
                }

                strReq = Common.Config("Interface", "UserFundChanges").ToUpper().Trim();
                if (strReq == "0" || strReq == "FALSE" || strReq == "F" ||
                    strReq == "NO" || strReq == "N" || strReq == "CLOSE" || strReq == "CLOSED")
                {
                    if (Common.Switch_UserFundChanges)
                        Common.Log(" *** Interface-UserFundChanges [Closed] *** ");
                    Common.Switch_UserFundChanges = false;
                }
                else
                {
                    if (!Common.Switch_UserFundChanges)
                        Common.Log(" *** Interface-UserFundChanges [Opened] *** ");
                    Common.Switch_UserFundChanges = true;
                }
                #endregion
                #region ������
                strReq = Common.Config("Interface", "ServiceStatus").ToUpper().Trim();
                if (strReq == "0" || strReq == "FALSE" || strReq == "F" ||
                    strReq == "NO" || strReq == "N" || strReq == "CLOSE" || strReq == "CLOSED")
                {
                    if (Common.Switch_ServiceStatus)
                        Common.Log(" *** Interface-ServiceStatus [Closed] *** ");
                    Common.Switch_ServiceStatus = false;
                }
                else
                {
                    if (!Common.Switch_ServiceStatus)
                        Common.Log(" *** Interface-ServiceStatus [Opened] *** ");
                    Common.Switch_ServiceStatus = true;
                }

                strReq = Common.Config("Interface", "ServiceConfiguration").ToUpper().Trim();
                if (strReq == "0" || strReq == "FALSE" || strReq == "F" ||
                    strReq == "NO" || strReq == "N" || strReq == "CLOSE" || strReq == "CLOSED")
                {
                    if (Common.Switch_Configuration)
                        Common.Log(" *** Interface-ServiceConfiguration [Closed] *** ");
                    Common.Switch_Configuration = false;
                }
                else
                {
                    if (!Common.Switch_Configuration)
                        Common.Log(" *** Interface-ServiceConfiguration [Opened] *** ");
                    Common.Switch_Configuration = true;
                }

                strReq = Common.Config("Interface", "ServiceMaintain").ToUpper().Trim();
                if (strReq == "0" || strReq == "FALSE" || strReq == "F" ||
                    strReq == "NO" || strReq == "N" || strReq == "CLOSE" || strReq == "CLOSED")
                {
                    if (Common.Switch_Maintain)
                        Common.Log(" *** Interface-ServiceMaintain [Closed] *** ");
                    Common.Switch_Maintain = false;
                }
                else
                {
                    if (!Common.Switch_Maintain)
                        Common.Log(" *** Interface-ServiceMaintain [Opened] *** ");
                    Common.Switch_Maintain = true;
                }
                #endregion
                #endregion
                //����remoting����
                RemotingConfiguration.Configure(Process.GetCurrentProcess().MainModule.FileName + ".config", false);
                Common.Log("Interface System Created");

                try
                {
                    OrderNotifier.Clear(WebService_PlayID);
                }
                catch
                { }
                Common.Log("<<< Configuration Settings Loaded.");
                return true;
            }
            catch (Exception err)
            {
                Common.Log(err);
                return false;
            }
        }