private void writeATick(double insertPrice, int volume) { if (tsBits[1].Length <= 3) { tickTime = new TimeStamp(tsBits[0] + " " + tsBits[1] + ":00"); } else { tickTime = new TimeStamp(tsBits[0] + " " + tsBits[1]); } utcTime = tickTime; utcTime.AddSeconds(-GetUtcOffset(tickTime)); double price = insertPrice; tickIO.SetTime(utcTime); if (volume >= 1) { tickIO.SetTrade(price, volume); } else { // tickIO.SetQuote(price, price); tickIO.SetTrade(price, volume); } if (tickWriter == null) { tickWriter = Factory.TickUtil.TickWriter(true); tickWriter.KeepFileOpen = true; string folder = "DataCache"; tickWriter.Initialize(folder, symbol.Symbol); } // Console.WriteLine(tickIO); tickWriter.Add(tickIO); countTicksOut++; }
private void FilterFile(string symbol, string inputPath, string outputPath, TimeStamp startTime, TimeStamp endTime) { TickReader reader = Factory.TickUtil.TickReader(); TickWriter writer = Factory.TickUtil.TickWriter(true); writer.KeepFileOpen = true; writer.Initialize(outputPath, symbol); reader.Initialize(inputPath, symbol); TickQueue inputQueue = reader.ReadQueue; TickIO firstTick = Factory.TickUtil.TickIO(); TickIO lastTick = Factory.TickUtil.TickIO(); TickIO prevTick = Factory.TickUtil.TickIO(); long count = 0; long fast = 0; long dups = 0; TickIO tickIO = Factory.TickUtil.TickIO(); TickBinary tickBinary = new TickBinary(); inputQueue.Dequeue(ref tickBinary); tickIO.Inject(tickBinary); count++; firstTick.Copy(tickIO); firstTick.IsSimulateTicks = true; prevTick.Copy(tickIO); prevTick.IsSimulateTicks = true; if (tickIO.Time >= startTime) { writer.Add(firstTick); } try { while (true) { while (!inputQueue.TryDequeue(ref tickBinary)) { Thread.Sleep(1); } tickIO.Inject(tickBinary); count++; if (tickIO.Time >= startTime) { if (tickIO.Time > endTime) { break; } // if( tickIO.Bid == prevTick.Bid && tickIO.Ask == prevTick.Ask) { // dups++; // } else { // Elapsed elapsed = tickIO.Time - prevTick.Time; prevTick.Copy(tickIO); prevTick.IsSimulateTicks = true; // if( elapsed.TotalMilliseconds < 5000) { // fast++; // } else { while (!writer.TryAdd(prevTick)) { Thread.Sleep(1); } // } // } } } } catch (QueueException ex) { if (ex.EntryType != EventType.EndHistorical) { throw new ApplicationException("Unexpected QueueException: " + ex); } } lastTick.Copy(tickIO); Console.WriteLine(reader.Symbol + ": " + count + " ticks from " + firstTick.Time + " to " + lastTick.Time + " " + dups + " duplicates, " + fast + " less than 50 ms"); Factory.TickUtil.TickReader().CloseAll(); writer.Close(); }