コード例 #1
0
        protected virtual void processaMensagemFIX(EventoFIX evento)
        {
            // Se nao existe thread para tratar o evento, cria
            FIXMessageWorkerState workerState = null;

            if (evento == null)
            {
                logger.Error("Mensagem FIX nao pode ser nula");
                return;
            }

            if (String.IsNullOrEmpty(evento.ChannelID))
            {
                logger.Error("Eita porra....channelID nulo");
                return;
            }

            if (!poolFixWorkers.TryGetValue(evento.ChannelID, out workerState))
            {
                logger.Info("Criando worker para  channel [" + evento.ChannelID + "]");
                workerState             = new FIXMessageWorkerState();
                workerState.ChannelID   = evento.ChannelID;
                workerState.Thread      = new Thread(new ParameterizedThreadStart(messageFixThreadWork));
                workerState.Thread.Name = myThreadName + "-Worker-" + workerState.ChannelID;
                workerState.Thread.Start(workerState);

                poolFixWorkers.Add(evento.ChannelID, workerState);
            }

            bool bsinaliza = workerState.QueueMensagens.IsEmpty;

            workerState.QueueMensagens.Enqueue(evento);
            if (MDSUtils.shouldLog(workerState.lastEnqueueLog, 30))
            {
                logger.Info("processaMensagemFIX para channelID [" + workerState.ChannelID + "] fila:" + workerState.QueueMensagens.Count);
                workerState.lastEnqueueLog = DateTime.UtcNow.Ticks;
            }

            //if (bsinaliza)
            //{
            //    lock (workerState.SyncObjFIX)
            //    {
            //        Monitor.Pulse(workerState.SyncObjFIX);
            //    }
            //}
        }
コード例 #2
0
        public virtual void EnqueueFIX(EventoFIX e)
        {
            try
            {
                bool sinaliza = queueFIX.IsEmpty;
                queueFIX.Enqueue(e);

                if (sinaliza)
                {
                    lock (SyncObjFix)
                    {
                        Monitor.Pulse(SyncObjFix);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("EnqueueFIX(): " + ex.Message, ex);
            }
        }
コード例 #3
0
 public void EnqueueFIX(EventoFIX e)
 {
     LivroOfertasConsumer.EnqueueFIX(e);
     NegociosConsumer.EnqueueFIX(e);
 }
コード例 #4
0
ファイル: ChannelTcpConflated.cs プロジェクト: radtek/Gradual
        private void queueProc()
        {
            logger.Info("Iniciando thread de processamento da fila de mensagens FIX");
            long lastLog = 0;

            while (_bKeepRunning)
            {
                try
                {
                    QuickFix.FIX44.Message message = null;

                    if (queueToProcess.TryDequeue(out message))
                    {
                        if (logger.IsDebugEnabled)
                        {
                            logger.Debug("Processing Message [" + message.Header.GetInt(34) + "] type [" + message.Header.GetString(35) + "]");
                        }

                        string channelID;
                        string msgtype = message.Header.GetString(QuickFix.Fields.Tags.MsgType);
                        switch (msgtype)
                        {
                        case QuickFix.FIX44.MarketDataIncrementalRefresh.MsgType:
                            if (message.GroupCount(QuickFix.Fields.Tags.NoMDEntries) > 0)
                            {
                                QuickFix.Group MDEntry    = message.GetGroup(1, QuickFix.Fields.Tags.NoMDEntries);
                                string         securityID = MDEntry.GetString(QuickFix.Fields.Tags.SecurityID);
                                channelID = dctChannel.GetOrAdd(securityID, FIX_DEFAULT_WORKER);
                            }
                            else
                            {
                                channelID = FIX_DEFAULT_WORKER;
                            }
                            break;

                        case QuickFix.FIX44.MarketDataSnapshotFullRefresh.MsgType:
                            if (message.IsSetField(QuickFix.Fields.Tags.SecurityID))
                            {
                                string securityID = message.GetString(QuickFix.Fields.Tags.SecurityID);
                                channelID = dctChannel.GetOrAdd(securityID, FIX_DEFAULT_WORKER);
                            }
                            else
                            {
                                channelID = FIX_DEFAULT_WORKER;
                            }
                            break;

                        case QuickFix.FIX44.SecurityList.MsgType:
                            if (message.GroupCount(QuickFix.Fields.Tags.NoRelatedSym) > 0)
                            {
                                QuickFix.Group MDEntry      = message.GetGroup(1, QuickFix.Fields.Tags.NoRelatedSym);
                                string         securityID   = MDEntry.GetString(QuickFix.Fields.Tags.SecurityID);
                                string         securityType = MDEntry.GetString(QuickFix.Fields.Tags.SecurityType);
                                channelID = dctChannel.GetOrAdd(securityID, securityType);
                            }
                            else
                            {
                                channelID = FIX_DEFAULT_WORKER;
                            }
                            break;

                        case QuickFix.FIX44.SecurityStatus.MsgType:
                            if (message.IsSetField(QuickFix.Fields.Tags.SecurityID))
                            {
                                string securityID = message.GetString(QuickFix.Fields.Tags.SecurityID);
                                channelID = dctChannel.GetOrAdd(securityID, FIX_DEFAULT_WORKER);
                            }
                            else
                            {
                                channelID = FIX_DEFAULT_WORKER;
                            }
                            break;

                        default:
                            channelID = FIX_DEFAULT_WORKER;
                            break;
                        }

                        EventoFIX eventoFIX = new EventoFIX();
                        eventoFIX.ChannelID   = channelID;
                        eventoFIX.MarketDepth = ConstantesUMDF.UMDF_MARKETDEPTH_MARKET_BY_ORDER;
                        eventoFIX.Message     = message;
                        eventoFIX.MsgSeqNum   = message.Header.GetInt(QuickFix.Fields.Tags.MsgSeqNum);
                        eventoFIX.MsgType     = msgtype;
                        eventoFIX.StreamType  = StreamTypeEnum.STREAM_TYPE_TCP_CONFLATED;


                        ContainerManager.Instance.EnqueueFIX(eventoFIX);

                        if (MDSUtils.shouldLog(lastLog))
                        {
                            logger.Info("Mensagens FIX para processar na fila: " + queueToProcess.Count);
                            lastLog = DateTime.UtcNow.Ticks;
                        }

                        continue;
                    }

                    Thread.Sleep(25);
                }
                catch (Exception ex)
                {
                    logger.Error("queueProc: " + ex.Message, ex);
                }
            }

            logger.Info("Thread de fila de mensagens FIX finalizada");
        }
コード例 #5
0
ファイル: ChannelTcpConflated.cs プロジェクト: radtek/Gradual
        public virtual void OnMessage(QuickFix.FIX44.SecurityList message, SessionID session)
        {
            try
            {
                EventoFIX evento = new EventoFIX();

                if (message.IsSetField(QuickFix.Fields.Tags.SecurityRequestResult) &&
                    message.IsSetField(QuickFix.Fields.Tags.SecurityReqID))
                {
                    string requestResult = message.GetString(QuickFix.Fields.Tags.SecurityRequestResult);

                    if (!requestResult.Equals("0"))
                    {
                        logger.WarnFormat("Request [{0}] nao pode ser atendido result=[{1}]",
                                          message.GetString(QuickFix.Fields.Tags.SecurityReqID),
                                          message.GetString(QuickFix.Fields.Tags.SecurityRequestResult));
                    }
                }

                if (message.IsSetSecurityReqID())
                {
                    int noRelatedSym = message.GroupCount(QuickFix.Fields.Tags.NoRelatedSym);

                    for (int i = 1; i <= noRelatedSym; i++)
                    {
                        QuickFix.Group relatedSyms = message.GetGroup(i, QuickFix.Fields.Tags.NoRelatedSym);

                        string securityID   = relatedSyms.GetString(QuickFix.Fields.Tags.SecurityID);
                        string securityType = relatedSyms.GetString(QuickFix.Fields.Tags.SecurityType);

                        dctChannel.AddOrUpdate(securityID, securityType, (key, oldValue) => securityType);
                    }
                }

                logger.Debug("OnMessage(QuickFix.FIX44.SecurityList) Enqueue to split [" + message.Header.GetInt(QuickFix.Fields.Tags.MsgSeqNum) + "]");
                enqueueToSplit(message);
                logger.Debug("OnMessage(QuickFix.FIX44.SecurityList) Enqueud [" + message.Header.GetInt(QuickFix.Fields.Tags.MsgSeqNum) + "]");

                // Requisita a proxima lista de papeis
                if (message.IsSetLastFragment() && message.LastFragment.ToString().ToUpper().Equals("Y"))
                {
                    if (message.IsSetSecurityReqID())
                    {
                        logger.Info("Final da security list ID [" + message.SecurityReqID.ToString() + "]");

                        logger.Info("Solicitando snapshots");
                        ThreadPool.QueueUserWorkItem(new WaitCallback(RequestMarketData), session);

                        if (_secListMarketRequested < _channelUmdfConfig.Markets.Count)
                        {
                            ThreadPool.QueueUserWorkItem(new WaitCallback(RequestSecurityList), session);
                        }
                        else
                        {
                            logger.Info("Final das requisicoes de securitylist");
                            //logger.Info("Solicitando snapshots");
                            //ThreadPool.QueueUserWorkItem(new WaitCallback(RequestMarketData), session);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("onMessage(SecurityList): " + ex.Message, ex);
            }
        }
コード例 #6
0
 protected override void trataMensagemFIX(EventoFIX evento)
 {
 }
コード例 #7
0
 protected abstract void trataMensagemFIX(EventoFIX evento);