Пример #1
0
        public static void ListaRanking(Queue <DadosFilaResumoCorretoras> fila, Socket socketClient)
        {
            ResumoCorretorasInfo resumoCorretoras = null;

            logger.Info("Montando nova lista de resumo de corretoras e enviando para fila");

            try
            {
                foreach (string segmentoMercado in SEGMENTOS_MERCADO)
                {
                    lock (dictInstrumentos)
                    {
                        lock (dictMaioresVolumesPorCorretora)
                        {
                            resumoCorretoras              = new ResumoCorretorasInfo();
                            resumoCorretoras.instrumento  = segmentoMercado;
                            resumoCorretoras.cabecalho    = new CabecalhoInfo();
                            resumoCorretoras.cabecalho.tp = resumoCorretoras.instrumento;
                            resumoCorretoras.cabecalho.d  = DateTime.Now.ToString("yyyyMMdd");
                            resumoCorretoras.cabecalho.h  = DateTime.Now.ToString("HHmmssSSS");
                            resumoCorretoras.resumo       = new List <CorretoraInfo>();

                            foreach (KeyValuePair <CorretorasInfo, string> info in dictMaioresVolumes[segmentoMercado])
                            {
                                double porcentagemCompra = (info.Key.VolumeCompra / dictMaioresVolumesPorCorretora[segmentoMercado][TODAS_CORRETORAS].VolumeCompra) * 100;
                                double porcentagemVenda  = (info.Key.VolumeVenda / dictMaioresVolumesPorCorretora[segmentoMercado][TODAS_CORRETORAS].VolumeVenda) * 100;

                                CorretoraInfo corretora = new CorretoraInfo();
                                corretora.r  = (resumoCorretoras.resumo.Count + 1).ToString();
                                corretora.c  = info.Value;
                                corretora.vc = info.Key.VolumeCompra.ToString("F0").Replace('.', ',');
                                corretora.pc = porcentagemCompra.ToString("F2").Replace('.', ',');
                                corretora.vv = info.Key.VolumeVenda.ToString("F0").Replace('.', ',');
                                corretora.pv = porcentagemVenda.ToString("F2").Replace('.', ',');
                                corretora.vb = info.Key.VolumeBruto.ToString("F0").Replace('.', ',');
                                corretora.vl = info.Key.VolumeLiquido.ToString("F0").Replace('.', ',');
                                resumoCorretoras.resumo.Add(corretora);

                                logger.Debug(String.Format("Segmento[{0,-2}] ({1,3}) {2,-9} {3,15} {4,8}% {5,15} {6,8}% {7,15} {8,15}",
                                                           segmentoMercado, resumoCorretoras.resumo.Count + 1, info.Value,
                                                           info.Key.VolumeCompra.ToString("N2"), porcentagemCompra.ToString("N2"),
                                                           info.Key.VolumeVenda.ToString("N2"), porcentagemVenda.ToString("N2"),
                                                           info.Key.VolumeBruto.ToString("N2"), info.Key.VolumeLiquido.ToString("N2")));
                            }
                            DadosFilaResumoCorretoras dadosFilaResumoCorretoras = new DadosFilaResumoCorretoras();
                            dadosFilaResumoCorretoras.socketClient         = socketClient;
                            dadosFilaResumoCorretoras.resumoCorretorasInfo = resumoCorretoras;
                            fila.Enqueue(dadosFilaResumoCorretoras);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Fatal("ListaRanking(): " + ex.Message, ex);
            }
        }
Пример #2
0
        public static void ListaRankingPorInstrumentoOuCorretora(Queue <DadosFilaResumoCorretoras> fila, Socket socketClient, string instrumento)
        {
            int tipoPesquisa = PESQUISA_POR_INSTRUMENTO;

            if (instrumento != null)
            {
                if (!instrumento.StartsWith(PREFIXO_CORRETORA))
                {
                    tipoPesquisa = PESQUISA_POR_INSTRUMENTO;
                }
                else
                {
                    tipoPesquisa = PESQUISA_POR_CORRETORA;
                }
            }

            ResumoCorretorasInfo resumoCorretoras = null;

            try
            {
                if (instrumento == null || tipoPesquisa == PESQUISA_POR_INSTRUMENTO)
                {
                    lock (dictInstrumentosAssinados)
                    {
                        foreach (KeyValuePair <string, int> assinatura in dictInstrumentosAssinados)
                        {
                            lock (dictInstrumentos)
                            {
                                if (instrumento == null || assinatura.Key.Equals(instrumento))
                                {
                                    resumoCorretoras              = new ResumoCorretorasInfo();
                                    resumoCorretoras.instrumento  = assinatura.Key;
                                    resumoCorretoras.cabecalho    = new CabecalhoInfo();
                                    resumoCorretoras.cabecalho.tp = assinatura.Key;
                                    resumoCorretoras.cabecalho.d  = DateTime.Now.ToString("yyyyMMdd");
                                    resumoCorretoras.cabecalho.h  = DateTime.Now.ToString("HHmmssSSS");
                                    resumoCorretoras.resumo       = new List <CorretoraInfo>();

                                    foreach (KeyValuePair <CorretorasInfo, string> info in dictInstrumentos[assinatura.Key].DictMaioresVolumes)
                                    {
                                        double porcentagemCompra = (info.Key.VolumeCompra / dictInstrumentos[assinatura.Key].DictMaioresVolumesPorCorretora[TODAS_CORRETORAS].VolumeCompra) * 100;
                                        double porcentagemVenda  = (info.Key.VolumeVenda / dictInstrumentos[assinatura.Key].DictMaioresVolumesPorCorretora[TODAS_CORRETORAS].VolumeVenda) * 100;

                                        CorretoraInfo corretora = new CorretoraInfo();
                                        corretora.r  = (resumoCorretoras.resumo.Count + 1).ToString();
                                        corretora.c  = info.Value;
                                        corretora.vc = info.Key.VolumeCompra.ToString("F0").Replace('.', ',');
                                        corretora.pc = porcentagemCompra.ToString("F2").Replace('.', ',');
                                        corretora.vv = info.Key.VolumeVenda.ToString("F0").Replace('.', ',');
                                        corretora.pv = porcentagemVenda.ToString("F2").Replace('.', ',');
                                        corretora.vb = info.Key.VolumeBruto.ToString("F0").Replace('.', ',');
                                        corretora.vl = info.Key.VolumeLiquido.ToString("F0").Replace('.', ',');
                                        resumoCorretoras.resumo.Add(corretora);

                                        logger.Debug(String.Format("Instrumento[{0,-14}] ({1,3}) {2,-9} {3,15} {4,8}% {5,15} {6,8}% {7,15} {8,15}",
                                                                   assinatura.Key, resumoCorretoras.resumo.Count + 1, info.Value,
                                                                   info.Key.VolumeCompra.ToString("N2"), porcentagemCompra.ToString("N2"),
                                                                   info.Key.VolumeVenda.ToString("N2"), porcentagemVenda.ToString("N2"),
                                                                   info.Key.VolumeBruto.ToString("N2"), info.Key.VolumeLiquido.ToString("N2")));
                                    }
                                    DadosFilaResumoCorretoras dadosFilaResumoCorretoras = new DadosFilaResumoCorretoras();
                                    dadosFilaResumoCorretoras.socketClient         = socketClient;
                                    dadosFilaResumoCorretoras.resumoCorretorasInfo = resumoCorretoras;
                                    fila.Enqueue(dadosFilaResumoCorretoras);
                                }
                            }
                        }
                    }
                }

                if (instrumento == null || tipoPesquisa == PESQUISA_POR_CORRETORA)
                {
                    string corretora = null;
                    if (instrumento != null)
                    {
                        corretora = Int32.Parse(instrumento.Substring(1)).ToString("D8");
                    }

                    lock (dictCorretorasAssinadas)
                    {
                        foreach (KeyValuePair <string, int> assinatura in dictCorretorasAssinadas)
                        {
                            lock (dictCorretoras)
                            {
                                if (instrumento == null || assinatura.Key.Equals(corretora))
                                {
                                    resumoCorretoras              = new ResumoCorretorasInfo();
                                    resumoCorretoras.instrumento  = PREFIXO_CORRETORA + Int32.Parse(assinatura.Key).ToString();
                                    resumoCorretoras.cabecalho    = new CabecalhoInfo();
                                    resumoCorretoras.cabecalho.tp = PREFIXO_CORRETORA + Int32.Parse(assinatura.Key).ToString();
                                    resumoCorretoras.cabecalho.d  = DateTime.Now.ToString("yyyyMMdd");
                                    resumoCorretoras.cabecalho.h  = DateTime.Now.ToString("HHmmssSSS");
                                    resumoCorretoras.resumo       = new List <CorretoraInfo>();

                                    if (dictCorretoras.ContainsKey(assinatura.Key))
                                    {
                                        foreach (KeyValuePair <CorretorasInfo, string> info in dictCorretoras[assinatura.Key].DictMaioresVolumes)
                                        {
                                            double volumeCompraCorretora = dictCorretoras[assinatura.Key].DictMaioresVolumesPorInstrumento[TODOS_INSTRUMENTOS].VolumeCompra;
                                            double volumeVendaCorretora  = dictCorretoras[assinatura.Key].DictMaioresVolumesPorInstrumento[TODOS_INSTRUMENTOS].VolumeVenda;
                                            double porcentagemCompra     = (volumeCompraCorretora == 0 ? 0 : (info.Key.VolumeCompra / volumeCompraCorretora) * 100);
                                            double porcentagemVenda      = (volumeVendaCorretora == 0 ? 0 : (info.Key.VolumeVenda / volumeVendaCorretora) * 100);

                                            CorretoraInfo intrumentoDados = new CorretoraInfo();
                                            intrumentoDados.r  = (resumoCorretoras.resumo.Count + 1).ToString();
                                            intrumentoDados.c  = info.Value;
                                            intrumentoDados.vc = info.Key.VolumeCompra.ToString("F0").Replace('.', ',');
                                            intrumentoDados.pc = porcentagemCompra.ToString("F2").Replace('.', ',');
                                            intrumentoDados.vv = info.Key.VolumeVenda.ToString("F0").Replace('.', ',');
                                            intrumentoDados.pv = porcentagemVenda.ToString("F2").Replace('.', ',');
                                            intrumentoDados.vb = info.Key.VolumeBruto.ToString("F0").Replace('.', ',');
                                            intrumentoDados.vl = info.Key.VolumeLiquido.ToString("F0").Replace('.', ',');
                                            resumoCorretoras.resumo.Add(intrumentoDados);

                                            logger.Debug(String.Format("Corretora[{0,-9}] ({1,3}) {2,-20} {3,15} {4,8}% {5,15} {6,8}% {7,15} {8,15}",
                                                                       assinatura.Key, resumoCorretoras.resumo.Count + 1, info.Value,
                                                                       info.Key.VolumeCompra.ToString("N2"), porcentagemCompra.ToString("N2"),
                                                                       info.Key.VolumeVenda.ToString("N2"), porcentagemVenda.ToString("N2"),
                                                                       info.Key.VolumeBruto.ToString("N2"), info.Key.VolumeLiquido.ToString("N2")));
                                        }
                                    }
                                    DadosFilaResumoCorretoras dadosFilaResumoCorretoras = new DadosFilaResumoCorretoras();
                                    dadosFilaResumoCorretoras.socketClient         = socketClient;
                                    dadosFilaResumoCorretoras.resumoCorretorasInfo = resumoCorretoras;
                                    fila.Enqueue(dadosFilaResumoCorretoras);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Fatal("ListaRankingPorInstrumento(): " + ex.Message, ex);
            }
        }