Example #1
0
        public void ReadFile()
        {
            TickIO tickIO = Factory.TickUtil.TickIO();

            try
            {
                while (reader.TryReadTick(tickIO))
                {
                    if (tickIO.UtcTime > endTime)
                    {
                        break;
                    }
                    if (tickIO.UtcTime > startTime)
                    {
                        Output(tickIO.ToString());
                    }
                }
            }
            catch (QueueException ex)
            {
                if (ex.EntryType != EventType.EndHistorical)
                {
                    throw;
                }
            }
        }
        private Yield DequeueTick()
        {
            LatencyManager.IncrementSymbolHandler();
            var result = Yield.NoWork.Repeat;

            if (isFirstTick)
            {
                if (!reader.TryReadTick(currentTick))
                {
                    return(result);
                }
            }
            else
            {
                currentTick.Inject(nextTick.Extract());
                if (!reader.TryReadTick(nextTick))
                {
                    return(result);
                }
            }
            tickCounter++;
            if (isFirstTick)
            {
                playbackOffset = fixSimulatorSupport.GetRealTimeOffset(currentTick.UtcTime.Internal);
                prevTickTime   = TimeStamp.UtcNow.Internal + 5000000;
            }
            currentTick.SetTime(new TimeStamp(GetNextUtcTime(currentTick.lUtcTime)));
            prevTickTime = currentTick.UtcTime.Internal;
            if (tickCounter > 10)
            {
                intervalTime = 1000;
            }
            isFirstTick = false;
            FillSimulator.StartTick(currentTick);
            if (trace)
            {
                log.Trace("Dequeue tick " + nextTick.UtcTime + "." + nextTick.UtcTime.Microsecond);
            }
            return(Yield.DidWork.Invoke(ProcessTick));
        }
        private bool DequeueTick()
        {
            LatencyManager.IncrementSymbolHandler();
            var result = false;

            if (tickPool.AllocatedCount >= tickPool.Capacity / 2)
            {
                return(false);
            }
            while (!quoteSimulatorSupport.QuotePacketQueue.IsFull)
            {
                if (!reader.TryReadTick(temporaryTick))
                {
                    if (onEndTick != null)
                    {
                        onEndTick(id);
                    }
                    else
                    {
                        throw new ApplicationException("OnEndTick was null");
                    }
                    queueTask.Stop();
                    return(result);
                }
                tickCounter++;
                if (isFirstTick)
                {
                    currentTick.Inject(temporaryTick.Extract());
                }
                else
                {
                    currentTick.Inject(nextTick.Extract());
                }
                isFirstTick = false;
                FillSimulator.StartTick(currentTick);
                nextTick.Inject(temporaryTick.Extract());
                if (FillSimulator.IsChanged)
                {
                    FillSimulator.ProcessOrders();
                }
                if (trace)
                {
                    log.Trace("Dequeue tick " + nextTick.UtcTime + "." + nextTick.UtcTime.Microsecond);
                }
                ProcessOnTickCallBack();
                result = true;
            }
            return(result);
        }
Example #4
0
        private void DequeueTick()
        {
            LatencyManager.IncrementSymbolHandler();

            if (!reader.TryReadTick(temporaryTick))
            {
                if (onEndTick == null)
                {
                    throw new ApplicationException("OnEndTick was null");
                }
                onEndTick(id);
                endOfTickData = true;
                queueTask.Resume();
                if (debug)
                {
                    log.Debug("End Of Tick Data.");
                }
                return;
            }
            tickCounter++;
            if (isFirstTick)
            {
                currentTick.Inject(temporaryTick.Extract());
            }
            else
            {
                currentTick.Inject(nextTick.Extract());
            }
            isFirstTick = false;
            FillSimulator.StartTick(currentTick);
            nextTick.Inject(temporaryTick.Extract());
            tickSync.AddTick(nextTick);
            if (trace)
            {
                log.Trace("Dequeue tick " + nextTick.UtcTime + "." + nextTick.UtcTime.Microsecond);
            }
            ProcessOnTickCallBack();
        }
Example #5
0
 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();
     }
 }
Example #6
0
        public virtual Yield Invoke()
        {
            EventItem eventItem;

            if (fileReaderTask.Filter.Receive(out eventItem))
            {
                switch (eventItem.EventType)
                {
                default:
                    throw new ApplicationException("Unexpected event: " + eventItem);
                }
            }
            if (!isStarted)
            {
                return(Yield.NoWork.Repeat);
            }
            lock (taskLocker)
            {
                if (isDisposed)
                {
                    return(Yield.Terminate);
                }
                try
                {
                    var loopCount = 0;
                    while (!CancelPending && loopCount < 1000 && tickBoxPool.AllocatedCount < tickBoxPool.Capacity)
                    {
                        ++loopCount;
                        if (!tickFile.TryReadTick(tickIO))
                        {
                            if (debug)
                            {
                                log.Debug("Finished reading to file length: " + tickFile.Length);
                            }
                            return(SendFinish());
                        }

                        tick       = tickIO.Extract();
                        isDataRead = true;

                        if (Factory.TickCount > nextUpdate)
                        {
                            try {
                                progressCallback("Loading bytes...", tickFile.Position, tickFile.Length);
                            } catch (Exception ex) {
                                log.Debug("Exception on progressCallback: " + ex.Message);
                            }
                            nextUpdate = Factory.TickCount + 2000;
                        }

                        if (MaxCount > 0 && Count > MaxCount)
                        {
                            if (debug)
                            {
                                log.Debug("Ending data read because count reached " + MaxCount + " ticks.");
                            }
                            return(SendFinish());
                        }

                        if (IsAtEnd(tick))
                        {
                            return(SendFinish());
                        }

                        if (IsAtStart(tick))
                        {
                            count = Count + 1;
                            if (debug && Count < 10)
                            {
                                log.Debug("Read a tick " + tickIO);
                            }
                            else if (trace)
                            {
                                log.Trace("Read a tick " + tickIO);
                            }
                            tick.Symbol = tickFile.Symbol.BinaryIdentifier;

                            if (tick.UtcTime <= lastTime)
                            {
                                tick.UtcTime = lastTime + 1;
                            }
                            lastTime = tick.UtcTime;

                            if (isFirstTick)
                            {
                                isFirstTick = false;
                                StartEvent();
                            }
                            else
                            {
                                tickCount++;
                            }

                            box = tickBoxPool.Create(tickPoolCallerId);
                            if (debug)
                            {
                                log.Debug("Allocated box id in reader " + box.Id + ", count " + tickBoxPool.AllocatedCount);
                            }
                            var tickId = box.TickBinary.Id;
                            box.TickBinary    = tick;
                            box.TickBinary.Id = tickId;

                            TickEvent();
                        }
                        tickCount++;
                    }
                }
                catch (ObjectDisposedException)
                {
                    return(SendFinish());
                }
                return(Yield.DidWork.Repeat);
            }
        }