示例#1
0
        //[TestMethod]
        public void TestDownloadHistoricalData()
        {
            const string symbol      = "MEG";
            const int    numYears    = 10;
            string       downloadStr = "http://www.pse.com.ph/servlet/PSEChartServlet?securitySymbol=%s&years=%f";

            downloadStr = downloadStr.Replace("%s", symbol).Replace("%f", numYears.ToString());

            var downloadUri = new Uri(downloadStr);
            var downloader  = new HistoricalDataDownloader(downloadUri);

            downloader.Download();

            HistoricalDataReader reader = downloader.GetReader();

            var outputSettings = new CSVOutputSettings();

            outputSettings.CSVFormat       = "S,D,O,H,L,C,V,F";
            outputSettings.Delimiter       = ",";
            outputSettings.OutputDirectory = "C:\\Users\\yeahbah\\Documents\\projects";
            outputSettings.Filename        = symbol + ".csv";
            outputSettings.DateFormat      = "MM/DD/YYYY";

            reader.ToCSV(outputSettings);
        }
示例#2
0
        public void TestDownloadHistoricalDataUsingUtil()
        {
            var stockList = new List <string>();

            stockList.Add("MEG");
            stockList.Add("DMC");
            stockList.Add("PX");
            stockList.Add("NIKL");
            stockList.Add("GEO");
            stockList.Add("SCC");
            stockList.Add("ALI");
            stockList.Add("AC");
            stockList.Add("EEI");
            stockList.Add("GERI");
            stockList.Add("FGEN");
            stockList.Add("FPH");
            stockList.Add("ANI");
            stockList.Add("ELI");
            stockList.Add("LPZ");
            stockList.Add("MUSX");
            stockList.Add("LC");

            var outputSettings = new CSVOutputSettings();

            outputSettings.CSVFormat       = "S,D,O,H,L,C,V,F";
            outputSettings.Delimiter       = ",";
            outputSettings.OutputDirectory = "C:\\Users\\yeahbah\\Documents\\projects";
            outputSettings.Filename        = "HistoricalData.csv";
            outputSettings.DateFormat      = "MM/DD/YYYY";


            //Util.DownloadAndConvertHistoricalData(stockList, 20, outputSettings,
            //    null);
        }
示例#3
0
        public void ToCSV(CSVOutputSettings outputSettings)
        {
            List <string> csvList = new List <string>();

            SetLists();
            for (int i = 0; i < this.openList.Count; i++)
            {
                string csvLine   = outputSettings.CSVFormat.Replace(",", outputSettings.Delimiter);
                string tradeDate = getTradeDate(dateList[i]).ToString(outputSettings.DateFormat);
                double volume    = getTradeVolume(volumeList[i]);
                if (this._symbol.Contains("^"))
                {
                    volume = volume / outputSettings.SectorVolumeDivider;
                }

                string tradeVolume = volume.ToString("0");

                csvLine = csvLine.Replace(CSVOutputSettings.STOCK_SYMBOL, this._symbol);
                csvLine = csvLine.Replace(CSVOutputSettings.DATE_SYMBOL, tradeDate);
                csvLine = csvLine.Replace(CSVOutputSettings.OPEN_SYMBOL, openList[i]);
                csvLine = csvLine.Replace(CSVOutputSettings.HIGH_SYMBOL, highList[i]);
                csvLine = csvLine.Replace(CSVOutputSettings.LOW_SYMBOL, lowList[i]);
                csvLine = csvLine.Replace(CSVOutputSettings.CLOSE_SYMBOL, closeList[i]);
                csvLine = csvLine.Replace(CSVOutputSettings.VOLUME_SYMBOL, tradeVolume);
                csvLine = csvLine.Replace(CSVOutputSettings.NFBS_SYMBOL, "0");

                csvList.Add(csvLine);
            }
            string fileName = outputSettings.OutputDirectory + Helpers.GetDirectorySeparator() +
                              outputSettings.Filename;

            this.SaveToFile(fileName, csvList);
        }
示例#4
0
        static void ConvertIt(string fileToConvert)
        {
            IPdfService      pdfService  = new PdfTextSharpService();
            var              pseDocument = new PSEDocument();
            IPSEReportReader reader      = new PSEReportReader2();

            reader.Fill(pseDocument, pdfService.ExtractTextFromPdf(fileToConvert));
            if (_outputFormat.Contains("csv"))
            {
                string[] csvParam  = _outputFormat.Split(':');
                string   csvFormat = string.Empty;
                if (csvParam.Length == 2)
                {
                    csvFormat = csvParam[1];
                    csvFormat = csvFormat.Replace("S", "{S}");
                    csvFormat = csvFormat.Replace("D", "{D}");
                    csvFormat = csvFormat.Replace("O", "{O}");
                    csvFormat = csvFormat.Replace("H", "{H}");
                    csvFormat = csvFormat.Replace("L", "{L}");
                    csvFormat = csvFormat.Replace("C", "{C}");
                    csvFormat = csvFormat.Replace("V", "{V}");
                    csvFormat = csvFormat.Replace("F", "{F}");
                }
                else
                {
                    csvFormat = "{S},{D},{O},{H},{L},{C},{V},{F}";
                }

                var csvOutputSettings = new CSVOutputSettings();
                csvOutputSettings.CSVFormat              = csvFormat;
                csvOutputSettings.DateFormat             = _dateFormat;
                csvOutputSettings.Delimiter              = ",";
                csvOutputSettings.Filename               = Path.GetFileName(fileToConvert).Replace("pdf", "csv");
                csvOutputSettings.OutputDirectory        = _outputPath;
                csvOutputSettings.UseSectorValueAsVolume = true;
                csvOutputSettings.SectorVolumeDivider    = 1000;

                pseDocument.ToCSV(csvOutputSettings);
            }
        }
示例#5
0
        private static void DoDownloadHistoricalData(IEnumerable <string> stockList,
                                                     int numYears, CSVOutputSettings outputSettings,
                                                     Action <string> BeforeDownload, Action <string> AfterDownload, Action <Exception> ExceptionCallback)
        {
            // initialize parameters
            HistoricalDownloadParams downloadParams = new HistoricalDownloadParams();

            downloadParams.stockList      = stockList;
            downloadParams.NumYears       = numYears;
            downloadParams.OutputSettings = outputSettings.Clone() as CSVOutputSettings;
            downloadParams.BeforeStockDataDownloadCallback = BeforeDownload;
            downloadParams.AfterStockDataDownloadCallback  = AfterDownload;
            downloadParams.OnExceptionCallback             = ExceptionCallback;

            // start the thread
            DownloadWorker worker = new DownloadWorker();

            Thread t = new Thread(worker.DownloadStockHistoryData);

            Variables.threadList.Add(t);
            t.Start(downloadParams);
            //worker.DownloadStockHistoryData(downloadParams);
        }
示例#6
0
        private void ReceiveGetParamMessage(MessageBase message)
        {
            OutputSettings outputSettings = null;

            switch (OutputTo)
            {
            case OutputTo.CSV:
                outputSettings = new CSVOutputSettings();
                var csvOutputSettings = outputSettings as CSVOutputSettings;
                csvOutputSettings.CSVFormat              = GetCSVFormat();
                csvOutputSettings.DateFormat             = DateFormat;
                csvOutputSettings.Delimiter              = Delimiter;
                csvOutputSettings.OutputDirectory        = OutputLocation;
                csvOutputSettings.UseSectorValueAsVolume = IndexValueAsVolume;
                csvOutputSettings.SectorVolumeDivider    = IndexValueDivisor;
                csvOutputSettings.Filename = ReportFilenameFormat;
                break;

            case OutputTo.Amibroker:
                outputSettings = new AmiOutputSettings();
                outputSettings.UseSectorValueAsVolume = IndexValueAsVolume;
                outputSettings.SectorVolumeDivider    = IndexValueDivisor;
                (outputSettings as AmiOutputSettings).DatabaseDirectory = OutputLocation;
                break;

            case OutputTo.Metastock:
                outputSettings = new MetaOutputSettings();
                ((MetaOutputSettings)outputSettings).OutputDirectory    = OutputLocation;
                ((MetaOutputSettings)outputSettings).UseSingleDirectory = MSSingleDirectory;
                break;
            }

            Messenger.Default.Send(new OutputSettingsMessage {
                DataOutputSettings = outputSettings
            });
        }
示例#7
0
文件: Program.cs 项目: yvdjee/PSEGet
        static void ConvertIt(string fileToConvert)
        {
            IPdfService      pdfService  = new PdfTextSharpService();
            var              pseDocument = new PSEDocument();
            IPSEReportReader reader      = new PSEReportReader2();

            reader.Fill(pseDocument, pdfService.ExtractTextFromPdf(fileToConvert));
            if (_outputFormat.Contains("csv"))
            {
                string[] csvParam  = _outputFormat.Split(':');
                string   csvFormat = string.Empty;
                if (csvParam.Length == 2)
                {
                    csvFormat = csvParam[1];
                    csvFormat = csvFormat.Replace("S", "{S}");
                    csvFormat = csvFormat.Replace("D", "{D}");
                    csvFormat = csvFormat.Replace("O", "{O}");
                    csvFormat = csvFormat.Replace("H", "{H}");
                    csvFormat = csvFormat.Replace("L", "{L}");
                    csvFormat = csvFormat.Replace("C", "{C}");
                    csvFormat = csvFormat.Replace("V", "{V}");
                    csvFormat = csvFormat.Replace("F", "{F}");
                }
                else
                {
                    csvFormat = "{S},{D},{O},{H},{L},{C},{V},{F}";
                }

                var csvOutputSettings = new CSVOutputSettings();
                csvOutputSettings.CSVFormat              = csvFormat;
                csvOutputSettings.DateFormat             = _dateFormat;
                csvOutputSettings.Delimiter              = ",";
                csvOutputSettings.Filename               = Path.GetFileName(fileToConvert).Replace("pdf", "csv");
                csvOutputSettings.OutputDirectory        = _outputPath;
                csvOutputSettings.UseSectorValueAsVolume = true;
                csvOutputSettings.SectorVolumeDivider    = 1000;

                pseDocument.ToCSV(csvOutputSettings);
            }
            else if ((HostOS.determineHostEnviroment() == HostOS.HostEnviroment.Windows) && (_outputFormat.Contains("ami")))
            {
                IAmibrokerService amiService = new AmibrokerService();
                if (!amiService.IsAmibrokerInstalled())
                {
                    throw new Exception("Error: Amibroker is not installed on this machine.");
                }

                string[] amiParam = _outputFormat.Split(':');
                if (amiParam.Length < 2)
                {
                    throw new Exception("Error: Unspecified Amibroker database folder.");
                }
                string amiDatabaseFolder = _outputFormat.Replace("ami:", string.Empty);

                var amiOutputSettings = new AmiOutputSettings();
                amiOutputSettings.DatabaseDirectory      = amiDatabaseFolder;
                amiOutputSettings.SectorVolumeDivider    = 1000;
                amiOutputSettings.UseSectorValueAsVolume = true;

                pseDocument.ToAmibroker(amiOutputSettings);
            }
        }
示例#8
0
        public void DownloadStockHistoryData(object downloadParams)
        {
            HistoricalDownloadParams _downloadParams = downloadParams as HistoricalDownloadParams;
            IEnumerable <string>     stocks          = _downloadParams.stockList as IEnumerable <string>;
            string            downloadStr;
            int               numYears       = _downloadParams.NumYears;
            CSVOutputSettings outputSettings = _downloadParams.OutputSettings;

            Dictionary <string, string> indexDict = new Dictionary <string, string>();

            indexDict.Add("^PSEi", "PSE");
            indexDict.Add("^ALLSHARES", "ALL");
            indexDict.Add("^FINANCIAL", "FIN");
            indexDict.Add("^INDUSTRIAL", "IND");
            indexDict.Add("^HOLDING", "HDG");
            indexDict.Add("^PROPERTY", "PRO");
            indexDict.Add("^SERVICE", "SVC");
            indexDict.Add("^MINING-OIL", "M-O");
            try
            {
                foreach (string symbol in stocks)
                {
                    string tmpSymbol = symbol;

                    if (tmpSymbol.Contains("^"))
                    {
                        tmpSymbol   = indexDict[symbol];
                        downloadStr = "http://www2.pse.com.ph/servlet/ChartForPhisixServlet?indexID=%s&years=%f";
                    }
                    else
                    {
                        downloadStr = "http://www2.pse.com.ph/servlet/PSEChartServlet?securitySymbol=%s&years=%f";
                    }

                    downloadStr             = downloadStr.Replace("%s", tmpSymbol).Replace("%f", numYears.ToString());
                    outputSettings.Filename = symbol + ".csv";

                    // before download callback
                    if (_downloadParams.BeforeStockDataDownloadCallback != null)
                    {
                        _downloadParams.BeforeStockDataDownloadCallback(symbol);
                    }

                    HistoricalDataDownloader downloader = new HistoricalDataDownloader(new Uri(downloadStr));
                    downloader.Download();

                    HistoricalDataReader reader = downloader.GetReader(symbol);
                    lock (DownloadWorker.threadLock)
                    {
                        reader.ToCSV(outputSettings);
                        Variables.DownloadedCount++;

                        // after download
                        if (_downloadParams.AfterStockDataDownloadCallback != null)
                        {
                            _downloadParams.AfterStockDataDownloadCallback(symbol);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                //throw new Exception(e.Message);
                if (_downloadParams.OnExceptionCallback != null)
                {
                    _downloadParams.OnExceptionCallback(e);
                }

                // abort threads
                foreach (Thread t in Variables.threadList)
                {
                    if (t.IsAlive)
                    {
                        t.Abort();
                    }
                }
            }
        }
示例#9
0
 public void ToCSV(CSVOutputSettings csvOutputSettings)
 {
     Converter.Convert <CSVOutputSettings>(this, csvOutputSettings);
 }