Example #1
0
        private ExecutarCancelamentoOrdemResponse EnfileirarCancelamento(ExecutarCancelamentoOrdemRequest request)
        {
            ExecutarCancelamentoOrdemResponse response = new ExecutarCancelamentoOrdemResponse();

            string msg = "Cancelamento de Ordem enviado com sucesso";
            StatusRoteamentoEnum status = StatusRoteamentoEnum.Sucesso;

            response.DadosRetorno = RoteadorOrdensUtil.FormatarRespostaCancelamento(msg, status);

            queueCancelamento.Enqueue(request);

            return(response);
        }
        private void cancelarOrdem(OrdemInfo ordem)
        {
            try
            {
                OrdemCancelamentoInfo info = new OrdemCancelamentoInfo();
                info.ClOrdID     = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "-C" + ordem.Symbol + ordem.ChannelID + ordem.Account;
                info.Account     = ordem.Account;
                info.ChannelID   = ordem.ChannelID;
                info.Exchange    = ordem.Exchange;
                info.OrigClOrdID = ordem.ClOrdID;
                info.Symbol      = ordem.Symbol;
                info.SecurityID  = ordem.SecurityID;
                info.Side        = ordem.Side;
                if (!String.IsNullOrEmpty(ordem.ExecBroker))
                {
                    info.ExecBroker = ordem.ExecBroker;
                }
                ExecutarCancelamentoOrdemRequest request = new ExecutarCancelamentoOrdemRequest();

                IRoteadorOrdens roteador = Ativador.Get <IRoteadorOrdens>();
                ExecutarCancelamentoOrdemResponse response = roteador.CancelarOrdem(request);

                if (response.DadosRetorno.StatusResposta != StatusRoteamentoEnum.Sucesso)
                {
                    logger.Error("Erro ao cancelar ordem [" + ordem.ClOrdID + "] alteracao de [" + ordem.ClOrdID + "]");
                    foreach (OcorrenciaRoteamentoOrdem ocorr in response.DadosRetorno.Ocorrencias)
                    {
                        logger.Error("Erro: " + ocorr.Ocorrencia);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("cancelarOrdem(): " + ex.Message, ex);
            }
        }
Example #3
0
 public ExecutarCancelamentoOrdemResponse CancelarOrdem(ExecutarCancelamentoOrdemRequest request)
 {
     throw new NotImplementedException();
 }
Example #4
0
        /// <summary>
        /// Envia um pedido de cancelamento de ordem para o canal correspondente
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public ExecutarCancelamentoOrdemResponse CancelarOrdem(ExecutarCancelamentoOrdemRequest request)
        {
            ExecutarCancelamentoOrdemResponse response = new ExecutarCancelamentoOrdemResponse();
            CanalInfo            _canal = null;
            StatusRoteamentoEnum status = StatusRoteamentoEnum.Sucesso;
            string msg = "Cancelamento Enviado";

            logger.Debug("Request de Cancelamento Recebido:");
            logger.Debug("Cliente ......: " + request.info.Account);
            logger.Debug("Bolsa ........: " + request.info.Exchange);
            logger.Debug("Canal ........: " + request.info.ChannelID);
            logger.Debug("Order ID .....: " + request.info.OrderID);
            logger.Debug("OrigClOrdID ..: " + request.info.OrigClOrdID);
            logger.Debug("ClOrdID ......: " + request.info.ClOrdID);


            try
            {
                _canal = (CanalInfo)_canais[request.info.Exchange + request.info.ChannelID];

                if (!_bKeepRunning)
                {
                    msg    = "Servico esta em finalizacao";
                    status = StatusRoteamentoEnum.Erro;
                    logger.Info(msg);
                    response.DadosRetorno = RoteadorOrdensUtil.FormatarRespostaCancelamento(msg, status);
                    return(response);
                }

                if (_canal == null)
                {
                    msg    = "Nao ha canal configurado para " + request.info.Exchange + "-" + request.info.ChannelID;
                    status = StatusRoteamentoEnum.Erro;
                    logger.Info(msg);
                    response.DadosRetorno = RoteadorOrdensUtil.FormatarRespostaCancelamento(msg, status);
                }
                else
                {
                    if (_canal.roteador == null || _canal.Conectado == false)
                    {
                        status = StatusRoteamentoEnum.Erro;
                        msg    = "Nao ha canal ativo e conectado para " + request.info.Exchange + "-" + request.info.ChannelID;
                        logger.Info(msg);
                        response.DadosRetorno = RoteadorOrdensUtil.FormatarRespostaCancelamento(msg, status);
                    }
                    else
                    {
                        response = EnfileirarCancelamento(request);
                    }
                }
            }
            catch (Exception ex)
            {
                msg    = "CancelarOrdem(): " + ex.Message;
                status = StatusRoteamentoEnum.Erro;
                logger.Error(msg + "-" + ex.StackTrace);
                response.DadosRetorno = RoteadorOrdensUtil.FormatarRespostaCancelamento(msg, status);

                if (_canal != null)
                {
                    _resetCanal(_canal);
                }
            }

            logger.Info(msg);

            logger.Debug("Request de Cancelamento Recebido:");

            return(response);
        }
Example #5
0
        /// <summary>
        /// Cancelamento da ordem
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btCancelar_Click(object sender, EventArgs e)
        {
            try
            {
                OrdemCancelamentoInfo ordem = new OrdemCancelamentoInfo();
                ordem.ClOrdID     = txtClOrdID.Text;
                ordem.OrigClOrdID = txtOrigOrdID.Text;
                ordem.ChannelID   = Convert.ToInt32(txtOperador.Text);
                if (cmbBolsa.SelectedItem.Equals("BOVESPA"))
                {
                    ordem.Exchange = "BOVESPA";
                }
                else
                {
                    ordem.Exchange = "BMF";
                }
                ordem.OrderID    = txtExchangeNumber.Text;
                ordem.Account    = Convert.ToInt32(txtCodCliente.Text);
                ordem.Symbol     = txtPapel.Text;
                ordem.SecurityID = txtSecurityId.Text;
                ordem.ExecBroker = txtTraderID.Text;
                ordem.Memo5149   = "Cancelto " + DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss.fff");

                if (txtSenderLocation.Text.Length > 0)
                {
                    ordem.SenderLocation = txtSenderLocation.Text;
                }

                if (txtExecTrader.Text.Length > 0)
                {
                    ordem.ExecutingTrader = txtExecTrader.Text;
                }

                /*if (!String.IsNullOrEmpty(txtCompIDBolsa.Text))
                 * {
                 *  ordem.CompIDBolsa = txtCompIDBolsa.Text;
                 * }*/


                if (rdCompra.Checked)
                {
                    ordem.Side = OrdemDirecaoEnum.Compra;
                }
                else
                {
                    ordem.Side = OrdemDirecaoEnum.Venda;
                }
                ordem.OrderQty = Convert.ToInt32(txtQtde.Text);

                IRoteadorOrdens roteador = Ativador.Get <IRoteadorOrdens>();

                if (roteador != null)
                {
                    ExecutarCancelamentoOrdemRequest request = new ExecutarCancelamentoOrdemRequest();

                    request.info = ordem;

                    ExecutarCancelamentoOrdemResponse resp = roteador.CancelarOrdem(request);

                    if (resp.DadosRetorno != null)
                    {
                        string msg = "";

                        foreach (OcorrenciaRoteamentoOrdem ocorr in resp.DadosRetorno.Ocorrencias)
                        {
                            msg += ocorr.Ocorrencia + "\r\n";
                        }

                        if (resp.DadosRetorno.StatusResposta == StatusRoteamentoEnum.Erro)
                        {
                            MessageBox.Show(msg);
                        }
                        else
                        {
                            _addMsg(msg);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
                logger.Error("Erro: " + ex.Message, ex);
            }
        }