Пример #1
0
        public ConcurrentBag <List <Candle> > GetHistoryFromFile(ProgressDelegate progress, int period, DateTime fromDate, DateTime toDate)
        {
            IHistory h;
            int      num;
            Dictionary <string, string>    source           = ZerodhaOperations.LoadInstruments();
            ConcurrentBag <List <Candle> > resultCollection = new ConcurrentBag <List <Candle> >();
            int num2 = period;

            if (num2 > 10)
            {
                if (num2 == 15)
                {
                    h = new TradeHistory15();
                    goto TR_0000;
                }
                else if (num2 == 30)
                {
                    h = new TradeHistory30();
                    goto TR_0000;
                }
                else if (num2 == 60)
                {
                    h = new TradeHistory60();
                    goto TR_0000;
                }
            }
            else if (num2 == 5)
            {
                h = new TradeHistory5();
                goto TR_0000;
            }
            else if (num2 == 10)
            {
                h = new TradeHistory10();
                goto TR_0000;
            }
            else if (num2 == 100)
            {
                h = new TradeHistoryDaily();
                goto TR_0000;
            }
            {
                h = new TradeHistoryDaily();
            }
TR_0000:
            num = Environment.ProcessorCount;
            ParallelOptions parallelOptions = new ParallelOptions();

            parallelOptions.MaxDegreeOfParallelism = num;
            Parallel.ForEach <KeyValuePair <string, string> >(source, parallelOptions, delegate(KeyValuePair <string, string> i)
            {
                resultCollection.Add(h.GetHistoryFromFile(h.folderName, i.Value, fromDate.AddDays(-30), toDate));
                if (progress != null)
                {
                    progress($"Loading Data ... {i.Value}");
                }
            });
            return(resultCollection);
        }
Пример #2
0
        public ConcurrentBag <ConcurrentBag <Candle> > GetHistory(ProgressDelegate progress, int period, DateTime fromDate, DateTime toDate)
        {
            Dictionary <string, string>             instrumnets      = ZerodhaOperations.LoadInstruments();
            ConcurrentBag <ConcurrentBag <Candle> > resultCollection = new ConcurrentBag <ConcurrentBag <Candle> >();
            IHistory h;

            switch (period)
            {
            case 60:
                h = new TradeHistory60();
                break;

            case 30:
                h = new TradeHistory30();
                break;

            case 15:
                h = new TradeHistory15();
                break;

            case 5:
                h = new TradeHistory5();
                break;

            case 10:
                h = new TradeHistory10();
                break;

            default:
                h = new TradeHistoryDaily();
                break;
            }

            int cores = Environment.ProcessorCount;

            Parallel.ForEach(instrumnets, new ParallelOptions {
                MaxDegreeOfParallelism = cores
            }, (i) =>
            {
                resultCollection.Add(h.GetHistory(i.Key, i.Value, fromDate, toDate));
                progress(string.Format("Loading Data ... {0}", i.Value));
            });

            return(resultCollection);
        }