Exemplo n.º 1
0
        Bars IBars2WLBars(string symbol, WealthLab.BarScale scale, int barInterval, IBars bars, bool includePartialBar)
        {
            l.Debug("IBars2WLBars");
            WealthLab.Bars result = new WealthLab.Bars(symbol, scale, barInterval);

            IBar b = bars.First;

            while (b != bars.Last)
            {
                result.Add(b.GetDateTime(), b.Open, b.High, b.Low, b.Close, b.Volume);
                b = bars.GetNext(b);
            }

//            bars.NewBarEvent += bars_NewBarEvent;

            if (b != null) // а значит указывает на Last
            {
                if ((!includePartialBar) && ((result.Date[result.Count - 1] + bars.scale.ToTimeSpan()) < (DateTime.Now - sec3)))
                {
                    result.Add(b.GetDateTime(), b.Open, b.High, b.Low, b.Close, b.Volume);
                }
                if (includePartialBar)
                {
                    result.Open.PartialValue   = b.Open;;
                    result.Close.PartialValue  = b.Close;
                    result.High.PartialValue   = b.High;
                    result.Low.PartialValue    = b.Low;
                    result.Volume.PartialValue = b.Volume;
                }
            }

            l.Debug("IBars2WLBars result.Count " + result.Count);
            return(result);
        }
Exemplo n.º 2
0
        // Объеденяет файлы
        public void Concat(int count = 100 *1024 *1024 / Simple.Tick.Size)
        {
            _lock.AcquireWriterLock(10000);
            try
            {
                List <TicksFile> newTicksFileList = new List <TicksFile>();

                if (Count <= count)
                {
                    //Объединяю всё в один файл
                    newTicksFileList.Add(
                        forConcatCreateFile(DateTime.MinValue, DateTime.MaxValue, string.Empty, Count)
                        );
                }
                else
                {
                    // Как минимум разбиваю по годам
                    IBar bar      = First;
                    int  year     = bar.GetDateTime().Year;
                    int  lastYear = Last.GetDateTime().Year;
                    while (year <= lastYear)
                    {
                        // расчитываю кво баров в данном году
                        int barCountOfYear = 0;
                        int nextYear       = DateTime2Int.Int(new DateTime(year + 1, 1, 1));
                        while ((bar != null) && (bar.DT < nextYear))
                        {
                            ++barCountOfYear;
                            bar = GetNext(bar);
                        }
                        if (barCountOfYear <= count)
                        {
                            //Объединяю год в один файл
                            if (barCountOfYear > 0)
                            {
                                newTicksFileList.Add(
                                    forConcatCreateFile(new DateTime(year, 1, 1), new DateTime(year + 1, 1, 1).AddSeconds(-1), " yyyy", barCountOfYear)
                                    );
                            }
                        }
                        else
                        {
                            //Разбивыаю по месяцам
                            for (int i = 1; i <= 12; ++i)
                            {
                                TicksFile tf = forConcatCreateFile(new DateTime(year, i, 1), new DateTime(year, i, 1).AddMonths(1).AddSeconds(-1), " yyyyMM", (barCountOfYear / 12 * 2));
                                if (tf.Count > 0)
                                {
                                    newTicksFileList.Add(tf);
                                }
                            }
                        }
                        ++year;
                    }
                }
                // Удаляю все существующие файлы
                staticLock.AcquireWriterLock(10000);
                try
                {
                    foreach (TicksFile tf in ticksFileList)
                    {
                        if (!newTicksFileList.Contains(tf))
                        {
                            tf.Delete();
                            allTicksFileList.Remove(tf); // TODO возможно здесь баг, т.к. после Concat файл CaptionOfAllFiles.txt был больше 15M, а после пересоздания стал 800K
                        }
                    }

                    ticksFileList = newTicksFileList;
                    foreach (TicksFile tf in ticksFileList)
                    {
                        if (!allTicksFileList.Contains(tf))
                        {
                            allTicksFileList.Add(tf);
                        }
                    }
                }
                finally
                {
                    staticLock.ReleaseWriterLock();
                }
            }
            finally
            {
                _lock.ReleaseWriterLock();
            }
        }