コード例 #1
0
        public NCDFile(NCDFileType ncdFileType, string path)
        {
            _ncdFileType = ncdFileType;
            if (!File.Exists(path))
            {
                throw new FileNotFoundException();
            }
            _br = new BinaryReader(new MemoryStream(File.ReadAllBytes(path)));

            _fileName           = Path.GetFileName(path);
            _tickSizeTime       = _br.ReadUInt32();
            _tickSizePrice      = _br.ReadDouble();
            _fileStartPrice     = _lastPrice = _br.ReadDouble();
            _fileStartDateTicks = (long)_br.ReadUInt64();
            _fileStartDateTime  = _lastDateTime = TimeZoneInfo.ConvertTime(
                new DateTime((long)_fileStartDateTicks),
                TimeZoneInfo.Local /*ApplicationTimeZone*/);
        }
コード例 #2
0
        public NCDFiles(NCDFileType ncdFileType, string instrumentId, DateTime date, int numberDaysForward = 0, int numberDaysBack = 0)
        {
            _NCDFileType  = ncdFileType;
            _instrumentId = instrumentId;
            // build file list
            DateTime startDate = date.Date.AddDays(-numberDaysBack);
            DateTime endDate   = date.Date.AddDays(numberDaysForward);

            string instrumentDataPath = null;

            if (_NCDFileType == NCDFileType.Minute)
            {
                instrumentDataPath = Path.Combine(NinjaTrader.GlobalOptions.HistoricalDataPath, "minute", instrumentId);
            }
            else if (_NCDFileType == NCDFileType.Tick)
            {
                instrumentDataPath = Path.Combine(NinjaTrader.GlobalOptions.HistoricalDataPath, "tick", instrumentId);
            }
            else
            {
                throw new Exception($"Invalid NCDFileType: {_NCDFileType}");
            }

            _files = new List <string>(
                Directory.GetFiles(instrumentDataPath).Where(filePath =>
                                                             (DateTime.ParseExact(Path.GetFileName(filePath).Substring(0, 8), "yyyyMMdd", CultureInfo.InvariantCulture)
                                                              .Between(startDate, endDate))).OrderBy(filePath => filePath)
                );

            if (_files.Count == 0)
            {
                if (startDate == endDate)
                {
                    throw new Exception($"No files found for date: {date:MM/dd/yyyy}.");
                }
                else
                {
                    throw new Exception($"No files found for date range: {startDate:MM/dd/yyyy} - {endDate:MM/dd/yyyy}.");
                }
            }
            _filesLeft = new List <string>(_files);

            GetNextFile();
        }