public override ValueInvestingCompanyDBModel WebClientAPICall(ValueInvestingCompanyDBModel company) { string Json = ""; WebClient client = new WebClient(); Json = client.DownloadString($"https://financialmodelingprep.com/api/v3/financials/cash-flow-statement/{ company.STOCK_TICKER}"); var OCJson = CashFlow_Top_Level.FromJson(Json); Console.WriteLine("Writting to Book Value DB"); foreach (var item in OCJson.Financials) { Dividends_DB_Model dividends = new Dividends_DB_Model { DATE = (item.Date), DIVIDENDS = (item.DividendPayments), STOCK_TICKER = company.STOCK_TICKER }; SQL.WriteDividendsData(dividends); } Random rnd = new Random(); company.DIVIDENDS = Convert.ToDouble(rnd.Next()); return(company); }
//making a webclient call syncly public override ValueInvestingCompanyDBModel WebClientAPICall(ValueInvestingCompanyDBModel company) { string Json = ""; WebClient client = new WebClient(); Json = client.DownloadString($"https://financialmodelingprep.com/api/v3/financials/cash-flow-statement/{ company.STOCK_TICKER}"); //StockPriceModel Sp_json = JsonConvert.DeserializeObject<StockPriceModel>(Json); var OCJson = CashFlow_Top_Level.FromJson(Json); Console.WriteLine("Writting to Operating_Cash DB"); foreach (var item in OCJson.Financials) { Operating_Cash_DB_Model OperatingCash = new Operating_Cash_DB_Model { DATE = (item.Date), OPERATING_CASH_FLOW = (item.OperatingCashFlow), STOCK_TICKER = company.STOCK_TICKER }; SQL.WriteOperatingCashData(OperatingCash); } //Operating_Cash_DB_Model OperatingCash = new Operating_Cash_DB_Model { DATE = (OCJson.Symbol[0]), OPERATING_CASH_FLOW = OCJson. , STOCK_TICKER = company.STOCK_TICKER }; //SQL.WriteCurrentFinancialsData(StockPrice); Random rnd = new Random(); company.OPERATING_CASH = Convert.ToDouble(rnd.Next()); return(company); }
//making a call async public override async Task <ValueInvestingCompanyDBModel> WebClientAPICallAsync(ValueInvestingCompanyDBModel company) { string url = $"https://financialmodelingprep.com/api/v3/financials/cash-flow-statement/{ company.STOCK_TICKER}"; using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(url)) { if (response.IsSuccessStatusCode) { Console.WriteLine("Processing OperatingCash.WebClientAPICallAsync"); CashFlow_Top_Level result = await response.Content.ReadAsAsync <CashFlow_Top_Level>(); //foreach (var item in result.Financials) //{ // Console.WriteLine("Operating cash : " + item.OperatingCashFlow); //} List <double> growth = new List <double>(); for (int i = 0; i < result.Financials.Length; i++) { if (i == 0) { //growth.Add(OCJson.Financials[i].OperatingCashFlow); } else { double change = CalculateChange(result.Financials[i - 1].OperatingCashFlow, result.Financials[i].OperatingCashFlow); growth.Add(change); //Console.WriteLine("growth for " + i); //Console.WriteLine(change); } } double CalculateChange(double previous, double current) { if (previous == 0) { throw new InvalidOperationException(); } var change = current - previous; return((double)change / previous); } Console.WriteLine("Operating Cash growth for " + result.Financials.Length.ToString() + " years is : " + growth.Average()); company.OPERATING_CASH = growth.Average(); return(company); } else { throw new Exception(response.ReasonPhrase); } } }
public static string ToJson(this CashFlow_Top_Level self) => JsonConvert.SerializeObject(self, Evesting.Converter.Settings);
//making a call async public override async Task <ValueInvestingCompanyDBModel> WebClientAPICallAsync(ValueInvestingCompanyDBModel company) { string url = $"https://financialmodelingprep.com/api/v3/financials/cash-flow-statement/{ company.STOCK_TICKER}"; using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(url)) { if (response.IsSuccessStatusCode) { Console.WriteLine("Processing Dividends for BookValue__Plus_Dividends_Processor.WebClientAPICallAsync"); CashFlow_Top_Level result = await response.Content.ReadAsAsync <CashFlow_Top_Level>(); //foreach (var item in result.Financials) //{ // Console.WriteLine(item.DividendPayments); //} List <double> growth = new List <double>(); for (int i = 0; i < result.Financials.Length; i++) { if (i == 0) { } else { double change = CalculateChange(result.Financials[i - 1].DividendPayments, result.Financials[i].DividendPayments); growth.Add(change); Console.WriteLine("dividend growth for " + i); Console.WriteLine(change); } } double CalculateChange(double previous, double current) { if (previous == 0) { previous = .001; } var change = current - previous; return((double)change / previous); } Console.WriteLine("Dividends growth for " + result.Financials.Length.ToString() + " years is : " + growth.Average()); company.DIVIDENDS = growth.Average(); } else { Console.WriteLine("Somethign went wrong"); throw new Exception(response.ReasonPhrase); } } string shareholderequityURL = $"https://financialmodelingprep.com/api/v3/financials/balance-sheet-statement/{ company.STOCK_TICKER}"; using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(shareholderequityURL)) { if (response.IsSuccessStatusCode) { Console.WriteLine("Processing Total Share holders Equity for BookValue__Plus_Dividends_Processor.WebClientAPICallAsync"); Balance_Sheet_Rootobject BSresult = await response.Content.ReadAsAsync <Balance_Sheet_Rootobject>(); //foreach (var item in BSresult.financials) //{ // Console.WriteLine("Total Share holders Equity: " + item.Totalshareholdersequity); //} List <double> shegrowth = new List <double>(); for (int i = 0; i < BSresult.financials.Length; i++) { if (i == 0) { } else { double change = CalculateChange(BSresult.financials[i - 1].Totalshareholdersequity, BSresult.financials[i].Totalshareholdersequity); shegrowth.Add(change); } } double CalculateChange(double previous, double current) { if (previous == 0) { previous = .001; } var change = current - previous; return((double)change / previous); } Console.WriteLine("Shareholder Equity growth for " + BSresult.financials.Length.ToString() + " years is : " + shegrowth.Average()); company.SHAREHOLDER_EQUITY = shegrowth.Average(); return(company); } else { throw new Exception(response.ReasonPhrase); } } }