private OhlcData CollectApi(TimeRange range, OhlcData results)
        {
            var apiresults = ApiAdapters.Select(x => x.GetRange(range)).FirstOrDefault(o => o.IsNotEmpty());

            results = results ?? new OhlcData(range.TimeResolution);
            results.Merge(apiresults);
            return(results);
        }
        private OhlcData ContinuousOrMergedStorage(TimeRange timeRange, bool allowLive = false)
        {
            var partials = new List <OhlcData>();

            foreach (var r in StorageAdapters.Select(x => x.GetRange(timeRange)))
            {
                if (r.IsEmpty())
                {
                    continue;
                }

                if (!allowLive)
                {
                    r.RemoveAll(x => x.CollectedNearLive);
                }

                if (r.IsCovering(timeRange))
                {
                    return(r.HasGap() ? null : r);
                }

                partials.Add(r);
            }

            if (!partials.Any())
            {
                return(null);
            }

            var mergedData = new OhlcData(partials.First());

            mergedData.ConvertedFrom = partials.Select(x => x.ConvertedFrom).FirstOrDefault(x => x != null) ?? mergedData.ConvertedFrom;

            foreach (var i in partials)
            {
                mergedData.Merge(i);
            }

            if (!timeRange.IsFromInfinity && mergedData.HasGap())
            {
                return(null);
            }

            return(mergedData);
        }