示例#1
0
        public void TZConverter(string file, string symbol)
        {
            TickReader reader = Factory.TickUtil.TickReader();

            reader.Initialize(file, symbol);
            TickQueue queue = reader.ReadQueue;

            TickBinary tickBinary = new TickBinary();

            if (!TryGetNextTick(queue, ref tickBinary))
            {
            }
        }
示例#2
0
 public SymbolQueue(SymbolInfo symbol, Provider provider, TimeStamp startTime)
 {
     this.symbol    = symbol;
     this.provider  = provider;
     this.tickQueue = Factory.TickUtil.TickQueue(typeof(SymbolQueue));
     this.tickQueue.StartEnqueue = Start;
     this.startTime  = startTime;
     NextTick        = new TickBinary();
     NextTick.Symbol = symbol.BinaryIdentifier;
     if (captureEvents)
     {
         receiverId = Factory.Provider.EventLog.GetReceiverId(this);
     }
     provider.SendEvent(this, null, (int)EventType.Connect, null);
 }
示例#3
0
        private bool TryGetNextTick(TickQueue queue, ref TickBinary binary)
        {
            bool result = false;

            do
            {
                try {
                    result = queue.TryDequeue(ref binary);
                } catch (QueueException ex) {
                    // Ignore any other events.
                    if (ex.EntryType == EventType.EndHistorical)
                    {
                        throw;
                    }
                }
            } while(!result);
            return(result);
        }
        public TickWriterDefault(bool eraseFileToStart)
        {
            this.eraseFileToStart   = eraseFileToStart;
            writeQueue              = Factory.TickUtil.TickQueue(typeof(TickWriter));
            writeQueue.StartEnqueue = Start;
            var property = "PriceDataFolder";

            priceDataFolder = Factory.Settings[property];
            if (priceDataFolder == null)
            {
                throw new ApplicationException("Must set " + property + " property in app.config");
            }
            property      = "AppDataFolder";
            appDataFolder = Factory.Settings[property];
            if (appDataFolder == null)
            {
                throw new ApplicationException("Must set " + property + " property in app.config");
            }
        }
示例#5
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();
        }
示例#6
0
 public DataReceiverQueueWrapper(SymbolInfo symbol, Pool <TickBinaryBox> pool, TickQueue queue)
 {
     this.symbol = symbol;
     tickPool    = pool;
     tickQueue   = queue;
 }
示例#7
0
 public void Setup()
 {
     queue = Factory.Parallel.TickQueue(typeof(TickQueueTest));
 }
示例#8
0
 public void Setup()
 {
     queue = Factory.TickUtil.TickQueue(typeof(TickQueueTest));
 }
示例#9
0
        public void ReadFile()
        {
            TickQueue  queue           = reader.ReadQueue;
            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;
            TickIO     tickIO          = Factory.TickUtil.TickIO();
            TickBinary tickBinary      = new TickBinary();

            try {
                while (true)
                {
                    if (!TryGetNextTick(queue, ref tickBinary))
                    {
                        break;
                    }
                    tickIO.Inject(tickBinary);
                    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);
            }
            stringBuilder.AppendLine("From: " + firstTick.Time + "." + firstTick.Time.Microsecond);
            stringBuilder.AppendLine("To: " + lastTick.Time + "." + lastTick.Time.Microsecond);
            if (dups > 0)
            {
                stringBuilder.AppendLine("Prices duplicates: " + dups);
            }
            Factory.TickUtil.TickReader().CloseAll();
        }