Example #1
0
        public MonitorarCotacoesResponse MonitorarCotacoes(MonitorarCotacoesRequest request)
        {
            MonitorarCotacoesResponse response = new MonitorarCotacoesResponse();

            try
            {
                PersistenciaDB db = new PersistenciaDB();

                AlgoStruct algo = new AlgoStruct();
                if (!String.IsNullOrEmpty(request.IDAlgoritmo))
                {
                    algo.IDRegistro = request.IDAlgoritmo;
                }

                algo.IDLogin          = request.IDLogin;
                algo.Instrumento1     = request.Instrumento1;
                algo.Instrumento2     = request.Instrumento2;
                algo.Qtde1            = request.Qtde1;
                algo.Qtde2            = request.Qtde2;
                algo.SentidoAlgoritmo = request.SentidoAlgoritmo;
                algo.TipoAlgoritmo    = request.TipoAlgoritmo;

                response.IDRegistro = db.SalvarAlgoritmo(algo);

                ThreadPoolManager.Instance.AddAlgoritmo(algo);
            }
            catch (Exception ex)
            {
                logger.Error("MonitorarCotacoes(): " + ex.Message);
            }

            return(response);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="algo"></param>
        public virtual void RemoveAlgoritmo(AlgoStruct algo)
        {
            lock (dctRegistros)
            {
                if (dctRegistros.ContainsKey(algo.IDRegistro))
                {
                    dctRegistros.Remove(algo.IDRegistro);
                }

                // Sanity check
                if (dctInstrumentos1.ContainsKey(algo.Instrumento1))
                {
                    dctInstrumentos1[algo.Instrumento1].Remove(algo.IDRegistro);

                    if (dctInstrumentos1[algo.Instrumento1].Count == 0)
                    {
                        HashSet <string> algos;
                        dctInstrumentos1.TryRemove(algo.Instrumento1, out algos);
                    }
                }

                // Sanity check
                if (dctInstrumentos2.ContainsKey(algo.Instrumento2))
                {
                    dctInstrumentos2[algo.Instrumento2].Remove(algo.IDRegistro);

                    if (dctInstrumentos2[algo.Instrumento2].Count == 0)
                    {
                        HashSet <string> algos;
                        dctInstrumentos2.TryRemove(algo.Instrumento2, out algos);
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="portasoms"></param>
        /// <param name="contas"></param>
        /// <returns></returns>
        public List <AlgoStruct> CarregarAlgoritmos()
        {
            List <AlgoStruct> lRetorno = new List <AlgoStruct>();

            try
            {
                SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["DirectTradeCadastro"].ConnectionString);

                sqlConn.Open();

                SqlDataAdapter lAdapter;

                DataSet lDataSet = new DataSet();

                SqlCommand gComando = new SqlCommand("prc_buscar_algoritmos", sqlConn);

                gComando.CommandType = System.Data.CommandType.StoredProcedure;

                gLog4Net.Debug("Chamando prc_buscar_algoritmos()");

                lAdapter = new SqlDataAdapter(gComando);

                lAdapter.Fill(lDataSet);

                foreach (DataRow lRow in lDataSet.Tables[0].Rows)
                {
                    AlgoStruct algo = new AlgoStruct();

                    algo.IDLogin          = lRow["IDLogin"].DBToInt32().ToString();
                    algo.IDRegistro       = lRow["IDAlgoritmo"].DBToInt32().ToString();
                    algo.Instrumento1     = lRow["Instrumento1"].DBToString();
                    algo.Instrumento2     = lRow["Instrumento2"].DBToString();
                    algo.Qtde1            = lRow["Quantidade1"].DBToInt32();
                    algo.Qtde2            = lRow["Quantidade2"].DBToInt32();
                    algo.SentidoAlgoritmo = (SentidoAlgoritmoEnum)lRow["SentidoAlgoritmo"].DBToInt32();
                    algo.TipoAlgoritmo    = (AlgoritmoEnum)lRow["TipoAlgorito"].DBToInt32();

                    lRetorno.Add(algo);
                }

                sqlConn.Close();

                sqlConn.Dispose();
            }
            catch (Exception ex)
            {
                gLog4Net.Error("BuscarOrdensSpider():" + ex.Message, ex);
            }

            return(lRetorno);
        }
Example #4
0
        public string SalvarAlgoritmo(AlgoStruct algo)
        {
            string idalgoritmo = "";

            try
            {
                if (!String.IsNullOrEmpty(algo.IDRegistro))
                {
                    idalgoritmo = algo.IDRegistro;
                }

                SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["DirectTradeCadastro"].ConnectionString);

                sqlConn.Open();

                //SqlDataAdapter lAdapter;

                //DataSet lDataSet = new DataSet();

                SqlCommand gComando = new SqlCommand("prc_salvar_algoritmos", sqlConn);

                gComando.CommandType = System.Data.CommandType.StoredProcedure;

                gComando.Parameters.Add(new SqlParameter("@IDAlgoritmo", algo.IDRegistro));
                gComando.Parameters.Add(new SqlParameter("@IDLogin", algo.IDLogin));
                gComando.Parameters.Add(new SqlParameter("@Instrumento1", algo.Instrumento1));
                gComando.Parameters.Add(new SqlParameter("@Instrumento2", algo.Instrumento2));
                gComando.Parameters.Add(new SqlParameter("@Qtde1", algo.Qtde1));
                gComando.Parameters.Add(new SqlParameter("@Qtde2", algo.Qtde2));

                gComando.Parameters.Add(new SqlParameter("@LastCalc", algo.LastCalc));
                gComando.Parameters.Add(new SqlParameter("@SentidoAlgo", algo.SentidoAlgoritmo));
                gComando.Parameters.Add(new SqlParameter("@TipoAlgo", algo.TipoAlgoritmo));

                int id = (Int32)gComando.ExecuteScalar();

                idalgoritmo = id.ToString();

                sqlConn.Close();

                sqlConn.Dispose();
            }
            catch (Exception ex)
            {
                gLog4Net.Error("SalvarAlgoritmo():" + ex.Message, ex);
            }

            return(idalgoritmo);
        }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="algo"></param>
        public virtual void AddAlgoritmo(AlgoStruct algo)
        {
            lock (dctRegistros)
            {
                if (!dctRegistros.ContainsKey(algo.IDRegistro))
                {
                    dctRegistros.Add(algo.IDRegistro, algo);
                }

                // 1a perna
                dctInstrumentos1.GetOrAdd(algo.Instrumento1, new HashSet <string>()).Add(algo.IDRegistro);

                // 2a perna
                dctInstrumentos2.GetOrAdd(algo.Instrumento2, new HashSet <string>()).Add(algo.IDRegistro);
            }
        }
Example #6
0
        public static Dictionary <string, string> montaMensagemStreamerAlgoritmo(int acao, AlgoStruct algo, int casasDecimais)
        {
            Dictionary <string, string> mensagem = new Dictionary <string, string>();


            mensagem.Add(ConstantesMDS.HTTP_ALGORITMOS_ACAO, acao.ToString());

            mensagem.Add(ConstantesMDS.HTTP_ALGORITMOS_IDREGISTRO, algo.IDRegistro);

            mensagem.Add(ConstantesMDS.HTTP_ALGORITMOS_INSTRUMENTO1, algo.Instrumento1.Trim());

            mensagem.Add(ConstantesMDS.HTTP_ALGORITMOS_INSTRUMENTO2, algo.Instrumento2.Trim());

            mensagem.Add(ConstantesMDS.HTTP_ALGORITMOS_VALOR, String.Format("{0:f" + casasDecimais + "}", algo.Value).Replace('.', ','));

            mensagem.Add(ConstantesMDS.HTTP_ALGORITMOS_TIPO_ALGO, algo.TipoAlgoritmo.ToString());

            mensagem.Add(ConstantesMDS.HTTP_ALGORITMOS_SENTIDO_ALGO, algo.SentidoAlgoritmo.ToString());

            mensagem.Add(ConstantesMDS.HTTP_ALGORITMOS_HORA, algo.LastCalc.ToString("yyyyMMddHHmmssfff"));


            return(mensagem);
        }
Example #7
0
        public bool AddAlgoritmo(AlgoStruct algo)
        {
            bool retorno = false;

            try
            {
                ThreadWorkerBase worker = null;
                if (algo.TipoAlgorito == AlgoritmoEnum.DIFERENCIAL)
                {
                    bool bAdded = false;
                    foreach (ThreadWorkerBase runningworker in poolThreadDiferencial)
                    {
                        if (runningworker.HasRoom())
                        {
                            runningworker.AddAlgoritmo(algo);
                            bAdded = true;
                            break;
                        }
                    }

                    if (!bAdded)
                    {
                        worker = new ThreadWorkerDiferencial();
                        worker.Start();
                        worker.AddAlgoritmo(algo);
                        poolThreadDiferencial.Add(worker);
                    }
                }

                if (algo.TipoAlgorito == AlgoritmoEnum.FINANCEIRO)
                {
                    bool bAdded = false;
                    foreach (ThreadWorkerBase runningworker in poolThreadFinanceiro)
                    {
                        if (runningworker.HasRoom())
                        {
                            runningworker.AddAlgoritmo(algo);
                            bAdded = true;
                            break;
                        }
                    }

                    if (!bAdded)
                    {
                        worker = new ThreadWorkerDiferencial();
                        worker.AddAlgoritmo(algo);
                        poolThreadFinanceiro.Add(worker);
                    }
                }

                if (algo.TipoAlgorito == AlgoritmoEnum.SPREAD)
                {
                    bool bAdded = false;
                    foreach (ThreadWorkerBase runningworker in poolThreadSpread)
                    {
                        if (runningworker.HasRoom())
                        {
                            runningworker.AddAlgoritmo(algo);
                            bAdded = true;
                            break;
                        }
                    }

                    if (!bAdded)
                    {
                        worker = new ThreadWorkerDiferencial();
                        worker.AddAlgoritmo(algo);
                        poolThreadSpread.Add(worker);
                    }
                }

                retorno = true;
            }
            catch (Exception ex)
            {
                logger.Error("AddAlgoritmo()" + ex.Message, ex);
            }
            return(retorno);
        }
Example #8
0
 public abstract AlgoStruct DoAlgoritmo(AlgoStruct algo, CotacaoInfo cotacao);