Esempio n. 1
0
        /// <summary>
        ///     historical data request
        /// </summary>
        public void RequestHistoricalData(HistoricalDataRequest request)
        {
            //Historical data limitations: https://www.interactivebrokers.com/en/software/api/apiguide/api/historical_data_limitations.htm
            //the issue here is that the request may not be fulfilled...so we need to keep track of the request
            //and if we get an error regarding its failure, send it again using a timer
            var originalReqID = ++requestCounter;

            historicalDataRequests.TryAdd(originalReqID, request);

            arrivedHistoricalData.TryAdd(originalReqID, new List <OHLCBar>());

            //if necessary, chop up the request into multiple chunks so as to abide
            //the historical data limitations
            if (TwsUtils.RequestObeysLimits(request))
            {
                //send the request, no need for subrequests
                SendHistoricalRequest(originalReqID, request);
            }
            else
            {
                //create subrequests, add them to the ID map, and send them to TWS
                var subRequests = SplitRequest(request);
                subRequestCount.Add(originalReqID, subRequests.Count);

                foreach (var subReq in subRequests)
                {
                    lock (subReqMapLock)
                    {
                        requestCounter++;
                        historicalDataRequests.TryAdd(requestCounter, subReq);
                        subRequestIDMap.Add(requestCounter, originalReqID);
                        SendHistoricalRequest(requestCounter, subReq);
                    }
                }
            }
        }