21 using System.Diagnostics;
23 using System.Collections.Generic;
24 using ZipFile = Ionic.Zip.ZipFile;
43 var timer =
new Stopwatch();
45 var folderPath =
new DirectoryInfo(sourceDirectory);
46 if (!folderPath.Exists)
48 throw new ArgumentException($
"Source folder {folderPath.FullName} not found");
51 exchange = !
string.IsNullOrEmpty(exchange) && exchange.ToLowerInvariant() ==
"gdax" ?
"coinbase" : exchange;
54 foreach (var filePath
in folderPath.EnumerateFiles(
"*.zip"))
57 if (!
string.IsNullOrEmpty(exchange) && !filePath.Name.ToLowerInvariant().Contains(exchange.ToLowerInvariant()))
continue;
59 Log.
Trace($
"KaikoDataConverter(): Starting data conversion from source {filePath.Name} for date {processingDate:yyyy_MM_dd}... ");
60 using (var zip =
new ZipFile(filePath.FullName))
62 var targetDayEntries = zip.Entries.Where(e => e.FileName.Contains($
"{processingDate.ToStringInvariant("yyyy_MM_dd
")}")).ToList();
64 if (!targetDayEntries.Any())
66 Log.
Error($
"KaikoDataConverter(): Date {processingDate:yyyy_MM_dd} not found in source file {filePath.FullName}.");
69 foreach (var zipEntry
in targetDayEntries)
71 var nameParts = zipEntry.FileName.Split(
new char[] {
'/' }).Last().Split(
new char[] {
'_' });
72 var market = nameParts[0] ==
"Coinbase" ?
"GDAX" : nameParts[0];
73 var ticker = nameParts[1];
77 Log.
Trace($
"KaikoDataConverter(): Processing {symbol.Value} {tickType}");
82 var ticks = reader.GetTicksFromZipEntry(zipEntry);
89 Log.
Trace($
"KaikoDataConverter(): Starting consolidation for {symbol.Value} {tickType}");
90 List<TickAggregator> consolidators =
new List<TickAggregator>();
94 consolidators.AddRange(
new[]
102 consolidators.AddRange(
new[]
109 foreach (var tick
in ticks)
111 foreach (var consolidator
in consolidators)
113 consolidator.Update(tick);
117 foreach (var consolidator
in consolidators)
120 writer.Write(consolidator.Flush());
125 Log.
Error($
"KaikoDataConverter(): Error processing entry {zipEntry.FileName}. Exception {e}");
130 Log.
Trace($
"KaikoDataConverter(): Finished in {timer.Elapsed}");