/// <summary> /// This event is raised when historical data arrives from TWS /// </summary> private void _client_HistoricalData(object sender, QDMSIBClient.HistoricalDataEventArgs e) { int id; lock (_subReqMapLock) { //if the data is arriving for a sub-request, we must get the id of the original request first //otherwise it's just the same id id = _subRequestIDMap.ContainsKey(e.RequestId) ? _subRequestIDMap[e.RequestId] : e.RequestId; } if (!_historicalDataRequests.ContainsKey(id)) { //this means we don't have a request with this key. If all works well, //it should mean that this is actually a realtime data request using the new system return; } var bar = TWSUtils.HistoricalDataEventArgsToOHLCBar(e); //stocks need to have their volumes multiplied by 100, I think all other instrument types do not if (_historicalDataRequests[id].Instrument.Type == InstrumentType.Stock) { bar.Volume *= 100; } _arrivedHistoricalData[id].Add(bar); }
private void _client_HistoricalDataUpdate(object sender, QDMSIBClient.HistoricalDataEventArgs e) { if (e.Bar.Volume < 0) { return; } var originalRequest = _realTimeDataRequests[e.RequestId]; var args = TWSUtils.HistoricalDataEventArgsToRealTimeDataEventArgs(e, originalRequest.Instrument.ID.Value, _requestIDMap[e.RequestId]); RaiseEvent(DataReceived, this, args); }
public static OHLCBar HistoricalDataEventArgsToOHLCBar(QDMSIBClient.HistoricalDataEventArgs e) { var bar = new OHLCBar { DTOpen = e.Bar.Time, Open = (decimal)e.Bar.Open, High = (decimal)e.Bar.High, Low = (decimal)e.Bar.Low, Close = (decimal)e.Bar.Close, Volume = e.Bar.Volume, }; return(bar); }
public static RealTimeDataEventArgs HistoricalDataEventArgsToRealTimeDataEventArgs(QDMSIBClient.HistoricalDataEventArgs e, int instrumentId, int reqId) { var rtdea = new RealTimeDataEventArgs(instrumentId, QDMS.BarSize.FiveSeconds, MyUtils.ConvertToTimestamp(e.Bar.Time), (decimal)e.Bar.Open, (decimal)e.Bar.High, (decimal)e.Bar.Low, (decimal)e.Bar.Close, e.Bar.Volume, e.Bar.WAP, e.Bar.Count, reqId); return(rtdea); }