Пример #1
0
        private void SaveSeries(CandleSeries series)
        {
            CandleSeriesSaveInfo mySaveInfo = GetSpecInfo(series.Specification);

            if (mySaveInfo.AllCandlesInFile == null)
            {
                mySaveInfo.AllCandlesInFile = series.CandlesAll;

                int indexSpec = _candleSeriesSaveInfos.FindIndex(s => s.Specification == series.Specification);
                _candleSeriesSaveInfos[indexSpec].AllCandlesInFile = series.CandlesAll;
            }
            if (series.CandlesAll == null ||
                series.CandlesAll.Count == 0)
            {
                return;
            }

            Candle firstCandle = series.CandlesAll[0];
            Candle lastCandle  = series.CandlesAll[series.CandlesAll.Count - 1];

            if (firstCandle.TimeStart == mySaveInfo.LastCandleTime &&
                lastCandle.TimeStart == mySaveInfo.StartCandleTime &&
                lastCandle.Close == mySaveInfo.LastCandlePrice)
            {
                return;
            }

            mySaveInfo.InsertCandles(series.CandlesAll);

            if (Directory.Exists(_pathName) == false)
            {
                Directory.CreateDirectory(_pathName);
            }

            StreamWriter writer = new StreamWriter(_pathName + "\\" + series.Specification + ".txt");

            for (int i = 0; i < mySaveInfo.AllCandlesInFile.Count; i++)
            {
                writer.WriteLine(mySaveInfo.AllCandlesInFile[i].StringToSave);
            }

            writer.Close();
        }
Пример #2
0
        public CandleSeriesSaveInfo TryLoadCandle(string specification)
        {
            List <Candle> candlesFromServer = new List <Candle>();

            if (File.Exists(_pathName + "\\" + specification + ".txt"))
            {
                try
                {
                    using (StreamReader reader = new StreamReader(_pathName + "\\" + specification + ".txt"))
                    {
                        while (reader.EndOfStream == false)
                        {
                            string str       = reader.ReadLine();
                            Candle newCandle = new Candle();
                            newCandle.SetCandleFromString(str);
                            candlesFromServer.Add(newCandle);
                        }

                        reader.Close();
                    }
                }
                catch (Exception e)
                {
                    // ignore
                }
            }

            // далее смотрим есть ли сохранение в глобальном хранилище


            List <Candle> candlesFromOsData = new List <Candle>();

            string path = "Data\\ServersCandleTempData\\" + specification + ".txt";

            if (Directory.Exists("Data\\ServersCandleTempData") &&
                File.Exists(path))
            {
                try
                {
                    using (StreamReader reader = new StreamReader(path))
                    {
                        while (reader.EndOfStream == false)
                        {
                            string str       = reader.ReadLine();
                            Candle newCandle = new Candle();
                            newCandle.SetCandleFromString(str);
                            candlesFromOsData.Add(newCandle);
                        }

                        reader.Close();
                    }
                }
                catch (Exception e)
                {
                    // ignore
                }
            }

            if (candlesFromOsData.Count == 0 &&
                candlesFromServer.Count == 0)
            {
                return(null);
            }

            List <Candle> resultCandles = new List <Candle>();

            if (candlesFromOsData.Count != 0 &&
                candlesFromServer.Count != 0)
            {
                resultCandles = candlesFromServer;
                resultCandles.Merge(candlesFromOsData);
            }
            else if (candlesFromServer.Count != 0)
            {
                resultCandles = candlesFromServer;
            }
            else if (candlesFromOsData.Count != 0)
            {
                resultCandles = candlesFromOsData;
            }

            CandleSeriesSaveInfo myInfo = new CandleSeriesSaveInfo();

            myInfo.Specification = specification;
            myInfo.InsertCandles(resultCandles);

            return(myInfo);
        }