コード例 #1
0
        private static void ParseIntradayData(StockSerie stockSerie, string folder, string fileName)
        {
            try
             {
            if (File.Exists(folder + "\\" + fileName))
            {
               using (StreamReader sr = new StreamReader(folder + "\\" + fileName))
               {
                  string line = sr.ReadLine();
                  string[] row = line.Replace("\"", "").Replace(" - ", ",").Split(',');
                  if (row.Length == 7)
                  {
                     try
                     {
                        StockDailyValue dailyValue = new StockDailyValue(stockSerie.StockName,
                            float.Parse(row[2], usCulture),
                            float.Parse(row[4], usCulture),
                            float.Parse(row[3], usCulture),
                            float.Parse(row[5], usCulture),
                            long.Parse(row[6]),
                            DateTime.Parse(row[0] + " " + row[1], usCulture));

                        StockDailyValue lastValue = stockSerie.Values.Last();

                        if (lastValue.DATE.Date == dailyValue.DATE.Date)
                        {
                           if (lastValue.DATE.Hour == 0 && lastValue.DATE.Minute == 0) return;

                           stockSerie.Remove(lastValue.DATE);
                        }
                        stockSerie.Add(dailyValue.DATE, dailyValue);
                        stockSerie.ClearBarDurationCache();
                     }
                     catch (System.Exception e)
                     {
                        StockLog.Write("Unable to parse intraday data for " + stockSerie.StockName);
                        StockLog.Write(line);
                        StockLog.Write(e);
                     }
                  }
               }
            }
             }
             catch (System.Exception e)
             {
            StockLog.Write("Unable to parse intraday data for " + stockSerie.StockName);
            StockLog.Write(e);
             }
        }
コード例 #2
0
        public override bool DownloadDailyData(string rootFolder, StockSerie stockSerie)
        {
            StockLog.Write("DownloadDailyData Group: " + stockSerie.StockGroup + " - " + stockSerie.StockName);

            if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
            {
                bool isUpTodate = false;
                stockSerie.Initialise();
                if (stockSerie.Count > 0)
                {
                    DateTime lastDate = stockSerie.Keys.Last();
                    if (lastDate.TimeOfDay != TimeSpan.Zero)
                    {
                        stockSerie.Remove(lastDate);
                        lastDate = stockSerie.Keys.Last();
                    }

                    isUpTodate = (lastDate >= DateTime.Today) ||
                                 (lastDate.DayOfWeek == DayOfWeek.Friday && (DateTime.Now - lastDate).Days <= 3 &&
                                  (DateTime.Today.DayOfWeek == DayOfWeek.Monday && DateTime.Now.Hour < 18)) ||
                                 (lastDate == DateTime.Today.AddDays(-1) && DateTime.Now.Hour < 18);

                    if (!isUpTodate)
                    {
                        NotifyProgress("Downloading " + stockSerie.StockGroup.ToString() + " - " + stockSerie.StockName);

                        // Happy new year !!! it's time to archive old data...
                        for (int year = lastDate.Year; year < DateTime.Today.Year; year++)
                        {
                            if (
                               !File.Exists(rootFolder + ARCHIVE_FOLDER + "\\" + stockSerie.ShortName + "_" +
                                            stockSerie.StockName + "_" + stockSerie.StockGroup.ToString() + "_" +
                                            year.ToString() + ".csv"))
                            {
                                this.DownloadFileFromProvider(rootFolder + ARCHIVE_FOLDER,
                                   stockSerie.ShortName + "_" + stockSerie.StockName + "_" + stockSerie.StockGroup.ToString() +
                                   "_" + year.ToString() + ".csv", new DateTime(year, 1, 1), new DateTime(year, 12, 31),
                                   stockSerie.ShortName);
                            }
                        }
                        DateTime startDate = new DateTime(DateTime.Today.Year, 01, 01);
                        string fileName = stockSerie.ShortName + "_" + stockSerie.StockName + "_" +
                                          stockSerie.StockGroup.ToString() + ".csv";
                        this.DownloadFileFromProvider(rootFolder + ABC_DAILY_FOLDER, fileName, startDate, DateTime.Today,
                           stockSerie.ISIN);

                        if (stockSerie.StockName == "CAC40")
                        // Check if something new has been downloaded using CAC40 as the reference for all downloads
                        {
                            this.ParseCSVFile(stockSerie, rootFolder + ABC_DAILY_FOLDER + "\\" + fileName);
                            if (lastDate == stockSerie.Keys.Last())
                            {
                                this.needDownload = false;
                            }
                            else
                            {
                                DownloadMonthlyFileFromABC(rootFolder + ABC_DAILY_FOLDER, DateTime.Today, "eurolistap");
                                DownloadMonthlyFileFromABC(rootFolder + ABC_DAILY_FOLDER, DateTime.Today, "eurolistbp");
                                DownloadMonthlyFileFromABC(rootFolder + ABC_DAILY_FOLDER, DateTime.Today, "eurolistcp");
                                DownloadMonthlyFileFromABC(rootFolder + ABC_DAILY_FOLDER, DateTime.Today, "alterp");
                                //DownloadMonthlyFileFromABC(rootFolder + ABC_DAILY_FOLDER, DateTime.Today, "srdp");
                                DownloadMonthlyFileFromABC(rootFolder + ABC_DAILY_FOLDER, DateTime.Today, "sp500u");
                                DownloadMonthlyFileFromABC(rootFolder + ABC_DAILY_FOLDER, DateTime.Today, "indicessecp");
                            }
                        }
                    }
                    else
                    {
                        if (stockSerie.StockName == "CAC40")
                        // Check if something new has been downloaded using CAC40 as the reference for all downloads
                        {
                            this.needDownload = false;
                        }
                    }
                    stockSerie.IsInitialised = isUpTodate; // && !needReloadIntraday; Why need reload intraday ???
                }
                else
                {
                    NotifyProgress("Creating archive for " + stockSerie.StockName + " - " + stockSerie.StockGroup.ToString());
                    DateTime lastDate = new DateTime(DateTime.Today.Year, 01, 01);
                    if (stockSerie.StockName == "CAC40")
                    {
                        for (int m = DateTime.Today.Month - 1; m >= 1; m--)
                        {
                            DateTime month = new DateTime(lastDate.Year, m, 1);
                            DownloadMonthlyFileFromABC(rootFolder + ARCHIVE_FOLDER, month, "eurolistap");
                            DownloadMonthlyFileFromABC(rootFolder + ARCHIVE_FOLDER, month, "eurolistbp");
                            DownloadMonthlyFileFromABC(rootFolder + ARCHIVE_FOLDER, month, "eurolistcp");
                            DownloadMonthlyFileFromABC(rootFolder + ARCHIVE_FOLDER, month, "alterp");
                            //DownloadMonthlyFileFromABC(rootFolder + ARCHIVE_FOLDER, month, "srdp");
                            DownloadMonthlyFileFromABC(rootFolder + ARCHIVE_FOLDER, month, "sp500u");
                            DownloadMonthlyFileFromABC(rootFolder + ARCHIVE_FOLDER, month, "indicessecp");
                        }
                    }
                    for (int i = lastDate.Year - 1; i > ARCHIVE_START_YEAR; i--)
                    {
                        if (
                           !this.DownloadFileFromProvider(rootFolder + ARCHIVE_FOLDER,
                              stockSerie.ShortName + "_" + stockSerie.StockName + "_" + stockSerie.StockGroup.ToString() + "_" +
                              i.ToString() + ".csv", new DateTime(i, 1, 1), new DateTime(i, 12, 31), stockSerie.ISIN))
                        {
                            break;
                        }
                        if (stockSerie.StockName == "CAC40")
                        {
                            for (int m = 12; m >= 1; m--)
                            {
                                DateTime month = new DateTime(i, m, 1);
                                DownloadMonthlyFileFromABC(rootFolder + ARCHIVE_FOLDER, month, "eurolistap");
                                DownloadMonthlyFileFromABC(rootFolder + ARCHIVE_FOLDER, month, "eurolistbp");
                                DownloadMonthlyFileFromABC(rootFolder + ARCHIVE_FOLDER, month, "eurolistcp");
                                DownloadMonthlyFileFromABC(rootFolder + ARCHIVE_FOLDER, month, "alterp");
                                //DownloadMonthlyFileFromABC(rootFolder + ARCHIVE_FOLDER, month, "srdp");
                                DownloadMonthlyFileFromABC(rootFolder + ARCHIVE_FOLDER, month, "sp500u");
                                DownloadMonthlyFileFromABC(rootFolder + ARCHIVE_FOLDER, month, "indicessecp");
                            }
                        }
                    }
                    this.DownloadFileFromProvider(rootFolder + ABC_DAILY_FOLDER,
                       stockSerie.ShortName + "_" + stockSerie.StockName + "_" + stockSerie.StockGroup.ToString() + ".csv",
                       lastDate, DateTime.Today, stockSerie.ISIN);
                }
            }
            return true;
        }