public void Dispose() { if (_connectionTimer != null) { _connectionTimer.Dispose(); _connectionTimer = null; } if (!_requestQueue.Reader.Completion.IsCompleted) { _requestQueue.Writer.Complete(); } _requestHandlerThread?.Join(); foreach (var ds in DataSources.Values) { ds.Disconnect(); } /* * if (DataSources.ContainsKey("Interactive Brokers")) * { * ((IB)DataSources["Interactive Brokers"]).Dispose(); * } */ if (DataSources.ContainsKey("ContinuousFuturesBroker")) { ((IContinuousFuturesBroker)DataSources["ContinuousFuturesBroker"]).Dispose(); } }
public void Dispose() { if (_connectionTimer != null) { _connectionTimer.Dispose(); _connectionTimer = null; } _eventWait.Set(); _requestHandlerThread?.Join(); foreach (var ds in DataSources.Values) { ds.Disconnect(); } /* * if (DataSources.ContainsKey("Interactive Brokers")) * { * ((IB)DataSources["Interactive Brokers"]).Dispose(); * } */ if (DataSources.ContainsKey("ContinuousFuturesBroker")) { ((IContinuousFuturesBroker)DataSources["ContinuousFuturesBroker"]).Dispose(); } }
private DbExecution CreateDbExecution(string dataSourceName, IEnumerable <string> filePaths) { DataSource dataSource = dataSourceName != null && DataSources.ContainsKey(dataSourceName) ? DataSources[dataSourceName] : null; return(new DbExecution(dataSource, filePaths)); }
/// <summary> /// Ensures that the data source specified is present and connected. /// Throws an exception otherwise. /// </summary> private void CheckDataSource(string name) { if (!DataSources.ContainsKey(name)) { throw new Exception(string.Format("Data source {0} does not exist.", name)); } if (!DataSources[name].Connected) { throw new Exception(string.Format("Data source {0} is not connected.", name)); } }
private ReportGroup CreateReportGroup(string name, string targetFolder, string dataSourceName, string reportServer, IEnumerable <Report> reports) { DataSource dataSource = dataSourceName != null && DataSources.ContainsKey(dataSourceName) ? DataSources[dataSourceName] : null; ReportServerInfo reportServerInfo = reportServer != null && ReportServers.ContainsKey(reportServer) ? ReportServers[reportServer] : null; return(new ReportGroup(name, targetFolder, dataSource, reportServerInfo, reports)); }
/// <summary> /// Ensures that the data source specified is present and connected. /// Throws an exception otherwise. /// </summary> private void CheckDataSource(HistoricalDataRequest request) { string name = request.Instrument.Datasource.Name; if (!DataSources.ContainsKey(name)) { throw new Exception(string.Format("Data source {0} does not exist.", name)); } if (request.DataLocation != DataLocation.LocalOnly && !DataSources[name].Connected) { throw new Exception(string.Format("Data source {0} is not connected.", name)); } }
protected override void OnComplete(int dataSourceId, PullersEventArgs e) { if (DataSources.ContainsKey(dataSourceId)) { DataSources[dataSourceId] = true; ExtensionMethods.TraceInformation("GEC:Completed:{0}", dataSourceId); } else { ExtensionMethods.TraceInformation("GEC:The data source {0} was not registered with global event '{1}'! This operation was ignored.", dataSourceId, Name); } CheckIfAllCompleted(e); }
/// <summary> /// Request to initiate a real time data stream. /// </summary> /// <param name="request">The request</param> /// <returns>True is the request was successful, false otherwise.</returns> public bool RequestRealTimeData(RealTimeDataRequest request) { request.AssignedID = GetUniqueRequestID(); lock (requestsLock) { requests.Add(request.AssignedID, request); } //if there is already an active stream of this instrument bool streamExists; lock (activeStreamsLock) { streamExists = ActiveStreams.Collection.Any(x => x.Instrument.ID == request.Instrument.ID); } if (streamExists) { IncrementSubscriberCount(request.Instrument); //log the request Log(LogLevel.Info, $"RTD Request for existing stream: {request.Instrument.Symbol} from {request.Instrument.Datasource.Name} @ {Enum.GetName(typeof(BarSize), request.Frequency)}"); return(true); } if (DataSources.ContainsKey(request.Instrument.Datasource.Name) && //make sure the datasource is present & connected DataSources[request.Instrument.Datasource.Name].Connected) { ForwardRtdRequest(request); return(true); } if (!DataSources.ContainsKey(request.Instrument.Datasource.Name)) { throw new Exception("No such datasource."); } if (!DataSources[request.Instrument.Datasource.Name].Connected) { throw new Exception("Datasource not connected."); } return(false); }
public void Dispose() { if (_cfBroker != null) { _cfBroker.Dispose(); _cfBroker = null; } if (_connectionTimer != null) { _connectionTimer.Dispose(); _connectionTimer = null; } if (DataSources.ContainsKey("Interactive Brokers")) { ((IB)DataSources["Interactive Brokers"]).Dispose(); } if (_arrivedBars != null) { _arrivedBars.Dispose(); } }
public HistoricalDataBroker(IDataStorage localStorage, IEnumerable <IHistoricalDataSource> additionalSources = null) { if (localStorage == null) { throw new ArgumentNullException(nameof(localStorage)); } dataStorage = localStorage; //add the continuous futures broker to the data sources //add additional sources if (additionalSources != null) { foreach (IHistoricalDataSource ds in additionalSources) { if (!DataSources.ContainsKey(ds.Name)) { ds.Error += DatasourceError; ds.HistoricalDataArrived += ExternalHistoricalDataArrived; ds.Disconnected += SourceDisconnects; DataSources.Add(ds.Name, ds); } } } dataStorage.Error += DatasourceError; dataStorage.HistoricalDataArrived += LocalStorageHistoricalDataArrived; connectionTimer = new Timer(10000); connectionTimer.Elapsed += ConnectionTimerElapsed; connectionTimer.Start(); originalRequests = new ConcurrentDictionary <int, HistoricalDataRequest>(); subRequests = new ConcurrentDictionary <int, List <HistoricalDataRequest> >(); usedIDs = new List <int>(); TryConnect(); }
/// <summary> /// Request to initiate a real time data stream. /// </summary> /// <param name="request">The request</param> /// <returns>True is the request was successful, false otherwise.</returns> public bool RequestRealTimeData(RealTimeDataRequest request) { request.AssignedID = GetUniqueRequestID(); lock (_requestsLock) { _requests.Add(request.AssignedID, request); } //if there is already an active stream of this instrument bool streamExists; lock (_activeStreamsLock) { streamExists = ActiveStreams.Collection.Any(x => x.Instrument.ID == request.Instrument.ID && x.Frequency == request.Frequency); } if (streamExists) { IncrementSubscriberCount(request.Instrument); //log the request Log(LogLevel.Info, string.Format("RTD Request for existing stream: {0} from {1} @ {2}", request.Instrument.Symbol, request.Instrument.Datasource.Name, Enum.GetName(typeof(BarSize), request.Frequency))); return(true); } else if (DataSources.ContainsKey(request.Instrument.Datasource.Name) && //make sure the datasource is present & connected DataSources[request.Instrument.Datasource.Name].Connected) { if (request.Instrument.IsContinuousFuture) { //if it's a CF, we need to find which contract is currently "used" //and request that one int frontContractRequestID; lock (_cfRequestLock) { frontContractRequestID = _cfBroker.RequestFrontContract(request.Instrument); _pendingCFRealTimeRequests.Add(frontContractRequestID, request); } Log(LogLevel.Info, string.Format("Request for CF RTD, sent front contract request, RT request ID: {0}, FC request ID: {1}", request.AssignedID, frontContractRequestID)); //the asynchronous nature of the request for the front month creates a lot of problems //we either have to abandon the REP socket and use something asynchronous there //which creates a ton of problems (we need unique IDs for every request and so forth) //or we send back "success" without actually knowing if the request for the //continuous futures real time data was successful or not! //For now I have chosen the latter approach. } else //NOT a continuous future, just a normal instrument: do standard request procedure { ForwardRTDRequest(request); } return(true); } else //no new request was made, send the client the reason why { if (!DataSources.ContainsKey(request.Instrument.Datasource.Name)) { throw new Exception("No such datasource."); } if (!DataSources[request.Instrument.Datasource.Name].Connected) { throw new Exception("Datasource not connected."); } return(false); } }
public bool HasEntry(int dataSourceId) { return(DataSources.ContainsKey(dataSourceId)); }