private void SendHistoricalRequest(int id, HistoricalDataRequest request) { Log(LogLevel.Info, string.Format("Sent historical data request to TWS. ID: {0}, Symbol: {1}, {2} back from {3}", id, request.Instrument.Symbol, TWSUtils.TimespanToDurationString((request.EndingDate - request.StartingDate), request.Frequency), request.EndingDate.ToString("yyyy-MM-dd hh:mm:ss"))); TimeZoneInfo exchangeTZ = request.Instrument.GetTZInfo(); //we need to convert time from the exchange TZ to Local...the ib client then converts it to UTC var endingDate = TimeZoneInfo.ConvertTime(request.EndingDate, exchangeTZ, TimeZoneInfo.Utc); try { _client.RequestHistoricalData ( id, TWSUtils.InstrumentToContract(request.Instrument), endingDate.ToString("yyyyMMdd HH:mm:ss") + " GMT", TWSUtils.TimespanToDurationString(request.EndingDate - request.StartingDate, request.Frequency), TWSUtils.BarSizeConverter(request.Frequency), GetDataType(request.Instrument), request.RTHOnly, false ); } catch (Exception ex) { Log(LogLevel.Error, "IB: Could not send historical data request: " + ex.Message); RaiseEvent(Error, this, new ErrorArgs(-1, "Could not send historical data request: " + ex.Message, id)); } }
private void SendHistoricalRequest(int id, HistoricalDataRequest request) { Log(LogLevel.Info, $"Sent historical data request to TWS. ID: {id}, Symbol: {request.Instrument.Symbol}, {TwsUtils.TimespanToDurationString(request.EndingDate - request.StartingDate, request.Frequency)} back from {request.EndingDate:yyyy-MM-dd hh:mm:ss}"); var exchangeTz = request.Instrument.GetTimeZoneInfo(); //we need to convert time from the exchange TZ to Local...the ib client then converts it to UTC var startingDate = TimeZoneInfo.ConvertTime(request.StartingDate, exchangeTz, TimeZoneInfo.Local); var endingDate = TimeZoneInfo.ConvertTime(request.EndingDate, exchangeTz, TimeZoneInfo.Local); try { client.RequestHistoricalData ( id, TwsUtils.InstrumentToContract(request.Instrument), endingDate, TwsUtils.TimespanToDurationString(endingDate - startingDate, request.Frequency), TwsUtils.BarSizeConverter(request.Frequency), GetDataType(), request.RTHOnly ? 1 : 0 ); } catch (Exception ex) { Log(LogLevel.Error, "IB: Could not send historical data request: " + ex.Message); RaiseEvent(Error, this, new ErrorArgs(-1, "Could not send historical data request: " + ex.Message, id)); } }