Exemple #1
0
        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();
        }
Exemple #2
0
        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"] + @"\DataCache\";           // *** 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.Close();
                }
            }

            using (StreamWriter sw = new StreamWriter(path + symbol + "_log" + ext)) {
                for (int i = 0; i < ticksOut.Count; i++)
                {
                    sw.WriteLine(ticksOut[i]);
                }
            }
        }