Esempio n. 1
0
        private List <BasicDailyDataInformation> analysisDataCSV(string s)
        {
            var lines = s.Split('\n');
            List <BasicDailyDataInformation> result = new List <BasicDailyDataInformation>();

            foreach (var l in lines)
            {
                Regex    regex   = new Regex("([\"'])(?:(?=(\\\\?))\\2.)*?\\1");
                var      matches = regex.Matches(l);
                string[] row     = new string[matches.Count];
                for (int i = 0; i < matches.Count; i++)
                {
                    row[i] = matches[i].Groups[0].Value.Trim('"');
                }
                if (row.Length != 9 || row[0] == "日期")
                {
                    continue;
                }
                var toAdd = new BasicDailyDataInformation()
                {
                    date        = row[0].getRidOfPostStar().getDateTimeFromStringMK(),
                    dealedStock = row[1].getDecimalFromString(),
                    volume      = row[2].getDecimalFromString(),
                    open        = row[3].getDecimalFromString(),
                    high        = row[4].getDecimalFromString(),
                    low         = row[5].getDecimalFromString(),
                    close       = row[6].getDecimalFromString(),
                    change      = row[7].getDecimalFromString(),
                    dealedOrder = row[8].getDecimalFromString()
                };
                result.Add(toAdd);
            }
            return(result);
        }
Esempio n. 2
0
        private List <BasicDailyDataInformation> fillInBasicDailyDataInformation(List <string[]> dataByRowsAndCols)
        {
            List <BasicDailyDataInformation> result = new List <BasicDailyDataInformation>();

            foreach (var row in dataByRowsAndCols)
            {
                if (row.Length != 9)
                {
                    continue;
                }
                var toAdd = new BasicDailyDataInformation()
                {
                    date        = row[0].getRidOfPostStar().getDateTimeFromStringMK(),
                    dealedStock = row[1].getDecimalFromString(),
                    volume      = row[2].getDecimalFromString(),
                    open        = row[3].getDecimalFromString(),
                    high        = row[4].getDecimalFromString(),
                    low         = row[5].getDecimalFromString(),
                    close       = row[6].getDecimalFromString(),
                    change      = row[7].getDecimalFromString(),
                    dealedOrder = row[8].getDecimalFromString()
                };
                result.Add(toAdd);
            }
            return(result);
        }
Esempio n. 3
0
        private string recordDataInWebBrowser(HtmlDocument doc, string checkingYM, string checkingID)
        {
            string resultYM = "";

            viewModel.acquiredData = BasicDailyDataInformation.ToTitle() + "\r\n";
            var         basicDailyDataList = Core.basicDailyDataManager.getBasicDailyData(currentMission.ID);
            var         fileStatusList     = Core.basicDailyDataManager.getFileStatus(currentMission.ID);
            HtmlElement IDHeader           = doc.GetElementById("stk_no");

            HtmlElement resultTable = getResultTable(doc);

            if (resultTable == null)
            {
                return("");
            }
            List <BasicDailyDataInformation> analyzedDataList = analysisDataTable(resultTable.InnerHtml);
            FileStatus currentFileStatus = getCurrentFileStatus(analyzedDataList);

            if ((currentFileStatus != FileStatus.Null &&
                 checkingYM == analyzedDataList.First().date.ToString("yyyyMM") &&
                 IDHeader.InnerHtml.Contains(checkingID)) ||
                currentFileStatus == FileStatus.Null && ++nullcount >= 4)
            {
                nullcount = 0;
                renewFileStatus(fileStatusList, currentFileStatus, analyzedDataList.Count);
                renewBasicDailyDataList(basicDailyDataList, analyzedDataList);
                Core.basicDailyDataManager.saveBasicDailyData(currentMission.ID, basicDailyDataList);
                Core.basicDailyDataManager.saveFileStatus(currentMission.ID, fileStatusList);
                missionList.Remove(currentMission);
                missionListB.RemoveAt(0);
                missionList.Remove(currentMission);
                currentMission = null;
            }
            return(resultYM);
        }
Esempio n. 4
0
        public void startMainMissionLoop()
        {
            missionStartTime       = DateTime.Now;
            viewModel.acquiredData = BasicDailyDataInformation.ToTitle();

            missionListA = missionList.Where(x => x.type == "A").ToList();
            missionListB = missionList.Where(x => x.type == "B").ToList();

            Thread.Sleep(100);


            currentWebSiteStockType = "A";
            currentMission          = null;

            DateTime missionAssignedTime = DateTime.Now;
            int      nullcount           = 0;

            while (missionListA.Count > 0)
            {
                currentMission = missionListA.First();
                printMissionList();
                Application.DoEvents();
                var basicDailyDataList = Core.basicDailyDataManager.getBasicDailyData(currentMission.ID);
                var fileStatusList     = Core.basicDailyDataManager.getFileStatus(currentMission.ID);

                printMissionList();
                var s = GetCSV(
                    $"http://www.tse.com.tw/exchangeReport/STOCK_DAY?response=csv&date={currentMission.year}{currentMission.month.ToString("D2")}01&stockNo={currentMission.ID}");

                List <BasicDailyDataInformation> analyzedDataList = analysisDataCSV(s);
                FileStatus currentFileStatus = getCurrentFileStatus(analyzedDataList);

                if ((currentFileStatus != FileStatus.Null) || nullcount > 3)
                {
                    renewFileStatus(fileStatusList, currentFileStatus, analyzedDataList.Count);
                    renewBasicDailyDataList(basicDailyDataList, analyzedDataList);
                    Core.basicDailyDataManager.saveBasicDailyData(currentMission.ID, basicDailyDataList);
                    Core.basicDailyDataManager.saveFileStatus(currentMission.ID, fileStatusList);
                    missionList.Remove(currentMission);
                    missionListA.RemoveAt(0);
                    currentMission = null;
                    nullcount      = 0;
                }
                else
                {
                    nullcount++;
                }
                printMissionList();
            }

            webBrowser.Navigate(@"http://www.tpex.org.tw/web/stock/aftertrading/daily_trading_info/st43.php?l=zh-tw");

            while (missionListB.Count > 0)
            {
                Application.DoEvents();
                if (currentMission == null)
                {
                    currentMission = missionListB.First();
                    printMissionList();
                }

                bool isRetry = DateTime.Now.Subtract(missionAssignedTime).TotalSeconds > 4;
                if (isRetry)
                {
                    webBrowser.Navigate(@"http://www.tpex.org.tw/web/stock/aftertrading/daily_trading_info/st43.php?l=zh-tw");
                    missionAssignedTime = DateTime.Now;
                    querySend           = false;
                }

                if (!querySend && webBrowser.ReadyState == WebBrowserReadyState.Complete)
                {
                    missionAssignedTime = DateTime.Now;
                    querySend           = true;
                    selectIDandDateThenDoQueryB();
                }
            }
            printMissionList();
        }