public void Dispose() { if (_cfBroker != null) { _cfBroker.Dispose(); _cfBroker = null; } if (_connectionTimer != null) { _connectionTimer.Dispose(); _connectionTimer = null; } foreach (var dataSource in DataSources.Where(ds => ds.Value is IDisposable)) { ((IDisposable)dataSource.Value).Dispose(); } /*if (DataSources.ContainsKey("Interactive Brokers")) * { * ((IB)DataSources["Interactive Brokers"]).Dispose(); * }*/ if (_arrivedBars != null) { _arrivedBars.Dispose(); } }
public HistoricalDataBroker(IContinuousFuturesBroker cfBroker, IDataStorage localStorage, IEnumerable <QDMS.IHistoricalDataSource> additionalSources = null) { if (cfBroker == null) { throw new ArgumentNullException("cfBroker"); } if (localStorage == null) { throw new ArgumentNullException("localStorage"); } _dataStorage = localStorage; DataSources = new ObservableDictionary <string, QDMS.IHistoricalDataSource> { /* * { "Interactive Brokers", new IB(Properties.Settings.Default.histClientIBID) }, * { "Yahoo", new Yahoo() }, * { "Quandl", new Quandl() }, * { "FRED", new FRED() }, * { "Google", new Google() } */ }; //add the continuous futures broker to the data sources DataSources.Add("ContinuousFuturesBroker", cfBroker); //add additional sources if (additionalSources != null) { foreach (IHistoricalDataSource ds in additionalSources) { if (!DataSources.ContainsKey(ds.Name)) { DataSources.Add(ds.Name, ds); } } } foreach (IHistoricalDataSource ds in DataSources.Values) { ds.Error += DatasourceError; ds.HistoricalDataArrived += ExternalHistoricalDataArrived; ds.Disconnected += SourceDisconnects; } _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> /// Constructor /// </summary> /// <param name="additionalDataSources">Optional. Pass any additional data sources (for testing purposes).</param> /// <param name="cfBroker">IContinuousFuturesBroker (for testing purposes).</param> public RealTimeDataBroker(IContinuousFuturesBroker cfBroker, IDataStorage localStorage, IEnumerable <IRealTimeDataSource> additionalDataSources = null) { if (cfBroker == null) { throw new ArgumentNullException("cfBroker"); } _connectionTimer = new Timer(10000); _connectionTimer.Elapsed += ConnectionTimerElapsed; _connectionTimer.Start(); DataSources = new ObservableDictionary <string, IRealTimeDataSource> { { "SIM", new RealTimeSim() }/*, * {"Interactive Brokers", new IB(Properties.Settings.Default.rtdClientIBID)}*/ }; if (additionalDataSources != null) { foreach (IRealTimeDataSource ds in additionalDataSources) { DataSources.Add(ds.Name, ds); } } //we need to set the appropriate event methods for every data source foreach (IRealTimeDataSource s in DataSources.Values) { s.DataReceived += RealTimeData; s.TickReceived += TickReceived; s.Disconnected += SourceDisconnects; s.Error += s_Error; } ActiveStreams = new ConcurrentNotifierBlockingList <RealTimeStreamInfo>(); _arrivedBars = new BlockingCollection <RealTimeDataEventArgs>(); StreamSubscribersCount = new Dictionary <RealTimeStreamInfo, int>(); _aliases = new Dictionary <int, List <int> >(); _pendingCFRealTimeRequests = new Dictionary <int, RealTimeDataRequest>(); _continuousFuturesIDMap = new Dictionary <int, int>(); _requests = new Dictionary <int, RealTimeDataRequest>(); _usedIDs = new List <int>(); //connect to our data sources TryConnect(); //local storage _localStorage = localStorage; //start up the continuous futures broker _cfBroker = cfBroker; _cfBroker.FoundFrontContract += _cfBroker_FoundFrontContract; }
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(); } }