private IEnumerable <CandleData> downloadSegment(StartEndTimes segment) { HistoricPrices historicData = new HistoricPrices(); try { //Logger.WriteLog(string.Format("downloading data: {0} - {1}", segment.Start.ToString(), segment.End.ToString())); //var temp = historicData.GetPrices( // product: ProductName, // granularity: "60", // startTime: segment.Start.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"), // endTime: segment.End.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")).Result; var temp = historicData.GetPrices( product: ProductName, granularity: "60", startTime: segment.Start.ToUniversalTime().ToString("s", System.Globalization.CultureInfo.InvariantCulture), endTime: segment.End.ToUniversalTime().ToString("s", System.Globalization.CultureInfo.InvariantCulture)).Result; //("s", System.Globalization.CultureInfo.InvariantCulture) if (temp != null) { //if (temp.Count() > 0) // extraData.AddRange(temp); return(temp); } else { return(null); } } catch (Exception ex) { delayTime += 200; Logger.WriteLog("Error downloading additional data, retrying with " + delayTime.ToString() + " ms delay. (" + ex.Message + ")"); return(null); } }
private bool DownloadDataFromDateTillNow(bool createNewDB = false) { HistoricPrices historicData = new HistoricPrices(); const int HOURS = 5; List <CandleData> extraData = new List <CandleData>(); DateTime startDate = new DateTime(); if (createNewDB) { startDate = DateTime.Now.AddMonths(-1); } //startDate = DateTime.Now.AddYears(-1);//get all data from past year //new DateTime(2017,06,1,0,0,0); else { startDate = RawExchangeData.First().Time.AddMinutes(1); } var endDate = DateTime.Now.AddMinutes(-1); //one min less of now var startDt = startDate; // from older date to newer date var endDt = startDt.AddHours(HOURS); do { if (startDt > endDt) { startDt = endDt; } if (endDt > endDate) { endDt = endDate; } try { Logger.WriteLog(string.Format("downloading data: {0} - {1}", startDt.ToString(), endDt.ToString())); var temp = historicData.GetPrices( product: ProductName, granularity: "60", startTime: startDt.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"), endTime: endDt.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")).Result; startDt = temp.First().Time.AddMinutes(2); //most recent plus one min + one min to compensate endDt = startDt.AddHours(HOURS); // start date plus 5 hours //System.Diagnostics.Debug.Print("start:{0} end:{1}",startDt, endDt); if (temp != null) { if (temp.Count() > 0) { extraData.AddRange(temp); } } else { return(false); } } catch (Exception ex) { delayTime += 200; Logger.WriteLog("Error downloading additional data, retrying with " + delayTime.ToString() + " ms delay. (" + ex.Message + ")"); return(false); } System.Threading.Thread.Sleep(delayTime); } while (startDt <= endDate); extraData = extraData.OrderByDescending((d) => d.Time).ToList(); //extraData.ForEach((d) => { System.Diagnostics.Debug.Print(d.Time.ToString()); }); RawExchangeData.AddRange(extraData); RawExchangeData = RawExchangeData.OrderByDescending(d => d.Time).ToList(); Logger.WriteLog("done downloading additional data from server"); return(true); }