public async Task <CompanyKeyMetricsDto> GetKeyMetrics(string stock)
        {
            CompanyKeyMetricsDto result = null;

            try
            {
                _logger.WriteInformation("Getting Company Key Metrics List");
                using (var httpClient = new HttpClient())
                {
                    using (var request = new HttpRequestMessage(new HttpMethod("GET"), _dcfUrl + stock))
                    {
                        request.Headers.TryAddWithoutValidation("Upgrade-Insecure-Requests", "1");

                        _logger.WriteInformation($"Getting {stock} Company Key Metric");
                        var response = await httpClient.SendAsync(request);

                        if (response.IsSuccessStatusCode)
                        {
                            var jsonString = await response.Content.ReadAsStringAsync();

                            result = JsonConvert.DeserializeObject <CompanyKeyMetricsDto>(jsonString);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.WriteError("Error calling Company Key Metric API", ex);
            }
            _logger.WriteInformation("Received Company Key Metrics");
            return(result);
        }
Exemplo n.º 2
0
        public async Task <List <Server> > GetServerList()
        {
            {
                List <Server> result     = null;
                var           httpClient = new RestClient(_apiUrl);
                var           request    = await GetServerListRequest();

                _logger.WriteInformation("Getting Server List");
                try
                {
                    IRestResponse <List <Server> > response = await httpClient.ExecuteTaskAsync <List <Server> >(request);

                    if (response.IsSuccessful)
                    {
                        result = response.Data;
                    }
                }
                catch (Exception ex)
                {
                    _logger.WriteError("Error calling Server List APi", ex);
                }
                _logger.WriteInformation("Received Server List");
                return(result);
            }
        }
Exemplo n.º 3
0
        public async Task <SymbolsList> GetStockList()
        {
            SymbolsList result = null;

            try
            {
                _logger.WriteInformation("Getting Stock List");
                using (var httpClient = new HttpClient())
                {
                    using (var request = new HttpRequestMessage(new HttpMethod("GET"), _apiUrl))
                    {
                        request.Headers.TryAddWithoutValidation("Upgrade-Insecure-Requests", "1");

                        var response = await httpClient.SendAsync(request);

                        if (response.IsSuccessStatusCode)
                        {
                            var jsonString = await response.Content.ReadAsStringAsync();

                            result = JsonConvert.DeserializeObject <SymbolsList>(jsonString);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.WriteError("Error calling Stock list APi", ex);
            }
            _logger.WriteInformation("Received Stock List");
            return(result);
        }
Exemplo n.º 4
0
 public async Task SaveStocks(List <Stock> stocks)
 {
     try
     {
         foreach (var stock in stocks)
         {
             var existingStock = _context.Stocks.FirstOrDefault(x => x.Symbol == stock.Symbol);
             if (existingStock == null)
             {
                 ValidateStockDcf(stock);
                 await AddStock(stock);
             }
             else
             {
                 ValidateStockDcf(stock);
                 await UpdateStock(stock, existingStock);
             }
         }
         await _context.SaveChangesAsync();
     }
     catch (Exception ex)
     {
         _logger.WriteError("Error saving DCF list to DB", ex);
     }
     _logger.WriteInformation("Saved data to DB");
 }
        public async Task <List <CompanyRatingDto> > GetCompanyRatingList(List <Stock> stocks)
        {
            List <CompanyRatingDto> result = new List <CompanyRatingDto>();

            try
            {
                _logger.WriteInformation("Getting Company Rating List");
                using (var httpClient = new HttpClient())
                {
                    var stockListString = _symbolService.GetStockListString(stocks, 3);
                    foreach (var stockListItem in stockListString)
                    {
                        using (var request = new HttpRequestMessage(new HttpMethod("GET"), _companyRatingUrl + stockListItem))
                        {
                            request.Headers.TryAddWithoutValidation("Upgrade-Insecure-Requests", "1");

                            _logger.WriteInformation($"Getting DCF Items {stockListString.IndexOf(stockListItem)} / {stockListString.Count} : {stockListItem}");
                            var response = await httpClient.SendAsync(request);

                            if (response.IsSuccessStatusCode)
                            {
                                var jsonString = await response.Content.ReadAsStringAsync();

                                var responseResults = JsonConvert.DeserializeObject <CompanyRatingListDto>(jsonString);
                                foreach (var responseResult in responseResults.CompaniesRating)
                                {
                                    result.Add(responseResult);
                                }
                            }
                            else
                            {
                                throw new Exception($"Failed http call + {stockListItem}");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.WriteError("Error calling Company Rating API", ex);
            }
            _logger.WriteInformation("Received Company Rating");
            return(result);
        }
Exemplo n.º 6
0
        public async Task SaveStocks(List <Stock> stocks)
        {
            var listOfStockLists = SplitStockList(stocks, 100);

            foreach (var stockList in listOfStockLists)
            {
                _logger.WriteInformation($"Saving stocks {listOfStockLists.IndexOf(stockList)} / {listOfStockLists.Count}");
                await _stockRepository.SaveStocks(stockList);
            }
        }
Exemplo n.º 7
0
        public async Task <ApiTokenResponse> GetToken()
        {
            ApiTokenResponse result = null;
            var httpClient          = new RestClient(_apiUrl);
            var request             = GetTokenRequest();

            _logger.WriteInformation("Getting Token");
            try
            {
                IRestResponse <ApiTokenResponse> response = await httpClient.ExecuteTaskAsync <ApiTokenResponse>(request);

                if (response.IsSuccessful)
                {
                    result = response.Data;
                }
            }
            catch (Exception ex)
            {
                _logger.WriteError("Error calling Token APi", ex);
            }
            _logger.WriteInformation("Received Token");
            return(result);
        }