/// <summary>
 /// Initializes this history provider to work for the specified job
 /// </summary>
 /// <param name="parameters">The initialization parameters</param>
 public override void Initialize(HistoryProviderInitializeParameters parameters)
 {
     if (_initialized)
     {
         // let's make sure no one tries to change our parameters values
         throw new InvalidOperationException("BrokerageHistoryProvider can only be initialized once");
     }
     _initialized = true;
     _brokerage.Connect();
     _dataPermissionManager = parameters.DataPermissionManager;
 }
 /// <summary>
 /// Initializes this history provider to work for the specified job
 /// </summary>
 /// <param name="parameters">The initialization parameters</param>
 public override void Initialize(HistoryProviderInitializeParameters parameters)
 {
     if (_initialized)
     {
         // let's make sure no one tries to change our parameters values
         throw new InvalidOperationException("SubscriptionDataReaderHistoryProvider can only be initialized once");
     }
     _initialized                    = true;
     _mapFileProvider                = parameters.MapFileProvider;
     _dataCacheProvider              = parameters.DataCacheProvider;
     _factorFileProvider             = parameters.FactorFileProvider;
     _dataPermissionManager          = parameters.DataPermissionManager;
     _parallelHistoryRequestsEnabled = parameters.ParallelHistoryRequestsEnabled;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="UniverseSelection"/> class
 /// </summary>
 /// <param name="algorithm">The algorithm to add securities to</param>
 /// <param name="securityService">The security service</param>
 /// <param name="dataPermissionManager">The data permissions manager</param>
 public UniverseSelection(
     IAlgorithm algorithm,
     ISecurityService securityService,
     IDataPermissionManager dataPermissionManager)
 {
     _algorithm              = algorithm;
     _securityService        = securityService;
     _dataPermissionManager  = dataPermissionManager;
     _pendingRemovalsManager = new PendingRemovalsManager(algorithm.Transactions);
     _currencySubscriptionDataConfigManager = new CurrencySubscriptionDataConfigManager(algorithm.Portfolio.CashBook,
                                                                                        algorithm.Securities,
                                                                                        algorithm.SubscriptionManager,
                                                                                        _securityService,
                                                                                        dataPermissionManager.GetResolution(Resolution.Minute));
 }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UniverseSelection"/> class
 /// </summary>
 /// <param name="algorithm">The algorithm to add securities to</param>
 /// <param name="securityService">The security service</param>
 /// <param name="dataPermissionManager">The data permissions manager</param>
 /// <param name="dataProvider">The data provider to use</param>
 /// <param name="internalConfigResolution">The resolution to use for internal configuration</param>
 public UniverseSelection(
     IAlgorithm algorithm,
     ISecurityService securityService,
     IDataPermissionManager dataPermissionManager,
     IDataProvider dataProvider,
     Resolution internalConfigResolution = Resolution.Minute)
 {
     _dataProvider           = dataProvider;
     _algorithm              = algorithm;
     _securityService        = securityService;
     _dataPermissionManager  = dataPermissionManager;
     _pendingRemovalsManager = new PendingRemovalsManager(algorithm.Transactions);
     _currencySubscriptionDataConfigManager = new CurrencySubscriptionDataConfigManager(algorithm.Portfolio.CashBook,
                                                                                        algorithm.Securities,
                                                                                        algorithm.SubscriptionManager,
                                                                                        _securityService,
                                                                                        dataPermissionManager.GetResolution(Resolution.Minute));
     // TODO: next step is to merge currency internal subscriptions under the same 'internal manager' instance and we could move this directly into the DataManager class
     _internalSubscriptionManager = new InternalSubscriptionManager(_algorithm, internalConfigResolution);
 }
Exemple #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HistoryProviderInitializeParameters"/> class from the specified parameters
 /// </summary>
 /// <param name="job">The job</param>
 /// <param name="api">The API instance</param>
 /// <param name="dataProvider">Provider used to get data when it is not present on disk</param>
 /// <param name="dataCacheProvider">Provider used to cache history data files</param>
 /// <param name="mapFileProvider">Provider used to get a map file resolver to handle equity mapping</param>
 /// <param name="factorFileProvider">Provider used to get factor files to handle equity price scaling</param>
 /// <param name="statusUpdateAction">Function used to send status updates</param>
 /// <param name="parallelHistoryRequestsEnabled">True if parallel history requests are enabled</param>
 /// <param name="dataPermissionManager">The data permission manager to use</param>
 public HistoryProviderInitializeParameters(
     AlgorithmNodePacket job,
     IApi api,
     IDataProvider dataProvider,
     IDataCacheProvider dataCacheProvider,
     IMapFileProvider mapFileProvider,
     IFactorFileProvider factorFileProvider,
     Action <int> statusUpdateAction,
     bool parallelHistoryRequestsEnabled,
     IDataPermissionManager dataPermissionManager)
 {
     Job                            = job;
     Api                            = api;
     DataProvider                   = dataProvider;
     DataCacheProvider              = dataCacheProvider;
     MapFileProvider                = mapFileProvider;
     FactorFileProvider             = factorFileProvider;
     StatusUpdateAction             = statusUpdateAction;
     ParallelHistoryRequestsEnabled = parallelHistoryRequestsEnabled;
     DataPermissionManager          = dataPermissionManager;
 }
Exemple #6
0
        /// <summary>
        /// Creates a new instance of the DataManager
        /// </summary>
        public DataManager(
            IDataFeed dataFeed,
            UniverseSelection universeSelection,
            IAlgorithm algorithm,
            ITimeKeeper timeKeeper,
            MarketHoursDatabase marketHoursDatabase,
            bool liveMode,
            IRegisteredSecurityDataTypesProvider registeredTypesProvider,
            IDataPermissionManager dataPermissionManager)
        {
            _dataFeed         = dataFeed;
            UniverseSelection = universeSelection;
            UniverseSelection.SetDataManager(this);
            _algorithmSettings       = algorithm.Settings;
            AvailableDataTypes       = SubscriptionManager.DefaultDataTypes();
            _timeKeeper              = timeKeeper;
            _marketHoursDatabase     = marketHoursDatabase;
            _liveMode                = liveMode;
            _registeredTypesProvider = registeredTypesProvider;
            _dataPermissionManager   = dataPermissionManager;

            // wire ourselves up to receive notifications when universes are added/removed
            algorithm.UniverseManager.CollectionChanged += (sender, args) =>
            {
                switch (args.Action)
                {
                case NotifyCollectionChangedAction.Add:
                    foreach (var universe in args.NewItems.OfType <Universe>())
                    {
                        var config = universe.Configuration;
                        var start  = algorithm.UtcTime;

                        var end = algorithm.LiveMode ? Time.EndOfTime
                                : algorithm.EndDate.ConvertToUtc(algorithm.TimeZone);

                        Security security;
                        if (!algorithm.Securities.TryGetValue(config.Symbol, out security))
                        {
                            // create a canonical security object if it doesn't exist
                            security = new Security(
                                _marketHoursDatabase.GetExchangeHours(config),
                                config,
                                algorithm.Portfolio.CashBook[algorithm.AccountCurrency],
                                SymbolProperties.GetDefault(algorithm.AccountCurrency),
                                algorithm.Portfolio.CashBook,
                                RegisteredSecurityDataTypesProvider.Null,
                                new SecurityCache()
                                );
                        }
                        AddSubscription(
                            new SubscriptionRequest(true,
                                                    universe,
                                                    security,
                                                    config,
                                                    start,
                                                    end));
                    }
                    break;

                case NotifyCollectionChangedAction.Remove:
                    foreach (var universe in args.OldItems.OfType <Universe>())
                    {
                        // removing the subscription will be handled by the SubscriptionSynchronizer
                        // in the next loop as well as executing a UniverseSelection one last time.
                        if (!universe.DisposeRequested)
                        {
                            universe.Dispose();
                        }
                    }
                    break;

                default:
                    throw new NotImplementedException("The specified action is not implemented: " + args.Action);
                }
            };
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="LeanEngineAlgorithmHandlers"/> class from the specified handlers
        /// </summary>
        /// <param name="results">The result handler for communicating results from the algorithm</param>
        /// <param name="setup">The setup handler used to initialize algorithm state</param>
        /// <param name="dataFeed">The data feed handler used to pump data to the algorithm</param>
        /// <param name="transactions">The transaction handler used to process orders from the algorithm</param>
        /// <param name="realTime">The real time handler used to process real time events</param>
        /// <param name="mapFileProvider">The map file provider used to retrieve map files for the data feed</param>
        /// <param name="factorFileProvider">Map file provider used as a map file source for the data feed</param>
        /// <param name="dataProvider">file provider used to retrieve security data if it is not on the file system</param>
        /// <param name="alphas">The alpha handler used to process generated insights</param>
        /// <param name="objectStore">The object store used for persistence</param>
        /// <param name="dataPermissionsManager">The data permission manager to use</param>
        public LeanEngineAlgorithmHandlers(IResultHandler results,
                                           ISetupHandler setup,
                                           IDataFeed dataFeed,
                                           ITransactionHandler transactions,
                                           IRealTimeHandler realTime,
                                           IMapFileProvider mapFileProvider,
                                           IFactorFileProvider factorFileProvider,
                                           IDataProvider dataProvider,
                                           IAlphaHandler alphas,
                                           IObjectStore objectStore,
                                           IDataPermissionManager dataPermissionsManager
                                           )
        {
            if (results == null)
            {
                throw new ArgumentNullException(nameof(results));
            }
            if (setup == null)
            {
                throw new ArgumentNullException(nameof(setup));
            }
            if (dataFeed == null)
            {
                throw new ArgumentNullException(nameof(dataFeed));
            }
            if (transactions == null)
            {
                throw new ArgumentNullException(nameof(transactions));
            }
            if (realTime == null)
            {
                throw new ArgumentNullException(nameof(realTime));
            }
            if (mapFileProvider == null)
            {
                throw new ArgumentNullException(nameof(mapFileProvider));
            }
            if (factorFileProvider == null)
            {
                throw new ArgumentNullException(nameof(factorFileProvider));
            }
            if (dataProvider == null)
            {
                throw new ArgumentNullException(nameof(dataProvider));
            }
            if (alphas == null)
            {
                throw new ArgumentNullException(nameof(alphas));
            }
            if (objectStore == null)
            {
                throw new ArgumentNullException(nameof(objectStore));
            }
            if (dataPermissionsManager == null)
            {
                throw new ArgumentNullException(nameof(dataPermissionsManager));
            }

            Results                = results;
            Setup                  = setup;
            DataFeed               = dataFeed;
            Transactions           = transactions;
            RealTime               = realTime;
            MapFileProvider        = mapFileProvider;
            FactorFileProvider     = factorFileProvider;
            DataProvider           = dataProvider;
            Alphas                 = alphas;
            ObjectStore            = objectStore;
            DataPermissionsManager = dataPermissionsManager;
        }