Esempio n. 1
0
        /// <summary>
        /// Write this file to disk.
        /// </summary>
        /// <param name="filePath">The full path to the new file</param>
        /// <param name="data">The data to write as a string</param>
        /// <param name="date">The date the data represents</param>
        private void WriteFile(string filePath, string data, DateTime date)
        {
            var tempFilePath = filePath + ".tmp";

            data = data.TrimEnd();
            if (File.Exists(filePath) && !_appendToZips)
            {
                File.Delete(filePath);
                Log.Trace("LeanDataWriter.Write(): Existing deleted: " + filePath);
            }

            // Create the directory if it doesnt exist
            Directory.CreateDirectory(Path.GetDirectoryName(filePath));

            if (_appendToZips)
            {
                var entryName = LeanData.GenerateZipEntryName(_symbol, date, _resolution, _tickType);
                Compression.ZipCreateAppendData(filePath, entryName, data, true);
                Log.Trace("LeanDataWriter.Write(): Appended: " + filePath);
            }
            else
            {
                // Write out this data string to a zip file
                Compression.Zip(data, tempFilePath, LeanData.GenerateZipEntryName(_symbol, date, _resolution, _tickType));

                // Move temp file to the final destination with the appropriate name
                File.Move(tempFilePath, filePath);
                Log.Trace("LeanDataWriter.Write(): Created: " + filePath);
            }
        }
        private void WriteHourAndDailyData(IEnumerable <BaseData> data)
        {
            var sb = new StringBuilder();

            var volData = data.Cast <FxcmVolume>();

            foreach (var obs in volData)
            {
                sb.AppendLine(string.Format("{0:yyyyMMdd HH:mm},{1},{2}", obs.Time, obs.Value,
                                            obs.Transactions));
            }
            var data_to_save = sb.ToString();

            var filename    = _symbol.Value.ToLower() + "_volume";
            var csvFilePath = Path.Combine(FolderPath, filename + ".csv");
            var zipFilePath = csvFilePath.Replace(".csv", ".zip");

            if (File.Exists(zipFilePath))
            {
                File.Delete(zipFilePath);
            }
            File.WriteAllText(csvFilePath, data_to_save);
            // Write out this data string to a zip file
            Compression.Zip(csvFilePath, Path.GetFileName(csvFilePath));
        }
Esempio n. 3
0
        /// <summary>
        /// Write this file to disk
        /// </summary>
        private void WriteFile(string data, string filename, DateTime time)
        {
            filename = filename.TrimEnd();
            if (File.Exists(data))
            {
                File.Delete(data);
                Log.Trace("LeanDataWriter.Write(): Existing deleted: " + data);
            }
            // Create the directory if it doesnt exist
            Directory.CreateDirectory(Path.GetDirectoryName(data));

            // Write out this data string to a zip file
            Compression.Zip(filename, data, Compression.CreateZipEntryName(_symbol, _securityType, time, _resolution, _dataType));
            Log.Trace("LeanDataWriter.Write(): Created: " + data);
        }
Esempio n. 4
0
        private void WriteHourAndDailyData(IEnumerable <BaseData> data)
        {
            var sb = new StringBuilder();

            var volData = data.Cast <FxcmVolume>();

            foreach (var obs in volData)
            {
                sb.AppendLine(string.Format("{0:yyyyMMdd HH:mm},{1},{2}", obs.Time, obs.Value,
                                            obs.Transactions));
            }

            var filename = _symbol.Value.ToLower() + "_volume.csv";
            var filePath = Path.Combine(_folderPath, filename);

            File.WriteAllText(filePath, sb.ToString());
            // Write out this data string to a zip file
            Compression.Zip(filePath, filename);
        }
        private void WriteMinuteData(IEnumerable <BaseData> data)
        {
            var sb        = new StringBuilder();
            var volData   = data.Cast <FxcmVolume>();
            var dataByDay = volData.GroupBy(o => o.Time.Date);

            foreach (var dayOfData in dataByDay)
            {
                foreach (var obs in dayOfData)
                {
                    sb.AppendLine($"{obs.Time.TimeOfDay.TotalMilliseconds.ToStringInvariant()},{obs.Value.ToStringInvariant()},{obs.Transactions}");
                }
                var filename = $"{dayOfData.Key.ToStringInvariant("yyyyMMdd")}_volume.csv";
                var filePath = Path.Combine(FolderPath, filename);
                File.WriteAllText(filePath, sb.ToString());
                // Write out this data string to a zip file
                Compression.Zip(filePath, filename);
                sb.Clear();
            }
        }
Esempio n. 6
0
        private void WriteMinuteData(IEnumerable <BaseData> data)
        {
            var sb        = new StringBuilder();
            var volData   = data.Cast <FxcmVolume>();
            var dataByDay = volData.GroupBy(o => o.Time.Date);

            foreach (var dayOfData in dataByDay)
            {
                foreach (var obs in dayOfData)
                {
                    sb.AppendLine(string.Format("{0},{1},{2}", obs.Time.TimeOfDay.TotalMilliseconds, obs.Value,
                                                obs.Transactions));
                }
                var filename = string.Format("{0:yyyyMMdd}_volume.csv", dayOfData.Key);
                var filePath = Path.Combine(_folderPath, filename);
                File.WriteAllText(filePath, sb.ToString());
                // Write out this data string to a zip file
                Compression.Zip(filePath, filename);
                sb.Clear();
            }
        }
        /// <summary>
        /// Write this file to disk.
        /// </summary>
        /// <param name="filePath">The full path to the new file</param>
        /// <param name="data">The data to write as a string</param>
        /// <param name="date">The date the data represents</param>
        private void WriteFile(string filePath, string data, DateTime date)
        {
            var tempFilePath = filePath + ".tmp";

            data = data.TrimEnd();
            if (File.Exists(filePath))
            {
                File.Delete(filePath);
                Log.Trace("LeanDataWriter.Write(): Existing deleted: " + filePath);
            }

            // Create the directory if it doesnt exist
            Directory.CreateDirectory(Path.GetDirectoryName(filePath));

            // Write out this data string to a zip file
            Compression.Zip(data, tempFilePath, LeanData.GenerateZipEntryName(_symbol.Value, _securityType, date, _resolution, _dataType));

            // Move temp file to the final destination with the appropriate name
            File.Move(tempFilePath, filePath);

            Log.Trace("LeanDataWriter.Write(): Created: " + filePath);
        }