/// <summary> /// Get stock prices for one instrument /// 20 year history /// </summary> static void StockPricesForOneInstruments(long InsId) { ApiClient api = new ApiClient(_apiKey); StockPricesRespV1 spList = api.GetStockPrices(InsId); foreach (var sp in spList.StockPricesList) { Console.WriteLine(sp.D + " : " + sp.C); } }
// Stockprices in Time period for Company ABB => InsId=3 static void StockPricesTimeRange() { ApiClient api = new ApiClient(_apiKey); StockPricesRespV1 sp2 = api.GetStockPrices(3, Convert.ToDateTime("2018-06-03"), Convert.ToDateTime("2018-10-10")); Console.WriteLine("sp2 count: " + sp2.StockPricesList.Count()); StockPricesRespV1 sp3 = api.GetStockPrices(3, Convert.ToDateTime("2018-01-10"), DateTime.Today); Console.WriteLine("sp3 count: " + sp3.StockPricesList.Count()); }
static void StockPricesForAllInstruments() { ApiClient api = new ApiClient(_apiKey); InstrumentRespV1 inst = api.GetInstruments(); // Get all stockprices for each Instrument foreach (var i in inst.Instruments) { //StockPricesRespV1 sp = api.GetStockPrices(i.InsId.Value, Convert.ToDateTime("2018-12-01"), DateTime.Today); StockPricesRespV1 sp = api.GetStockPrices(i.InsId.Value); Console.WriteLine(DateTime.Now.ToLongTimeString() + " GetStockPrices() " + i.InsId.Value + " " + sp.StockPricesList.Count()); } }
// Calc latest P/E for HM static void LatestPE() { ApiClient api = new ApiClient(_apiKey); int insId = 97; // HM StockPricesRespV1 spResp = api.GetStockPrices(insId, DateTime.Today.AddDays(-7), DateTime.Today); // We need lastest price. Ask for one week back. StockPriceV1 lastSp = spResp.StockPricesList.Last(); // First in list in latest stockprice. (Order Asc) ReportsR12RespV1 r12 = api.GetReportsR12(insId); ReportR12V1 lastReport = r12.Reports.First(); // Get last R12 report (Desc) var pe = lastSp.C / lastReport.EarningsPerShare; Console.WriteLine("Lastest R12 P/E is : " + pe); }
/// <summary> Return EndDay stockprice for one Instrument (max 10 year history)</summary> public StockPricesRespV1 GetStockPrices(long instrumentId) { string url = string.Format(_urlRoot + "/v1/instruments/{0}/stockprices", instrumentId); HttpResponseMessage response = WebbCall(url, _authKey); if (response.IsSuccessStatusCode) { string json = response.Content.ReadAsStringAsync().Result; StockPricesRespV1 res = JsonConvert.DeserializeObject <StockPricesRespV1>(json); return(res); } else { Console.WriteLine("GetStockPrices {0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } return(null); }
/// <summary> Return EndDay stockprice for one Instrument (max 10 year history)</summary> public StockPricesRespV1 GetStockPrices(long instrumentId, DateTime from, DateTime to) { string url = string.Format(_urlRoot + "/v1/instruments/{0}/stockprices", instrumentId); string urlPar = string.Format(_authKey + "&from={0}&to={1}", from.ToShortDateString(), to.ToShortDateString()); HttpResponseMessage response = WebbCall(url, urlPar); if (response.IsSuccessStatusCode) { string json = response.Content.ReadAsStringAsync().Result; StockPricesRespV1 res = JsonConvert.DeserializeObject <StockPricesRespV1>(json); return(res); } else { Console.WriteLine("GetStockPrices time {0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } return(null); }