Ejemplo n.º 1
0
        private List<ConfigFile> getConfigFileList(String dir, String extension)
        {
            DirectoryInfo di = new DirectoryInfo(dir);

            List<ConfigFile> fileList = new List<ConfigFile>();

            FileInfo[] rgFiles = di.GetFiles(extension);

            foreach (FileInfo fi in rgFiles)
            {
                //Console.WriteLine("FileName:" + fi.Name);
                ConfigFile oFile = new ConfigFile(dir + "/" + fi.Name);
                fileList.Add(oFile);
            }

            return fileList;
        }
Ejemplo n.º 2
0
        public string dealTradeCode(string monthFilePath, string code, string month, string year)//計算當天的商品代碼
        {
            try
            {
                monthFile = new ConfigFile(monthFilePath);
            }
            catch (Exception e)
            {
                throw e;
            }

            return dealTradeCode(code, month, year);
        }
Ejemplo n.º 3
0
        private void Form1_Load(object sender, EventArgs e)
        {


            this.yuantaOrderAPI = new YuantaOrdClass();

            try
            {
                yuantaOrderAPI.OnLogonS += new _DYuantaOrdEvents_OnLogonSEventHandler(yuantaOrderAPI_OnLogonS);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            timer1.Enabled = false;

            label_Version.Text = TradeUtility.TradeUtility.version;

            appDir = System.Windows.Forms.Application.StartupPath;

            trackFileDir = appDir + "\\" + Track_Dir + "\\";

            FileManager fm = new FileManager();

            trackFileList = fm.getConfigFileList(trackFileDir);

            configFilePath = appDir + "\\" + Config_Dir + "\\" + Config_File_Name;

            try
            {

                configFile = new ConfigFile(configFilePath);

            }
            catch (Exception ex)
            {
                MessageBox.Show("讀取  設定檔  失敗。原因 : " + ex.Message);

                return;
            }

            tradeCode = configFile.readConfig("Trade_Code");

            string tradeMonth = configFile.readConfig("Trade_Month");

            string tradeYear = configFile.readConfig("Trade_Year");

            string tradeMonthFilePath = appDir + "\\" + Config_Dir + "\\" + Month_File_Name;

            try
            {

                tradeCode = TradeUtility.TradeUtility.getInstance().dealTradeCode(tradeMonthFilePath, tradeCode, tradeMonth, tradeYear);

            }
            catch (Exception ex)
            {

                MessageBox.Show("讀取  月份代碼檔  失敗。原因 : " + ex.Message);

                return;
            }

            ipQuote = configFile.readConfig("IP_Quote");

            id = configFile.readConfig("ID");

            password = configFile.readConfig("Password");

            ipAPI = configFile.readConfig("IP_API");

            port = configFile.readConfig("Port");

            lots = configFile.readConfig("Lots");

            maxLoss = configFile.readConfig("Max_Loss");

            branchCode = configFile.readConfig("Branch_Code");

            account = configFile.readConfig("Account_Code");

            futuresCode = configFile.readConfig("Futures_Code");

            lotLimit = configFile.readConfig("Lot_Limit");

            try
            {

                master = new TradeMaster(this);

                master.setLotLimit(Convert.ToInt16(lotLimit));

                master.setFuturesCode(futuresCode);

                master.setMaxLoss(Convert.ToInt32(maxLoss));

                master.setID(id);

                master.setPassword(password);

                master.setBranchCode(branchCode);

                master.setAccount(account);

                master.setLots(lots);

                master.setIpAPI(ipAPI);

                master.setOrderAPI(yuantaOrderAPI);

                master.setTradeCode(tradeCode);

                master.prepareFirst();

                master.prepareTrackFile();

                readTrackFile(master);

                master.prepareDataFromLastTradeDay();

            }
            catch (Exception ez)
            {
                MessageBox.Show(ez.Message + "--" + ez.StackTrace);

                return;
            }

            textBox_loseLine.Text = Convert.ToString(master.getLoseLine()[1]);

            textBox1_winLine.Text = Convert.ToString(master.getWinLine()[1]);

            textBox_reverseLine.Text = Convert.ToString(master.getReverseLine()[1]);

            textBox_B_S.Text = master.OrderDircetion;

            textBox_MaxPrice.Text = Convert.ToString(master.MaxTradePointLastDay);

            textBox_MinPrice.Text = Convert.ToString(master.MinTradePointLastDay);

            textBox_OrderPrice.Text = Convert.ToString(master.OrderPrice);

            textBox_OrderStart.Text = Convert.ToString(master.IsStartOrder);

            textBox_NowTradeType.Text = master.NowTradeType;

            if (master.OrderNewPriceList != null)
            {
                for (int i = 0; i < master.OrderNewPriceList.Count; i++)
                {
                    textBox_OrderNewPriceList.Text += master.OrderNewPriceList[i] + Environment.NewLine;
                }
            }



            loginQuote();

            loginOrder();

        }
Ejemplo n.º 4
0
        public Boolean prepareTest()
        {

            appDir = System.IO.Directory.GetCurrentDirectory(); //主程式所在目錄

            appDir = System.Windows.Forms.Application.StartupPath;

            string configFilePath = appDir + "\\" + Config_Dir + "\\" + Config_File_Name;

            ConfigFile configFile = new ConfigFile(configFilePath);
            try
            {
                configFile.prepareReader();

                coreMethod = configFile.readConfig("Core_Method");
                ruleCountWin = Convert.ToInt32(configFile.readConfig("Rule_Count_Win"));
                ruleCountLose = Convert.ToInt32(configFile.readConfig("Rule_Count_Lose"));

                string strRuleCountReverse = "Rule_Count_Reverse_";

                for (int i = 1; i <= 10; i++)
                {

                    ruleCountReverse[i - 1] = Convert.ToInt32(configFile.readConfig(strRuleCountReverse + Convert.ToString(i)));

                }

                runCount = Convert.ToInt32(configFile.readConfig("Run_Count"));
                rulePeriod = Convert.ToInt32(configFile.readConfig("Rule_Period"));

                maxLoss = configFile.readConfig("Max_Loss");
                sourceDir = configFile.readConfig("Source_Dir");
                ratio = Convert.ToDouble(configFile.readConfig("Ratio"));
                lotLimit = Convert.ToInt32(configFile.readConfig("Lot_Limit"));

                checkCount = Convert.ToInt32(configFile.readConfig("Check_Count"));

                reversePeriod = Convert.ToDouble(configFile.readConfig("Reverse_Period"));

                if (null == sourceDir)
                {
                    sourceDir = Source_Dir;
                }

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.Source);
                Console.WriteLine(e.StackTrace);
                return false;
            }

            List<int> lotList = new List<int>();

            try
            {

                lots = configFile.readConfig("Lots");

                lotArray = lots.Split(',');

            }
            catch (Exception ee)
            {
                Console.WriteLine(ee.StackTrace);
            }

            //-----------------------------------------------------------------------------------------------------------------------------------
            //-----------------------------------------------------------------------------------------------------------------------------------

            StrategyFile strategyInstance = StrategyFile.getInstance();



            Boolean isRuleReady = false;

            if (TradeManager.Core_Method_1.Equals(coreMethod) || TradeManager.Core_Method_2.Equals(coreMethod))
            {

                isRuleReady = strategyInstance.dealStrategyRule(appDir, "TestStrategy.txt");

                this.winLine = strategyInstance.getWinLine();

                this.loseLine = strategyInstance.getLoseLine();

                this.reverseLine = strategyInstance.getReverseLine();

            }
            else if (TradeManager.Core_Method_3.Equals(coreMethod))
            {
                isRuleReady = strategyInstance.dealStopRatioRule(appDir, "TestStrategy.txt");

                this.stopRatio = strategyInstance.getStopRatio();
            }

            if (!isRuleReady)
            {
                return false;
            }


            //-----------------------------------------------------------------------------------------------------------------------------------
            //-----------------------------------------------------------------------------------------------------------------------------------

            reportDir = appDir + "\\" + Report_Dir + "\\";

            conclusionDir = appDir + "\\" + Conclusion_Dir + "\\";

            sourceFileDir = appDir + "\\" + sourceDir + "\\";




            conclusionReportFileName = conclusionDir + now.Year + "_" + now.Month + "_" + now.Day + "_" + now.Hour + "_" + now.Minute + "_" + now.Second + "_Conclusion.rpt";

            conclusionReport = new TradeFile(conclusionReportFileName);

            conclusionReport.prepareWriter();

            conclusionMsg("程式版本 :" + Version);

            conclusionMsg("說明 :" + Comment);

            conclusionMsg("使用核心:" + coreMethod);

            conclusionMsg("單日設定最大停損" + maxLoss);

            conclusionMsg("動態停利反轉比率:" + ratio);

            conclusionMsg("下單口數:" + lots);

            conclusionMsg("測試次數:" + runCount);

            conclusionMsg("確定買賣方向的檢查機制,時間間隔次數:" + checkCount);

            conclusionMsg("----------------------------------------------------------------------------------------------");


            if (stopRatio != null)
            {
                conclusionMsg("逆勢動態停利規則 : " + stopRatio.ToString());
            }

            return true;

        }