protected virtual void Dispose(bool disposing) { if (!isDisposed) { isDisposed = true; if (disposing) { if (debug) { log.Debug("Dispose()"); } if (queueTask != null) { queueTask.Stop(); queueTask.Join(); } if (reader != null) { reader.Dispose(); } if (tickTimer != null) { tickTimer.Dispose(); } if (fillSimulator != null) { if (debug) { log.Debug("Setting fillSimulator.IsOnline false"); } fillSimulator.IsOnline = false; } else { if (debug) { log.Debug("fillSimulator is null."); } } } } else { if (debug) { log.Debug("isDisposed " + isDisposed); } } }
private void Finalize() { if (debug) { log.Debug("Finalize()"); } Flush(); var count = tickFile.WriteCounter; var append = Interlocked.Read(ref appendCounter); if (debug) { log.Debug("Only " + count + " writes before closeFile but " + append + " appends."); } if (tickFile != null) { tickFile.Dispose(); } isFinalized = true; }
protected virtual void Dispose(bool disposing) { if (!isDisposed) { isDisposed = true; lock (taskLocker) { if (fileReaderTask != null) { fileReaderTask.Stop(); fileReaderTask.Join(); } if (tickFile != null) { tickFile.Dispose(); } lock ( readerListLocker) { readerList.Remove(this); } isFinalized = true; } } }
public void ReadFile() { try { TickIO firstTick = Factory.TickUtil.TickIO(); TickIO lastTick = Factory.TickUtil.TickIO(); TickIO prevTick = Factory.TickUtil.TickIO(); long count = 0; long dups = 0; long quotes = 0; long trades = 0; long quotesAndTrades = 0; var tickIO = Factory.TickUtil.TickIO(); try { while (reader.TryReadTick(tickIO)) { if (count == 0) { firstTick.Copy(tickIO); } if (tickIO.IsQuote && tickIO.IsTrade) { quotesAndTrades++; } else if (tickIO.IsQuote) { quotes++; } else { trades++; } if (count > 0) { bool quoteDup = tickIO.IsQuote && prevTick.IsQuote && tickIO.Bid == prevTick.Bid && tickIO.Ask == prevTick.Ask; bool tradeDup = tickIO.IsTrade && prevTick.IsTrade && tickIO.Price == prevTick.Price; if (tickIO.IsQuote && tickIO.IsTrade) { if (quoteDup && tradeDup) { dups++; } } else if (tickIO.IsQuote) { if (quoteDup) { dups++; } } else { if (tradeDup) { dups++; } } } count++; prevTick.Copy(tickIO); } } catch (QueueException) { // Terminated. } lastTick.Copy(tickIO); stringBuilder.AppendLine("Symbol: " + reader.Symbol); stringBuilder.AppendLine("Version: " + reader.DataVersion); stringBuilder.AppendLine("Ticks: " + count); if (quotes > 0) { stringBuilder.AppendLine("Quote Only: " + quotes); } if (trades > 0) { stringBuilder.AppendLine("Trade Only: " + trades); } if (quotesAndTrades > 0) { stringBuilder.AppendLine("Quote and Trade: " + quotesAndTrades); } var time = firstTick.Time.ToString(); var utcTime = firstTick.UtcTime.ToString(); stringBuilder.AppendLine("From: " + time + " (local), " + utcTime + " (UTC)"); time = lastTick.Time.ToString(); utcTime = lastTick.UtcTime.ToString(); stringBuilder.AppendLine(" To: " + time + " (local), " + utcTime + " (UTC)"); if (dups > 0) { stringBuilder.AppendLine("Prices duplicates: " + dups); } } finally { reader.Dispose(); } }
public void TSConverter(SymbolInfo symbolParam) // public void TSConverter(SymbolInfo symbolParam, string from, string to, TimeStamp startTime, TimeStamp endTime, bool fromMinute) { // this.symbol = symbolInfo; symbol = symbolParam; string path = Factory.Settings["AppDataFolder"] + @"\" + dataFolder + @"\"; // *** specify the path to the input file here // SymbolInfo symbol; // take user input symbol string ext = ".txt"; // *** specify input file extension here // double utcOffset = TimeStamp.UtcOffset; String tsLine; // the raw price data line double tickOpen; double tickHigh; double tickLow; double tickClose; int tickVolume; ArrayList ticksOut = new ArrayList(); // int ticksOutCount = 0; // bool fromMinute; char[] delimiterChars = { ',' }; // Do all the work here. // fromMinute = isFromMinute; int countLines = 0; try { using (StreamReader sr = new StreamReader(fromFile)) { tickIO.Initialize(); tickIO.SetSymbol(symbol.BinaryIdentifier); while ((tsLine = sr.ReadLine()) != null) { countLines++; if (countLines > 1) { tsBits = tsLine.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries); if (fromMinute) { tickOpen = double.Parse(tsBits[2]); tickHigh = double.Parse(tsBits[3]); tickLow = double.Parse(tsBits[4]); tickClose = double.Parse(tsBits[5]); tickVolume = int.Parse(tsBits[6]); if (tickOpen == tickHigh && tickOpen == tickLow && tickOpen == tickClose) { writeATick(tickOpen, tickVolume); } else { writeATick(tickOpen, 0); if (tickHigh - tickClose >= tickClose - tickOpen) { writeATick(tickHigh, 0); writeATick(tickLow, 0); writeATick(tickHigh, 0); } else { writeATick(tickLow, 0); writeATick(tickHigh, 0); writeATick(tickLow, 0); } writeATick(tickClose, tickVolume); } } } } } } catch (Exception ex) { throw new ApplicationException("Error on line " + countLines + ": " + ex.Message, ex); } finally { if (tickWriter != null) { tickWriter.Dispose(); } } using (StreamWriter sw = new StreamWriter(path + symbol + "_log" + ext)) { for (int i = 0; i < ticksOut.Count; i++) { sw.WriteLine(ticksOut[i]); } } }