public void HistoricalDataUpdateCorrectlyRaisesRealTimeDataEvent() { //need to set it up from the start w/ the right setting _ibClientMock = new Mock <IIBClient>(); _ibClientMock.Setup(x => x.Connect(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>())).Callback(() => _clientIsConnected = true); _ibClientMock.Setup(x => x.Connected).Returns(() => _clientIsConnected); var settings = new Mock <ISettings>(); settings.Setup(x => x.ibClientHost).Returns(Host); settings.Setup(x => x.ibUseNewRealTimeDataSystem).Returns(true); _ibDatasource = new IB(settings.Object, client: _ibClientMock.Object); _ibDatasource.Connect(); var exchange = new Exchange { ID = 1, Name = "Ex", Timezone = "Pacific Standard Time" }; var req = new RealTimeDataRequest { Instrument = new Instrument { ID = 1, Symbol = "SPY", UnderlyingSymbol = "SPY", Exchange = exchange, Currency = "USD", Type = InstrumentType.Stock }, Frequency = QDMS.BarSize.FiveSeconds, RTHOnly = true }; int requestID = -1; _ibClientMock .Setup(x => x.RequestHistoricalData( It.IsAny <int>(), It.IsAny <Contract>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <QDMSIBClient.BarSize>(), It.IsAny <HistoricalDataType>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <List <TagValue> >())) .Callback <int, Contract, string, string, BarSize, HistoricalDataType, bool, bool, List <TagValue> >((y, a, b, c, d, e, f, g, h) => requestID = y); _ibDatasource.RequestRealTimeData(req); bool received = false; _ibDatasource.DataReceived += (sender, e) => received = true; _ibClientMock.Raise(x => x.HistoricalDataUpdate += null, new HistoricalDataEventArgs(requestID, new Bar(new DateTime(2014, 1, 15), 1, 2, 3, 4, 5, 5, 3))); Assert.IsTrue(received); }
public void RealTimeRequestsAreReSentAfterARealTimeDataPacingViolation() { var exchange = new Exchange { ID = 1, Name = "Ex", Timezone = "Pacific Standard Time" }; var req = new RealTimeDataRequest { Instrument = new Instrument { ID = 1, Symbol = "SPY", Exchange = exchange }, Frequency = QDMS.BarSize.FiveSeconds, RTHOnly = true }; int requestID = 0; _ibClientMock .Setup(x => x.RequestRealTimeBars( It.IsAny <int>(), It.IsAny <Contract>(), It.IsAny <int>(), It.IsAny <RealTimeBarType>(), It.IsAny <bool>(), It.IsAny <List <TagValue> >())) .Callback <int, Contract, int, RealTimeBarType, bool, List <TagValue> >((y, a, b, c, d, e) => requestID = y); _ibDatasource.RequestRealTimeData(req); _ibClientMock.Raise(x => x.Error += null, new ErrorEventArgs(requestID, (ErrorMessage)420, "")); Thread.Sleep(25000); _ibClientMock.Verify(x => x.RequestRealTimeBars( It.IsAny <int>(), It.IsAny <Contract>(), It.IsAny <int>(), It.IsAny <RealTimeBarType>(), It.IsAny <bool>(), It.IsAny <List <TagValue> >()), Times.Exactly(2)); }