Esempio n. 1
0
        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));
            }
        }