/// <summary> /// Use the specified delegate to get the current date. /// </summary> /// <param name="now">New delegate, or <c>null</c> to reset to the <see cref="DateTime.Now"/>.</param> /// <param name="utcNow">set DateTime.UtcNow</param> public static IDisposable Setup(Func<DateTime> now = null, Func<DateTime> utcNow = null) { if (now == null && utcNow != null) { throw new ArgumentException($"{nameof(utcNow)} should be setuped with {nameof(now)}"); } var old = TimeKeeper; TimeKeeper = now == null ? CurrentTimeKeeper.Instance : new DefiniteTimeKeeper(now, utcNow); return Disposable.Create(() => TimeKeeper = old); }
/// <summary> /// Use the specified delegate to get the current date. /// </summary> /// <param name="getter">New delegate, or <c>null</c> to reset to the <see cref="DateTime.Now"/>.</param> public static IDisposable Setup(Func<DateTime> getter = null) { var oldKeeper = TimeKeeper; TimeKeeper = getter == null ? CurrentTimeKeeper.Instance : new DefiniteTimeKeeper(getter); return Disposable.Create(()=>TimeKeeper=oldKeeper); }
public DataManagerStub(IDataFeed dataFeed, IAlgorithm algorithm, ITimeKeeper timeKeeper) : this(dataFeed, algorithm, timeKeeper, MarketHoursDatabase.FromDataFolder(), SymbolPropertiesDatabase.FromDataFolder()) { }
public DataManagerStub(IAlgorithm algorithm, ITimeKeeper timeKeeper) : this(new NullDataFeed(), algorithm, timeKeeper) { }
public DataManagerStub(ITimeKeeper timeKeeper) : this(new QCAlgorithm(), timeKeeper) { }
/// <summary> /// Creates a new instance of the DataManager /// </summary> public DataManager(IDataFeed dataFeed, UniverseSelection universeSelection, IAlgorithmSettings algorithmSettings, ITimeKeeper timeKeeper) { _dataFeed = dataFeed; UniverseSelection = universeSelection; _algorithmSettings = algorithmSettings; AvailableDataTypes = SubscriptionManager.DefaultDataTypes(); _timeKeeper = timeKeeper; }
/// <summary> /// Creates a new instance of the DataManager /// </summary> public DataManager( IDataFeed dataFeed, UniverseSelection universeSelection, IAlgorithm algorithm, ITimeKeeper timeKeeper, MarketHoursDatabase marketHoursDatabase) { _dataFeed = dataFeed; UniverseSelection = universeSelection; UniverseSelection.SetDataManager(this); _algorithmSettings = algorithm.Settings; AvailableDataTypes = SubscriptionManager.DefaultDataTypes(); _timeKeeper = timeKeeper; _marketHoursDatabase = marketHoursDatabase; _liveMode = algorithm.LiveMode; var liveStart = DateTime.UtcNow; // 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.LiveMode ? liveStart : 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 ); } 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> /// Initialise the algorithm security manager with two empty dictionaries /// </summary> /// <param name="timeKeeper"></param> public SecurityManager(ITimeKeeper timeKeeper) { _timeKeeper = timeKeeper; _securityManager = new ConcurrentDictionary <Symbol, Security>(); }