Example #1
0
        public async Task <NseDailyData> GetDailyData(DateTime date)
        {
            NseURLs      nseUrls = new NseURLs(date);
            NseDailyData list    = new NseDailyData(date);
            Dictionary <string, string> urlToFileMapping = new Dictionary <string, string>();
            string folder = $"{Options.app.TmpFolder}/{date.ToString("ddMMyyyy")}";

            urlToFileMapping[nseUrls.BhavUrl]       = $"{folder}/bhav.csv.zip";
            urlToFileMapping[nseUrls.PRZipfileUrl]  = $"{folder}/PR.zip";
            urlToFileMapping[nseUrls.EquityListUrl] = $"{folder}/equity.csv";
            urlToFileMapping[nseUrls.ETFListUrl]    = $"{folder}/etf.csv";
            urlToFileMapping[nseUrls.IndexBhavUrl]  = $"{folder}/indexBhav.csv";
            urlToFileMapping[nseUrls.CompanyToIndustryMappingUrl] = $"{folder}/mapping.csv";
            urlToFileMapping[nseUrls.DeliveryPositionUrL]         = $"{folder}/MTO.csv";

            // Delete the folder if it exists then create the folder
            if (!Directory.Exists(folder))
            {
                Globals.Log.Info($"Creating folder {folder}");
                Directory.CreateDirectory(folder);

                Globals.Log.Info($"Download the {urlToFileMapping.Count}  URL's parallely.");
                List <Task> task = new List <Task>();
                foreach (var item in urlToFileMapping)
                {
                    task.Add(fileDownloader.Download(item.Key, item.Value));
                }
                await Task.WhenAll(task.ToArray());
            }

            NseDailyData dailyData = new NseDailyData(date);

            // Parse all the downloaded Data
            dailyData.deliveryPosition = csvParser.ParseDeliveryPositionFile(urlToFileMapping[nseUrls.DeliveryPositionUrL]);
            dailyData.IndexBhavData    = csvParser.ParseIndexBhavFile(urlToFileMapping[nseUrls.IndexBhavUrl]);
            if (dailyData.deliveryPosition.Count == 0)
            {
                Globals.Log.Error($"No data for {date}");
                return(null);
            }

            Globals.Log.Info($"Extracting Zip files to {folder}");
            ZipFile.ExtractToDirectory(urlToFileMapping[nseUrls.BhavUrl], folder, true);
            ZipFile.ExtractToDirectory(urlToFileMapping[nseUrls.PRZipfileUrl], folder, true);

            dailyData.CompanyToIndustry = csvParser.ParseCompanyToIndustryMappingFile(urlToFileMapping[nseUrls.CompanyToIndustryMappingUrl]);
            dailyData.Equitys           = csvParser.ParseEquityInformationFile(urlToFileMapping[nseUrls.EquityListUrl]);
            dailyData.Etfs = csvParser.ParseETFInformationFile(urlToFileMapping[nseUrls.ETFListUrl]);

            //Parse the unzipped files
            dailyData.BhavData       = csvParser.ParseBhavFile($"{folder}/{nseUrls.BhavFilename}");
            dailyData.ETFBhavData    = csvParser.ParseETFBhavFile($"{folder}/{nseUrls.ETFBhavFilename}");
            dailyData.circuitBreaker = csvParser.ParseCircuitBreakerFile($"{folder}/{nseUrls.CircuitBreakerFilename}");
            dailyData.highLow52Week  = csvParser.ParseHighLow52WeekFile($"{folder}/{nseUrls.HighLow52WeekFilename}");

            // Computed Valus
            dailyData.Indexes = dailyData.IndexBhavData.Select(x => new IndexInformation(x.IndexName))
                                .ToList();

            return(dailyData);
        }
Example #2
0
        public List <MarketCap> GetMarketCap()
        {
            NseURLs nseUrls = new NseURLs(DateTime.Today);

            return(csvParser.ParseMarketCapFile(nseUrls.MarketCapFilename));
        }