public void BarTimeAdjustmentsHappenCorrectly() { string json = @"{ ""status"": { ""code"": 200, ""message"": ""Success."" }, ""results"": [{ ""symbol"": ""IBM"", ""timestamp"": ""2016-08-15T09:00:00-04:00"", ""tradingDay"": ""2016-08-15"", ""open"": 162.4, ""high"": 162.97, ""low"": 162.38, ""close"": 162.77, ""volume"": 215371 }, { ""symbol"": ""IBM"", ""timestamp"": ""2016-08-15T10:00:00-04:00"", ""tradingDay"": ""2016-08-15"", ""open"": 162.8, ""high"": 162.95, ""low"": 162.61, ""close"": 162.63, ""volume"": 222815 }] }"; var exchange = new Exchange { Timezone = "Eastern Standard Time" }; var instrument = new Instrument() { Symbol = "IBM", Exchange = exchange, Sessions = new List <InstrumentSession> { new InstrumentSession { OpeningDay = DayOfTheWeek.Monday, OpeningTime = new TimeSpan(9, 30, 0) } } }; var request = new HistoricalDataRequest(instrument, BarSize.OneHour, DateTime.Now, DateTime.Now); List <OHLCBar> bars = BarChartUtils.ParseJson(JObject.Parse(json), request); //opening time set to the session opening instead of earlier Assert.AreEqual(new DateTime(2016, 8, 15, 9, 30, 0), bars[0].DTOpen.Value); //Bar closing time set correctly Assert.AreEqual(new DateTime(2016, 8, 15, 10, 0, 0), bars[0].DT); //timezone conversion has happened properly Assert.AreEqual(new DateTime(2016, 8, 15, 10, 0, 0), bars[1].DTOpen.Value); }
private List <OHLCBar> GetData(HistoricalDataRequest request) { string url = ""; try { url = BuildRequestUrl(request); } catch (Exception ex) { RaiseEvent(Error, this, new ErrorArgs(-1, "BarChart Error building URL: " + ex.Message, request.RequestID)); return(null); } using (var client = new WebClient()) { string data; JObject parsedData; try { data = client.DownloadString(url); parsedData = JObject.Parse(data); if (parsedData["status"]["code"].ToString() != "200") { throw new Exception(parsedData["status"]["message"].ToString()); } } catch (Exception ex) { RaiseEvent(Error, this, new ErrorArgs(-1, "BarChart data download error: " + ex.Message, request.RequestID)); return(null); } try { var bars = BarChartUtils.ParseJson(parsedData, request); return(bars); } catch (Exception ex) { RaiseEvent(Error, this, new ErrorArgs(-1, "BarChart data parsing error: " + ex.Message, request.RequestID)); return(null); } } }