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);
     }
 }
        /// <summary>
        /// Создать <see cref="ManagedMessageAdapter"/>.
        /// </summary>
        /// <param name="innerAdapter">Адаптер, в который будут перенаправляться сообщения.</param>
        public ManagedMessageAdapter(IMessageAdapter innerAdapter)
        {
            if (innerAdapter == null)
            {
                throw new ArgumentNullException("innerAdapter");
            }

            _innerAdapter = innerAdapter;
            _innerAdapter.NewOutMessage += ProcessOutMessage;

            CommissionManager = new CommissionManager();
            LatencyManager    = new LatencyManager();
            RiskManager       = new RiskManager();
        }
        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 void ProcessExecution(Message message)
        {
            if (message.Type != MessageTypes.Execution)
            {
                return;
            }

            var execMsg = (ExecutionMessage)message;

            var latency = LatencyManager.ProcessMessage(execMsg);

            if (latency != null)
            {
                execMsg.Latency = latency;
            }

            if (execMsg.Commission == null)
            {
                execMsg.Commission = CommissionManager.ProcessExecution(execMsg);
            }
        }
        void IMessageChannel.SendInMessage(Message message)
        {
            if (message.LocalTime.IsDefault())
            {
                message.LocalTime = _innerAdapter.CurrentTime.LocalDateTime;
            }

            if (message.Type == MessageTypes.Connect)
            {
                LatencyManager.Reset();
                CommissionManager.Reset();
                RiskManager.Reset();
            }
            else
            {
                LatencyManager.ProcessMessage(message);
                ProcessRisk(message);
            }

            _innerAdapter.SendInMessage(message);
        }
        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));
        }
Beispiel #13
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);
 }
Beispiel #14
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();
        }
        private void ExecutePathSearch(Location startLocation, Location targetLocation)
        {
            m_paths.Clear();

            CheckExistence(startLocation);
            CheckExistence(targetLocation);

            if (KeepPathsIndependet)
            {
                LatencyMan = new LatencyManager(KeepPathsIndependet);
            }
            else
            {
                LatencyMan = new LatencyManager(PrintLatency, SortByAttribute);
            }

            // print results
            if (PrintBanner && !OutputMode.ToUpper().Equals("TCL"))
            {
                OutputManager.WriteOutput(GetBannerWithLatency(startLocation, targetLocation));
            }

            RouteNet routeCmd = new RouteNet();

            routeCmd.Watch = Watch;

            foreach (List <Location> path in routeCmd.Route(SearchMode, Forward, Enumerable.Repeat(startLocation, 1), targetLocation, 1000, MaxDepth, KeepPathsIndependet))
            {
                if (!PathAlreadyFound(path, m_paths))
                {
                    m_paths.Add(path);

                    if (BlockUsedPorts)
                    {
                        foreach (Location l in path)
                        {
                            if (!l.Tile.IsPortBlocked(l.Pip))
                            {
                                l.Tile.BlockPort(l.Pip, Tile.BlockReason.Blocked);
                            }
                        }
                    }

                    ProgressInfo.Progress = ProgressStart + (int)(m_paths.Count / (double)MaxSolutions * ProgressShare);

                    if (m_paths.Count >= MaxSolutions)
                    {
                        break;
                    }
                }
            }

            if (m_paths.Count == 0)
            {
                OutputManager.WriteOutput("No path found");
            }
            else if (OutputMode.ToUpper().Equals("CHAIN"))
            {
                PrintAsChain(m_paths);
            }
            else if (OutputMode.ToUpper().Equals("XDL"))
            {
                OutputManager.WriteOutput(PathToString(startLocation, targetLocation, m_paths));
            }
            else if (OutputMode.ToUpper().Equals("TCL"))
            {
                AddToTCLOutput(m_paths);
            }
        }