예제 #1
0
        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>();
        }
예제 #2
0
        public static void DeleteFile(string filename)
        {
            string fileId  = Drive.GetFileId(filename);
            var    request = service.Files.Delete(fileId);

            request.Execute();

            Console.WriteLine("Deleted: {0}", filename);
        }
예제 #3
0
        public void LoadGroups()
        {
            string groupsFileId = Drive.GetFileId("groups.txt");

            if (groupsFileId != "")
            {
                string input = Drive.DownloadFile(groupsFileId, "groups.txt");
                Groups = input;
            }

            Console.WriteLine("Groups: " + Groups);
        }
예제 #4
0
        public static string RenameFile(string folderId, string filename, string newFilename)
        {
            string fileId = Drive.GetFileId(filename);

            if (fileId == "")
            {
                Console.WriteLine("Tried to rename file {0}, but it was not found!", filename, newFilename);
                return(fileId);
            }

            var fileMetadata = new Google.Apis.Drive.v3.Data.File();

            fileMetadata.Name = newFilename;
            var request = service.Files.Update(fileMetadata, fileId);

            request.Execute();

            Console.WriteLine("Renamed: {0} to {1}", filename, newFilename);

            return(fileId);
        }
예제 #5
0
        public DataViewModel()
        {
            Drive.CreateService();

            Data.numberFormat.NumberGroupSeparator   = ""; // thousands
            Data.numberFormat.NumberDecimalSeparator = ".";
            Data.dateTimeFormat = CultureInfo.CurrentCulture.DateTimeFormat.UniversalSortableDateTimePattern;

            SymbolsDrawings            = new Dictionary <string, Chart>();
            SymbolsDrawingsToSerialize = new Dictionary <string, Chart.DataToSerialize>();
            SDDs = new Dictionary <string, List <Data.SymbolDayData> >();

            ReportItems = new List <ReportItem>();
            WalletItems = new List <WalletItem>();

            LoadSymbolsInfoList();
            FilterSymbolInfoList("", "wszystko");

            // try to load symbols drawings
            // create default dir
            string folderId = Drive.CreateDirectory("temp");
            string fileId   = Drive.GetFileId("charts.json");

            if (fileId != "")
            {
                string input = Drive.DownloadFile(fileId, "charts.json");

                SymbolsDrawingsToSerialize =
                    JsonConvert.DeserializeObject <Dictionary <string, Chart.DataToSerialize> >(input);

                // in case of empty file the result of deserialization will be null,
                // so create new object
                if (SymbolsDrawingsToSerialize == null)
                {
                    SymbolsDrawingsToSerialize = new Dictionary <string, Chart.DataToSerialize>();
                }

                UpdateInfoNamesOnLoad();
            }
        }
예제 #6
0
        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);
        }