コード例 #1
0
        private void geraEvento(string instrumento, string cabecalho, List <LivroOfertasEntry> livroOfertasCompra, List <LivroOfertasEntry> livroOfertasVenda)
        {
            EventoAtualizacaoLivroOfertas mensagemEvento =
                new EventoAtualizacaoLivroOfertas(
                    instrumento,
                    ConstantesMDS.PLATAFORMA_TODAS,
                    cabecalho,
                    livroOfertasCompra,
                    livroOfertasVenda);

            epService.EPRuntime.SendEvent(mensagemEvento);
        }
コード例 #2
0
        public void Run()
        {
            EventoBovespa evento;
            long          antes;
            long          depois;

            logger.Info("Iniciando thread BovespaLivroOfertasConsumer");

            while (_dadosGlobais.KeepRunning)
            {
                evento = null;
                try
                {
                    evento = filaMensagensLivroOfertas.Pop();
                }
                catch (Exception intExcept)
                {
                    logger.Error("InterruptedException na leitura da fila de mensagens do retransmissor:");
                    logger.Debug(intExcept.Message);
                    continue;
                }

                antes = DateTime.Now.Ticks;

                string instrumento = evento.Instrumento;
                string tipo        = evento.Tipo;
                string corpo       = evento.Corpo;

                logger.Debug(evento.MsgID + " " + evento.Cabecalho + " S4 " + instrumento);

                try
                {
                    if (tipo.Equals("S0"))
                    {
                        processReenvio(corpo);
                        logger.Debug(evento.Cabecalho + " S0 " + instrumento);
                    }
                    else
                    {
                        BovespaLivroOfertas livro = null;

                        // S3 e S4 irão manipular o livro correspondente ao instrumento
                        if (todosLivros.ContainsKey(instrumento))
                        {
                            livro = todosLivros[instrumento];
                        }
                        else
                        {
                            logger.Debug("Livro do instrumento " + instrumento + " não existe, criando novo livro");
                            livro = new BovespaLivroOfertas();
                            todosLivros.Add(instrumento, livro);
                        }

                        if (tipo.Equals("S3"))
                        {
                            processAtualizacao(instrumento, livro, corpo);
                        }
                        else if (tipo.Equals("S4"))
                        {
                            processCancelamento(instrumento, livro, corpo);
                        }

                        if (!emReenvio)
                        {
                            // Buffer de montagem da mensagem
                            StringBuilder cabecalho = new StringBuilder();

                            // Cabeçalho
                            cabecalho.Append(ConstantesMDS.TIPO_REQUISICAO_LIVRO);
                            cabecalho.Append(ConstantesMDS.DESCRICAO_DE_BOLSA_BOVESPA);
                            cabecalho.Append(DateTime.Now.ToString("yyyyMMddHHmmssfff"));
                            cabecalho.Append(string.Format("%1$-20s", instrumento));

                            EventoAtualizacaoLivroOfertas atualof =
                                new EventoAtualizacaoLivroOfertas(instrumento,
                                                                  ConstantesMDS.PLATAFORMA_TODAS,
                                                                  cabecalho.ToString(),
                                                                  livro.serializarLivroRobot(BovespaLivroOfertas.LIVRO_COMPRA),
                                                                  livro.serializarLivroRobot(BovespaLivroOfertas.LIVRO_VENDA));


                            // Gera evento de atualização
                            // ATP: implementar ?
                            //o eventoAtualizaLivro =
                            //    new EventoAtualizacaoLivroOfertas(
                            //        instrumento, ConstantesMDS.PLATAFORMA_TODAS,
                            //        cabecalho.toString(),
                            //        livroCompra.toString(),
                            //        livroVenda.toString());

                            //epService.EPRuntime.SendEvent(eventoAtualizaLivro);
                        }

                        if (this._dadosGlobais.Parametros.DebugLOFBovespa &&
                            this._dadosGlobais.Parametros.DebugLOFBovPapel != null &&
                            this._dadosGlobais.Parametros.DebugLOFBovPapel.Equals(instrumento))
                        {
                            string loffile = string.Format("{0}\\{1}.txt",
                                                           _dadosGlobais.Parametros.DiretorioDump,
                                                           _dadosGlobais.Parametros.DebugLOFBovPapel);

                            FileStream   fs     = File.Open(loffile, FileMode.Create, FileAccess.Write);
                            StreamWriter writer = new StreamWriter(fs, Encoding.ASCII);


                            writer.WriteLine("=".PadRight(100, '='));
                            writer.WriteLine(evento.MsgID + "," + evento.Cabecalho + evento.Corpo);
                            List <string> livroCompraSerializado = livro.imprimirLivro(BovespaLivroOfertas.LIVRO_COMPRA);
                            List <string> livroVendaSerializado  = livro.imprimirLivro(BovespaLivroOfertas.LIVRO_VENDA);
                            for (int i = 0; (i < livroCompraSerializado.Count || i < livroVendaSerializado.Count); i++)
                            {
                                string linha = "";
                                if (i < livroCompraSerializado.Count)
                                {
                                    linha += livroCompraSerializado[i];
                                }
                                else
                                {
                                    linha += " ".PadLeft(20);
                                }

                                linha += "|";
                                if (i < livroVendaSerializado.Count)
                                {
                                    linha += livroVendaSerializado[i];
                                }
                                else
                                {
                                    linha += " ".PadLeft(20);
                                }

                                writer.WriteLine(linha);
                            }

                            writer.WriteLine("=".PadRight(100, '='));
                            writer.Close();
                            fs.Close();
                        }
                    }

                    _dadosGlobais.LastMdgIDBov = evento.MsgID;
                }
                catch (Exception e)
                {
                    logger.Error("Exception em BovespaLivroOfertasListener: ", e);
                    logger.Error("Processando a mensagem:");
                    logger.Error(evento.MsgID + "," + evento.Cabecalho + evento.Corpo);
                }

                depois = DateTime.Now.Ticks;
                TimeSpan duracao = new TimeSpan(depois - antes);
                logger.Debug("Duracao do processamento: " + duracao.TotalMilliseconds +
                             " ms (Mensagens na fila: " + filaMensagensLivroOfertas.Count + ")");
            }
        }