示例#1
0
        private async Task <CompanyDetail> CallSimFinForSimId(string urlToUse)
        {
            string apiKey = HandleSimFinUtils.GetApiKey(_logger);

            if (string.IsNullOrWhiteSpace(apiKey))
            {
                _logger.LogError("Did not find API key; calls will fail");
                return(null);
            }
            urlToUse = urlToUse.Replace(@"{API-KEY}", apiKey);
            string data = "[]";

            try
            {
                using (var wc = new WebClient())
                {
                    data = await wc.DownloadStringTaskAsync(urlToUse);
                }
                //NameTickerSimId
                var allDetails = JsonConvert.DeserializeObject <IEnumerable <CompanyDetail> >(data);
                return(allDetails.FirstOrDefault());
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error in GetSimId::GetSimIdByTicker;Details\n{ex.Message}");
                if (ex.InnerException != null)
                {
                    _logger.LogError(ex.InnerException.Message);
                }
                return(null);
            }
        }
        public async Task <List <CompanyDetail> > GetCompanyList()
        {
            string apiKey = HandleSimFinUtils.GetApiKey(_logger);

            if (string.IsNullOrWhiteSpace(apiKey))
            {
                _logger.LogError("Did not find API key; calls will fail");
                return(null);
            }
            var    urlToUse = _allEntities.Replace(@"{API-KEY}", apiKey);
            string data     = "";

            try
            {
                using (var wc = new WebClient())
                {
                    data = await wc.DownloadStringTaskAsync(urlToUse);
                }
                var allCompanyDetails = JsonConvert.DeserializeObject <IEnumerable <CompanyDetail> >(data);
                return(allCompanyDetails.ToList());
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error in DownloadListedFirms::GetCompanyList\n{ex.Message}");
                if (ex.InnerException != null)
                {
                    _logger.LogError(ex.InnerException.Message);
                }
                return(null);
            }
        }
示例#3
0
        private async Task <StatementList> GetListOfStatements(string companyId)
        {
            var    urlToUse = urlForStatmentList.Replace(@"{companyId}", companyId);
            string apiKey   = HandleSimFinUtils.GetApiKey(_logger);

            if (string.IsNullOrWhiteSpace(apiKey))
            {
                _logger.LogError("Did not find API key; calls will fail");
                return(null);
            }
            urlToUse = urlToUse.Replace(@"{API-KEY}", apiKey);
            string data = "[]";

            try
            {
                using (var wc = new WebClient())
                {
                    data = await wc.DownloadStringTaskAsync(urlToUse);
                }
                statementList           = JsonConvert.DeserializeObject <StatementList>(data);
                statementList.CompanyId = companyId;
                statementList           = RemovePastTTMs(statementList);
                return(statementList);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error in ListOfStatements:FetchStatementList\n{ex.Message}");
                if (ex.InnerException != null)
                {
                    _logger.LogError($"\n{ex.InnerException.Message}");
                }
                return(null);
            }
        }
示例#4
0
        public async Task <OutstandingShares> ObtainAggregatedList(string simId)
        {
            var outstandingShares = new OutstandingShares
            {
                SimId = simId
            };
            string apiKey = HandleSimFinUtils.GetApiKey(_logger);

            if (string.IsNullOrWhiteSpace(apiKey))
            {
                _logger.LogError("Did not find API key; calls will fail");
                return(null);
            }
            _logger.LogInformation($"Starting getting Outstanding share count for {simId}");
            await HandleGettingData(simId, outstandingShares, apiKey);

            _logger.LogInformation($"Completed download of Outstanding shares for {simId}");
            return(outstandingShares);
        }
        public async Task <List <CompanyFinancials> > DownloadFinancialsAsync(StatementList statementList)
        {
            var    cfl    = new List <CompanyFinancials>();
            string apiKey = HandleSimFinUtils.GetApiKey(_logger);

            if (string.IsNullOrWhiteSpace(apiKey))
            {
                _logger.LogError("Did not find API key; calls will fail");
                return(null);
            }
            var companyId = statementList.CompanyId;

            //get balance sheets
            var statementType    = "bs";
            var lastStatmentYear = statementList.Bs.Max(sl => sl.Fyear);
            var reportingList    = statementList.Bs.OrderByDescending(b => b.Fyear).Distinct().Take(ReportableItemsCount);

            foreach (var bs in reportingList)
            {
                bs.Period = bs.Fyear == lastStatmentYear ? "TTM" : bs.Period;
                var bsToAdd = await ObtainReportedNumbers(companyId, apiKey, statementType, bs);

                if (bsToAdd != null)
                {
                    AddAdditionalDetailstoFinancials(companyId, bs, bsToAdd, StatementType.BalanceSheet);
                    cfl.Add(bsToAdd);
                }
            }

            // get profit and loss
            statementType    = "pl";
            lastStatmentYear = statementList.Pl.Max(sl => sl.Fyear);
            reportingList    = statementList.Pl.OrderByDescending(b => b.Fyear).Take(ReportableItemsCount);
            foreach (StatementDetails pl in reportingList)
            {
                pl.Period = pl.Fyear == lastStatmentYear ? "TTM" : pl.Period;
                var plToAdd = await ObtainReportedNumbers(companyId, apiKey, statementType, pl);

                if (plToAdd != null)
                {
                    AddAdditionalDetailstoFinancials(companyId, pl, plToAdd, StatementType.ProfitLoss);
                    cfl.Add(plToAdd);
                }
            }

            //get cash flow
            statementType = "cf";
            reportingList = statementList.Cf.OrderByDescending(b => b.Fyear).Take(ReportableItemsCount);
            foreach (var cf in reportingList)
            {
                cf.Period = cf.Fyear == lastStatmentYear ? "TTM" : cf.Period;
                var cfToAdd = await ObtainReportedNumbers(companyId, apiKey, statementType, cf);

                if (cfToAdd != null)
                {
                    AddAdditionalDetailstoFinancials(companyId, cf, cfToAdd, StatementType.CashFlow);
                    cfl.Add(cfToAdd);
                }
            }
            return(cfl);
        }