Beispiel #1
0
        public void HistoricalRequestsAreSplitToRespectRequestLimits()
        {
            int[] requestCount = { 0 };

            _ibClientMock.Setup(
                x => x.RequestHistoricalData(
                    It.IsAny <int>(),
                    It.IsAny <Contract>(),
                    It.IsAny <DateTime>(),
                    It.IsAny <string>(),
                    It.IsAny <BarSize>(),
                    It.IsAny <HistoricalDataType>(),
                    It.IsAny <int>(),
                    It.IsAny <List <TagValue> >()))
            .Callback(() => requestCount[0]++);

            var requests = new Dictionary <KeyValuePair <BarSize, int>, int> //left side is barsize/seconds, right side is expected splits
            {
                { new KeyValuePair <BarSize, int>(BarSize.OneDay, 500 * 24 * 3600), 2 },
                { new KeyValuePair <BarSize, int>(BarSize.OneHour, 75 * 24 * 3600), 3 },
                { new KeyValuePair <BarSize, int>(BarSize.ThirtyMinutes, 22 * 24 * 3600), 4 },
                { new KeyValuePair <BarSize, int>(BarSize.OneMinute, 9 * 24 * 3600), 5 },
                { new KeyValuePair <BarSize, int>(BarSize.ThirtySeconds, 40 * 3600), 2 },
                { new KeyValuePair <BarSize, int>(BarSize.FifteenSeconds, 4 * 14400), 5 },
                { new KeyValuePair <BarSize, int>(BarSize.FiveSeconds, 2 * 7200), 3 },
                { new KeyValuePair <BarSize, int>(BarSize.OneSecond, 10 * 1800), 11 }
            };

            var inst = new Instrument();

            foreach (var kvp in requests)
            {
                _ibDatasource.RequestHistoricalData(new HistoricalDataRequest(
                                                        inst,
                                                        TWSUtils.BarSizeConverter(kvp.Key.Key),
                                                        DateTime.Now.AddSeconds(-kvp.Key.Value),
                                                        DateTime.Now,
                                                        dataLocation: DataLocation.ExternalOnly));

                Assert.AreEqual(kvp.Value, requestCount[0], kvp.Key.Key.ToString());
                requestCount[0] = 0;
            }
        }