private void LoadSymbolsInfoList() { // try to load from disk string today = DateTime.Today.ToString("dd-MM-yyyy"); string filename = "stocker_symbols_" + today + ".html"; if (MainWindow.testMode) { filename = "stocker_symbols_00-00-0000.html"; } string folderId = Drive.CreateDirectory("temp"); string fileId = Drive.GetFileId(filename); if (fileId != "") { string content = Drive.DownloadFile(fileId, filename); SymbolsInfoList = JsonConvert.DeserializeObject <List <Data.SymbolInfo> >(content); } else { if (SymbolsInfoList == null) { // load from web SymbolsInfoList = new List <Data.SymbolInfo>(Sources.GetSymbolsFromWeb()); // save to disk string output = JsonConvert.SerializeObject(SymbolsInfoList, Formatting.Indented); Drive.UploadFile(folderId, filename, output); } } VisibleSymbolsInfoList = new List <Data.SymbolInfo>(); }
public static List <Data.SymbolDayData> GetSymbolData(Dictionary <string, List <Data.SymbolDayData> > sdds, Data.SymbolInfo si) { string symbolName = si.ShortName; if (sdds.ContainsKey(symbolName)) { return(sdds[symbolName]); } string csv = ""; string today = DateTime.Today.ToString("dd-MM-yyyy"); string filename = "stocker_" + today + "_" + symbolName + ".csv"; if (MainWindow.testMode) { filename = "stocker_00-00-0000_AAA.csv"; } string fileId = Drive.GetFileId(filename); if (fileId != "") { csv = Drive.DownloadFile(fileId, filename); } else { csv = Sources.GetHtml(symbolName); string folderId = Drive.CreateDirectory("temp"); Drive.UploadFile(folderId, filename, csv); } if (csv == "Przekroczony dzienny limit wywolan") { MessageBox.Show(csv, "ERROR"); } List <Data.SymbolDayData> result = new List <Data.SymbolDayData>(); foreach (string line in csv.Split('\n')) { if (line.Length == 0) { continue; } if (line[0] == 'D') { continue; } string[] data = line.Split(','); Debug.Assert(data.Count() >= 5); DateTime date = DateTime.ParseExact(data[0], "yyyy-MM-dd", CultureInfo.InvariantCulture); // discard old data for perf if (date.Year < 2016) { continue; } float open = float.Parse(data[1], CultureInfo.InvariantCulture); float hi = float.Parse(data[2], CultureInfo.InvariantCulture); float low = float.Parse(data[3], CultureInfo.InvariantCulture); float close = float.Parse(data[4], CultureInfo.InvariantCulture); uint volume = 0; if (data.Length == 6) { volume = uint.Parse(data[5]); } Data.SymbolDayData sdd = new Data.SymbolDayData(date, open, hi, low, close, volume); result.Add(sdd); } result.Reverse(); sdds.Add(symbolName, result); return(result); }