public bool LoadFromEveCrest() { try { string url = "https://public-crest.eveonline.com/market/10000002/types/" + TypeId.ToString() + "/history/"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse response = null; try { response = (HttpWebResponse)request.GetResponse(); } catch (Exception ex) { if (Logging.ShowDebugMessages == true) { MessageBox.Show(ex.Message); } return(false); } Days = new List <Day>(); Stream resStream = response.GetResponseStream(); StreamReader reader = new StreamReader(resStream, Encoding.UTF8); string resString = reader.ReadToEnd(); JsonHistoryPage page = JsonConvert.DeserializeObject <JsonHistoryPage>(resString); long totalOrdersMovement = 0; long totalVolumeMovement = 0; decimal totalAvgPrice = 0.0m; decimal totalMaxPrice = 0.0m; decimal totalMinPrice = 0.0m; DateTime previousDateTime = DateTime.MaxValue; foreach (JsonHistoryItem jsonItem in page.Items) { PriceHistory.Day day = new PriceHistory.Day(Convert.ToDateTime(jsonItem.Date), jsonItem.LowPrice, jsonItem.HighPrice, jsonItem.AvgPrice, jsonItem.Volume, jsonItem.OrderCount); while (day.Date.Ticks - previousDateTime.Ticks > TimeSpan.TicksPerDay) { previousDateTime = previousDateTime.AddDays(1.0); PriceHistory.Day emptyDay = new PriceHistory.Day(previousDateTime); totalAvgPrice += emptyDay.AvgPrice; totalMaxPrice += emptyDay.MaxPrice; totalMinPrice += emptyDay.MinPrice; totalOrdersMovement += emptyDay.OrderCount; totalVolumeMovement += emptyDay.Volume; Days.Add(emptyDay); } totalAvgPrice += day.AvgPrice; totalMaxPrice += day.MaxPrice; totalMinPrice += day.MinPrice; totalOrdersMovement += day.OrderCount; totalVolumeMovement += day.Volume; Days.Add(day); previousDateTime = day.Date; } if (page.Items.Count() > 0) { AvgVolume = totalVolumeMovement / page.Items.Count(); AvgPrice = totalAvgPrice / page.Items.Count(); AvgOrders = totalOrdersMovement / page.Items.Count(); AvgMinPrice = totalMinPrice / page.Items.Count(); AvgMaxPrice = totalVolumeMovement / page.Items.Count(); } Days = Days.OrderByDescending(d => d.Date).ToList(); //if (page.Next != null && page.Next.Href.Count() >= 0) // LoadFromEveCrest(page.Next.Href); return(true); } catch (Exception ex) { if (Logging.ShowDebugMessages == true) { MessageBox.Show(ex.Message); } return(false); } }
public bool LoadFromEveCrest() { try { string url = "https://public-crest.eveonline.com/market/10000002/types/" + TypeId.ToString() + "/history/"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse response = null; try { response = (HttpWebResponse)request.GetResponse(); } catch (Exception ex) { if (Logging.ShowDebugMessages == true) MessageBox.Show(ex.Message); return false; } Days = new List<Day>(); Stream resStream = response.GetResponseStream(); StreamReader reader = new StreamReader(resStream, Encoding.UTF8); string resString = reader.ReadToEnd(); JsonHistoryPage page = JsonConvert.DeserializeObject<JsonHistoryPage>(resString); long totalOrdersMovement = 0; long totalVolumeMovement = 0; decimal totalAvgPrice = 0.0m; decimal totalMaxPrice = 0.0m; decimal totalMinPrice = 0.0m; DateTime previousDateTime = DateTime.MaxValue; foreach (JsonHistoryItem jsonItem in page.Items) { PriceHistory.Day day = new PriceHistory.Day(Convert.ToDateTime(jsonItem.Date), jsonItem.LowPrice, jsonItem.HighPrice, jsonItem.AvgPrice, jsonItem.Volume, jsonItem.OrderCount); while (day.Date.Ticks - previousDateTime.Ticks > TimeSpan.TicksPerDay) { previousDateTime = previousDateTime.AddDays(1.0); PriceHistory.Day emptyDay = new PriceHistory.Day(previousDateTime); totalAvgPrice += emptyDay.AvgPrice; totalMaxPrice += emptyDay.MaxPrice; totalMinPrice += emptyDay.MinPrice; totalOrdersMovement += emptyDay.OrderCount; totalVolumeMovement += emptyDay.Volume; Days.Add(emptyDay); } totalAvgPrice += day.AvgPrice; totalMaxPrice += day.MaxPrice; totalMinPrice += day.MinPrice; totalOrdersMovement += day.OrderCount; totalVolumeMovement += day.Volume; Days.Add(day); previousDateTime = day.Date; } if (page.Items.Count() > 0) { AvgVolume = totalVolumeMovement / page.Items.Count(); AvgPrice = totalAvgPrice / page.Items.Count(); AvgOrders = totalOrdersMovement / page.Items.Count(); AvgMinPrice = totalMinPrice / page.Items.Count(); AvgMaxPrice = totalVolumeMovement / page.Items.Count(); } Days = Days.OrderByDescending(d => d.Date).ToList(); //if (page.Next != null && page.Next.Href.Count() >= 0) // LoadFromEveCrest(page.Next.Href); return true; } catch (Exception ex) { if (Logging.ShowDebugMessages == true) MessageBox.Show(ex.Message); return false; } }