private void ProcessOnTickCallBack()
 {
     LatencyManager.IncrementSymbolHandler();
     if (quoteMessage == null)
     {
         quoteMessage = quoteSimulatorSupport.QuoteSocket.MessageFactory.Create();
     }
     onTick(id, Symbol, nextTick);
 }
 public Yield Invoke()
 {
     LatencyManager.IncrementSymbolHandler();
     if (tickStatus == TickStatus.None || tickStatus == TickStatus.Sent)
     {
         return(Yield.DidWork.Invoke(DequeueTick));
     }
     else
     {
         return(Yield.NoWork.Repeat);
     }
 }
        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);
        }
        private Yield ProcessTick()
        {
            LatencyManager.IncrementSymbolHandler();
            var result = Yield.NoWork.Repeat;

            switch (tickStatus)
            {
            case TickStatus.None:
                var overlapp    = 300L;
                var currentTime = TimeStamp.UtcNow;
                if (tickTimer.Active)
                {
                    tickTimer.Cancel();
                }
                if (nextTick.UtcTime.Internal > currentTime.Internal + overlapp &&
                    tickTimer.Start(nextTick.UtcTime))
                {
                    if (trace)
                    {
                        log.Trace("Set next timer for " + nextTick.UtcTime + "." + nextTick.UtcTime.Microsecond + " at " + currentTime + "." + currentTime.Microsecond);
                    }
                    tickStatus = TickStatus.Timer;
                }
                else
                {
                    if (nextTick.UtcTime.Internal < currentTime.Internal)
                    {
                        if (trace)
                        {
                            log.Trace("Current time " + currentTime + " was less than tick time " +
                                      nextTick.UtcTime + "." + nextTick.UtcTime.Microsecond);
                        }
                        result = Yield.DidWork.Invoke(SendPlayBackTick);
                    }
                }
                break;

            case TickStatus.Sent:
                result = Yield.DidWork.Invoke(Invoke);
                break;

            case TickStatus.Timer:
                break;

            default:
                throw new ApplicationException("Unknown tick status: " + tickStatus);
            }
            return(result);
        }
 private Yield ProcessOnTickCallBack()
 {
     LatencyManager.IncrementSymbolHandler();
     if (quoteMessage == null)
     {
         quoteMessage = quoteSimulatorSupport.QuoteSocket.MessageFactory.Create();
     }
     onTick(quoteMessage, Symbol, nextTick);
     if (trace)
     {
         log.Trace("Added tick to packet: " + nextTick.UtcTime);
     }
     quoteMessage.SendUtcTime = nextTick.UtcTime.Internal;
     return(Yield.DidWork.Invoke(TryEnqueuePacket));
 }
        public Yield Invoke()
        {
            var result = Yield.NoWork.Repeat;

            LatencyManager.IncrementSymbolHandler();
            if (DequeueTick())
            {
                if (tickCounter > nextMessageCounter)
                {
                    log.Info("Transmitted " + tickCounter + " ticks.");
                    nextMessageCounter += 10000;
                }
                result = Yield.DidWork.Repeat;
            }
            return(result);
        }
 private Yield TryEnqueuePacket()
 {
     LatencyManager.IncrementSymbolHandler();
     if (quoteMessage.Data.GetBuffer().Length == 0)
     {
         return(Yield.NoWork.Return);
     }
     quoteSimulatorSupport.QuotePacketQueue.Enqueue(quoteMessage, quoteMessage.SendUtcTime);
     if (trace)
     {
         log.Trace("Enqueued tick packet: " + new TimeStamp(quoteMessage.SendUtcTime));
     }
     quoteMessage = quoteSimulatorSupport.QuoteSocket.MessageFactory.Create();
     tickStatus   = TickStatus.Sent;
     return(Yield.DidWork.Return);
 }
 private Yield SendPlayBackTick()
 {
     LatencyManager.IncrementSymbolHandler();
     latency.TryUpdate(nextTick.lSymbol, nextTick.UtcTime.Internal);
     if (isFirstTick)
     {
         FillSimulator.StartTick(nextTick);
         isFirstTick = false;
     }
     else
     {
         if (FillSimulator.IsChanged)
         {
             FillSimulator.ProcessOrders();
         }
     }
     return(Yield.DidWork.Invoke(ProcessOnTickCallBack));
 }
        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));
        }
Exemplo n.º 10
0
 public Yield Invoke()
 {
     LatencyManager.IncrementSymbolHandler();
     if (!tickSync.TryLock())
     {
         TryCompleteTick();
         return(Yield.NoWork.Repeat);
     }
     else
     {
         if (trace)
         {
             log.Trace("Locked tickSync for " + Symbol);
         }
     }
     if (!endOfTickData)
     {
         DequeueTick();
         return(Yield.NoWork.Repeat);
     }
     return(Yield.DidWork.Repeat);
 }
Exemplo n.º 11
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();
        }