Esempio n. 1
0
        internal static void InsertBatch(IEnumerable <CIKInfo> cikInfos, List <IEXDataType> listIexDataTypes, ChartOption chartOption, int itemCount, Period period)
        {
            int total      = cikInfos.Count();
            int count      = 0;
            int batchCount = 50;
            CompanyCollection companyRepo = new CompanyCollection();

            do
            {
                var symbols = cikInfos.Select(x => x.Ticker).Skip(count).Take(batchCount).ToArray();
                count += symbols.Count();

                var dictSymbolComp = companyRepo.GetCompanyId(symbols.ToList());
                //get data
                IEXClientHandler response = new IEXClientHandler();
                var results = response.GetBatchReport(symbols, listIexDataTypes, ChartOption._1d, itemCount, period);


                //insert to db
                var comp  = new MongoDBRepository <Company>(nameof(Company));
                var stat  = new MongoDBRepository <Stat>("IEXStat");
                var fin   = new MongoDBRepository <Financial>(nameof(Financial));
                var quote = new MongoDBRepository <Quote>("Quote");


                foreach (string symbol in results.Keys)
                {
                    ObjectId compId = ObjectId.GenerateNewId(); //ObjectId.GenerateNewId().ToString();
                    results[symbol].Company._id = compId;
                    if (results[symbol].Company != null)
                    {
                        comp.MongoInsert(results[symbol].Company).Wait();
                    }

                    if (results[symbol].Stat != null)
                    {
                        results[symbol].Stat.companyId = compId;
                        stat.MongoInsert(results[symbol].Stat).Wait();
                    }

                    if (results[symbol].Financials.financials != null)
                    {
                        Parallel.For(0, results[symbol].Financials.financials.Count, (i) =>
                        {
                            results[symbol].Financials.financials[i].companyId = compId;
                        });

                        fin.MongoInsertMany(results[symbol].Financials.financials).Wait();
                    }

                    if (results[symbol].Quote != null)
                    {
                        results[symbol].Quote.companyId = compId;
                        quote.MongoInsert(results[symbol].Quote).Wait();
                    }
                }
            } while (count < total);
        }
Esempio n. 2
0
        public void BatchProcessSymbolsTest()
        {
            //getting list of company
            string[] symbols = new string[] { "ge", "appl", "msft", "ipar", "gntx" };
            //get data
            IEXClientHandler response = new IEXClientHandler();
            var results = response.GetBatchReport(symbols, new List <IEXDataType> {
                IEXDataType.company
            }, IEXApiHandler.IEXData.Stock.ChartOption._1d, 1);

            Assert.NotNull(results);
            //insert to db
            CompanyCollection repo = new CompanyCollection();

            repo.MongoInsertMany(results.Values.Select(x => x.Company).Distinct().ToList()).Wait();
        }