コード例 #1
0
ファイル: HistoricalDataBroker.cs プロジェクト: alacazar/qdms
        public HistoricalDataBroker(IDataStorage localStorage = null, IEnumerable <IHistoricalDataSource> additionalSources = null, IContinuousFuturesBroker cfBroker = null)
        {
            _dataStorage = localStorage ?? DataStorageFactory.Get();

            DataSources = new ObservableDictionary <string, 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 ?? new ContinuousFuturesBroker(clientName: "HDBCFClient"));

            //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();
        }
コード例 #2
0
ファイル: RealTimeDataBroker.cs プロジェクト: alacazar/qdms
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="additionalDataSources">Optional. Pass any additional data sources (for testing purposes).</param>
        /// <param name="cfBroker">Optional. IContinuousFuturesBroker (for testing purposes).</param>
        public RealTimeDataBroker(IEnumerable <IRealTimeDataSource> additionalDataSources = null, IContinuousFuturesBroker cfBroker = null, IDataStorage localStorage = null)
        {
            _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.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 ?? DataStorageFactory.Get();

            //start up the continuous futures broker
            _cfBroker = cfBroker ?? new ContinuousFuturesBroker(clientName: "RTDBCFClient");
            _cfBroker.FoundFrontContract += _cfBroker_FoundFrontContract;
        }
コード例 #3
0
        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>();

            _requestHandlerThread = new Thread(Poll)
            {
                Name = "HDBPoller"
            };
            _requestHandlerThread.Start();

            TryConnect();
        }