Пример #1
0
        private void OpenFile()
        {
            ClosePreviousFile();

            _fileDate = DateTime.Today;

            _filename = Path.Combine(_rootPath, GdaxFile.GetFilename(_fileDate, 60));
            _gdaxFile = GdaxFile.OpenWrite(_filename);
            Program.Log.Info($"File '{_filename}' is open");

            if (_productBook != null)
            {
                _gdaxFile.Serialize(_productBook, DateTime.UtcNow);
                Program.Log.Info("Current product book added to file");
            }
        }
Пример #2
0
        private IEnumerable <T> GetBooks <T>(ProductType productType, DateTime time, int granularity = MinGranularity) where T : class
        {
            bool dataExists;

            do
            {
                var filename = Path.Combine(_dataPath, GdaxFile.GetRelativePath(productType, granularity), GdaxFile.GetFilename(time, granularity));
                dataExists = File.Exists(filename);
                if (dataExists)
                {
                    using (var serialiser = GdaxFile.OpenRead(filename))
                    {
                        var eof = false;
                        do
                        {
                            T book = null;
                            try
                            {
                                var obj = serialiser.Deserialize();

                                // Return fake BookMatch for candles (for simulation from candle dump)
                                book = obj is T
                                    ? obj as T
                                    : ((Candle)obj).ToBookMatch(ProductType.BTC_EUR) as T;
                            }
                            catch (EndOfStreamException)
                            {
                                eof = true;
                            }
                            if (book != null) // && book.Time >= time)
                            {
                                yield return(book);
                            }
                        } while (!eof);

                        time += TimeSpan.FromDays(1);
                    }
                }
            } while (dataExists);
        }