Exemple #1
0
        private async Task AddHistoryToSecurities(Dictionary <Symbol, Security?> securities, HistoryFlags historyFlags, CancellationToken ct)
        {
            List <Security> secs         = securities.Values.NotNull().ToList();
            var             dividendJobs = secs.Where(_ => historyFlags.HasFlag(HistoryFlags.DividendHistory))
                                           .Select(sec => (sec, History.GetTicksAsync <DividendTick>(sec.Symbol, ct))).ToList();
            var splitJobs = secs.Where(_ => historyFlags.HasFlag(HistoryFlags.SplitHistory))
                            .Select(sec => (sec, History.GetTicksAsync <SplitTick>(sec.Symbol, ct))).ToList();
            var priceJobs = secs.Where(_ => historyFlags.HasFlag(HistoryFlags.PriceHistory))
                            .Select(sec => (sec, History.GetTicksAsync <PriceTick>(sec.Symbol, ct))).ToList();

            List <Task> tasks = new();

            tasks.AddRange(dividendJobs.Select(t => t.Item2));
            tasks.AddRange(splitJobs.Select(t => t.Item2));
            tasks.AddRange(priceJobs.Select(t => t.Item2));

            await TaskExt.WhenAll(tasks).ConfigureAwait(false);

            foreach (var(security, task) in dividendJobs)
            {
                security.DividendHistory = task.Result;
            }
            foreach (var(security, task) in splitJobs)
            {
                security.SplitHistory = task.Result;
            }
            foreach (var(security, task) in priceJobs)
            {
                security.PriceHistory     = task.Result;
                security.PriceHistoryBase = GetPriceHistoryBase(task.Result, security);
            }
        }
Exemple #2
0
        private async Task <IEnumerable <JsonElement> > GetElements(HashSet <Symbol> symbols, CancellationToken ct)
        {
            // start tasks
            var tasks     = GetUris(symbols).Select(u => MakeRequest(u, ct));
            var responses = await TaskExt.WhenAll(tasks).ConfigureAwait(false);

            return(responses.SelectMany(x => x).ToList());
        }