Exemple #1
0
 public void CancelRealTimeData(int requestID)
 {
     if (_reverseRequestIDMap.TryGetValue(requestID, out int twsId))
     {
         _client.CancelRealTimeBars(twsId);
     }
     else
     {
         RaiseEvent(Error, this, new ErrorArgs(-1, "Real time stream requested for cancelation not found. ID: " + requestID));
     }
 }
Exemple #2
0
 public void CancelRealTimeData(int requestID)
 {
     _client.CancelRealTimeBars(requestID);
 }
Exemple #3
0
        /// <summary>
        /// This event is raised in the case of some error
        /// This includes pacing violations, in which case we re-enqueue the request.
        /// </summary>
        private void _client_Error(object sender, ErrorEventArgs e)
        {
            //if we asked for too much real time data at once, we need to re-queue the failed request
            if ((int)e.ErrorCode == 420) //a real time pacing violation
            {
                HandleRealTimePacingViolationError(e);
            }
            else if ((int)e.ErrorCode == 162) //a historical data pacing violation
            {
                HandleHistoricalDataPacingViolationError(e);
            }
            else if ((int)e.ErrorCode == 200) //No security definition has been found for the request.
            {
                HandleNoSecurityDefinitionError(e);
            }
            else if ((int)e.ErrorCode == 10225) //bust event stops real-time bars
            {
                RealTimeDataRequest req;
                if (_realTimeDataRequests.TryGetValue(e.TickerId, out req))
                {
                    _logger.Error(string.Format(" RT Req: {0} @ {1}. Restarting stream.",
                                                req.Instrument.Symbol,
                                                req.Frequency));

                    _client.CancelRealTimeBars(e.TickerId);

                    RestartRealtimeStream(req);
                }
                else
                {
                    _logger.Error(e.ErrorMsg + " - Unable to find corresponding request");
                }
            }

            //different messages depending on the type of request
            var errorArgs = TWSUtils.ConvertErrorArguments(e);
            HistoricalDataRequest histReq;
            RealTimeDataRequest   rtReq;
            var isHistorical = _historicalDataRequests.TryGetValue(e.TickerId, out histReq);

            if (isHistorical)
            {
                int origId = _subRequestIDMap.ContainsKey(histReq.RequestID)
                    ? _subRequestIDMap[histReq.RequestID]
                    : histReq.RequestID;

                errorArgs.ErrorMessage += string.Format(" Historical Req: {0} @ {1} From {2} To {3} - TickerId: {4}  ReqID: {5}",
                                                        histReq.Instrument.Symbol,
                                                        histReq.Frequency,
                                                        histReq.StartingDate,
                                                        histReq.EndingDate,
                                                        e.TickerId,
                                                        histReq.RequestID);

                errorArgs.RequestID = origId;
            }
            else if (_realTimeDataRequests.TryGetValue(e.TickerId, out rtReq)) //it's a real time request
            {
                errorArgs.ErrorMessage += string.Format(" RT Req: {0} @ {1}",
                                                        rtReq.Instrument.Symbol,
                                                        rtReq.Frequency);

                errorArgs.RequestID = rtReq.RequestID;
            }

            RaiseEvent(Error, this, errorArgs);
        }