Ejemplo n.º 1
0
        // TODO: Find ways to optimize the process of data retrieval from external data source, partial get or get all
        /// <summary>
        /// Initialize with tick provider
        /// </summary>
        /// <param name="provider">Tick provider</param>
        /// <returns>Task object</returns>
        public async Task InitWithTickProviderAsync(ITickProvider provider)
        {
            _provider = provider;

            var dependencies = GetType().GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.NonPublic)
                               .Where(f => typeof(IAnalyzable).IsAssignableFrom(f.FieldType))
                               .Select(f => (IAnalyzable)f.GetValue(this));

            foreach (var dependency in dependencies)
            {
                await dependency.InitWithTickProviderAsync(_provider.Clone()).ConfigureAwait(false);
            }

            await _provider.InitWithAnalyzableAsync(this).ConfigureAwait(false);

            if (_provider != null && _provider.IsReady)
            {
                var startTime = _cache.Any() ? _cache.Max(t => t.Key) : DateTime.MinValue;
                var ticks     = await _provider.GetAsync <TTick>(startTime).ConfigureAwait(false);

                foreach (var tick in ticks.Where(t => !_cache.ContainsKey(t.DateTime)))
                {
                    _cache.Add(tick.DateTime, tick);
                }
            }
        }