コード例 #1
0
ファイル: SessionAcceptor.cs プロジェクト: radtek/Gradual
        private void SendToClient()
        {
            try
            {
                while (_running)
                {
                    try
                    {
                        TOMessage to = null;
#if _CQUEUE
                        if (!_queueMsg.TryDequeue(out to))
                        {
                            lock (_queueMsg)
                                Monitor.Wait(_queueMsg, 50);
                        }
#else
                        lock (_queueMsg)
                        {
                            if (_queueMsg.Count > 0)
                            {
                                to = _queueMsg.Dequeue();
                            }
                            else
                            {
                                Monitor.Wait(_queueMsg, 5);
                                continue;
                            }
                        }
#endif
                        if (null != to)
                        {
                            this._processMessage(to);
                        }
                        to = null;
                    }
                    catch (Exception ex)
                    {
                        logger.Error("erro no envio pro acceptor:" + ex.Message, ex);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("SendToClient() - Erro no envio para client: " + ex.Message, ex);
            }
        }
コード例 #2
0
ファイル: SessionAcceptor.cs プロジェクト: radtek/Gradual
        public void AddMessage(TOMessage to)
        {
            try
            {
#if _CQUEUE
                _queueMsg.Enqueue(to);
                lock (_queueMsg)
                    Monitor.Pulse(_queueMsg);
                //_queueRstEvt.Set();
#else
                lock (_queueMsg)
                {
                    _queueMsg.Enqueue(to);
                    Monitor.Pulse(_queueMsg);
                }
#endif
            }
            catch (Exception ex)
            {
                logger.Error("AddMessage() - Erro na adicao da mensagem da fila: " + ex.Message, ex);
            }
        }
コード例 #3
0
ファイル: SessionAcceptor.cs プロジェクト: radtek/Gradual
        private void _sendDefaultMessageIntegration(QuickFix.Message msgQF, TOMessage to, int account)
        {
            try
            {
                this.Send2DropCopy(msgQF);
                // Validar se deve efetuar o cast da conta para mnemonico
                if (this.Config.ParseAccount)
                {
                    string mnemonic = this.ParentAcceptor.GetMnemonicFromAccount(account);
                    if (!string.IsNullOrEmpty(mnemonic))
                    {
                        msgQF.SetField(new Account(mnemonic), true);
                    }
                }
                Session.SendToTarget(msgQF, to.Sessao);

                msgQF.Clear();
                msgQF = null;
            }
            catch (Exception ex)
            {
                logger.Error("Problemas no envio da mensagem de integracao default: " + ex.Message, ex);
            }
        }
コード例 #4
0
ファイル: SessionAcceptor.cs プロジェクト: radtek/Gradual
        private void _sendMessageBBGIntegration(string msgType, QuickFix.Message msgQF, TOMessage to, int account)
        {
            try
            {
                this.Send2DropCopy(msgQF); // Envio de mensagem 4.4 para a sessao drop copy
                // Validar se deve efetuar o cast da conta para mnemonico
                if (this.Config.ParseAccount)
                {
                    string mnemonic = this.ParentAcceptor.GetMnemonicFromAccount(account);
                    if (!string.IsNullOrEmpty(mnemonic))
                    {
                        msgQF.SetField(new Account(mnemonic), true);
                    }
                }
                QuickFix.Message msgQF42 = null;
                if (msgType == MsgType.EXECUTION_REPORT)
                {
                    msgQF42 = Fix42TranslatorBBG.Fix44ER_2_Fix42ER((QuickFix.FIX44.ExecutionReport)msgQF);
                }
                if (msgType == MsgType.ORDER_CANCEL_REJECT)
                {
                    msgQF42 = Fix42TranslatorBBG.Fix44OCR_2_Fix42OCR((QuickFix.FIX44.OrderCancelReject)msgQF);
                }

                Session.SendToTarget(msgQF42, to.Sessao);

                msgQF.Clear();
                msgQF = null;
                if (null != msgQF42)
                {
                    msgQF42.Clear();
                }
                msgQF42 = null;
            }
            catch (Exception ex)
            {
                logger.Error("Problemas no envio de mensagem de integração BBG: " + ex.Message, ex);
            }
        }
コード例 #5
0
ファイル: SessionAcceptor.cs プロジェクト: radtek/Gradual
        private void _processMessage(TOMessage to)
        {
            try
            {
                if (null != to)
                {
                    QuickFix.Message msgQF   = to.MensagemQF;
                    string           msgType = msgQF.Header.GetField(Tags.MsgType);
                    int    account           = 0;
                    string strAcc            = string.Empty;
                    #region Limit Validation
                    // Atualizacao dos valores de limite, de acordo com o execution report
                    if (this.CalcularLimite)
                    {
                        if (this.Config.Bolsa.Equals(ExchangePrefixes.BOVESPA, StringComparison.InvariantCultureIgnoreCase))
                        {
                            strAcc = msgQF.IsSetField(Tags.Account) ? msgQF.GetField(Tags.Account) : string.Empty;
                            if (!string.IsNullOrEmpty(strAcc))
                            {
                                account = Convert.ToInt32(strAcc.Remove(strAcc.Length - 1));
                            }
                            else
                            {
                                account = 0;
                            }
                        }
                        else
                        {
                            strAcc = msgQF.IsSetField(Tags.Account) ? msgQF.GetField(Tags.Account) : string.Empty;
                            if (!string.IsNullOrEmpty(strAcc))
                            {
                                account = Convert.ToInt32(strAcc);
                            }
                            else
                            {
                                account = 0;
                            }
                        }
                        bool          bProfileInst = false;
                        LimitResponse retProfile   = LimiteManager.LimitControl.GetInstance().VerifyInstitutionalProfile(account);

                        if (0 != retProfile.ErrorCode)
                        {
                            bProfileInst = true;
                        }
                        if (msgType == MsgType.EXECUTION_REPORT && !bProfileInst)
                        {
                            // Validar o perfil instituicional

                            QuickFix.FIX44.ExecutionReport er = (QuickFix.FIX44.ExecutionReport)msgQF;
                            // Bovespa
                            if (this.Config.Bolsa.Equals(ExchangePrefixes.BOVESPA, StringComparison.InvariantCultureIgnoreCase))
                            {
                                // BOVESPA
                                decimal ultimoPreco = StreamerManager.GetInstance().GetLastPrice(er.Symbol.ToString());
                                if (Decimal.Zero != ultimoPreco)
                                {
                                    LimitResponse ret          = new LimitResponse();
                                    decimal       valorAlocado = er.OrderQty.getValue() * ultimoPreco;
                                    // Retirar o digito verificador

                                    string chaveAtual = er.ClOrdID.ToString() + "-" + strAcc + "-" + er.Symbol.ToString();

                                    switch (er.OrdStatus.getValue())
                                    {
                                    // Alocar limite da parte e contra parte
                                    case OrdStatus.NEW:
                                    case OrdStatus.REPLACED:
                                    case OrdStatus.CANCELED:
                                    {
                                        // Buscar o "new order" referencial para busca do TipoLimite
                                        // toOrder = this.Initiator.GetTOOrderSession(chaveAtual);
                                        if (null == to.Order)
                                        {
                                            logger.Info("RefOrder não encontrada (New): " + chaveAtual);
                                        }
                                        else
                                        {
                                            ret = LimiteManager.LimitControl.GetInstance().UpdateOperationalLimitBovespa(account, to.TipoLimite, valorAlocado, ultimoPreco, Convert.ToInt32(er.Side.ToString()), er.OrdStatus.getValue());
                                            if (0 != ret.ErrorCode)
                                            {
                                                logger.Info("Erro na atualizacao do limite operacional Bovespa (New): " + ret.ErrorMessage);
                                            }
                                        }
                                    }
                                    break;

                                    // Atualizar a quantidade executada
                                    case OrdStatus.FILLED:
                                    case OrdStatus.PARTIALLY_FILLED:
                                        if (null != to.Order)
                                        {
                                            to.Order.CumQty = Convert.ToInt32(er.CumQty.getValue());
                                            valorAlocado    = er.CumQty.getValue() * ultimoPreco;
                                            ret             = LimiteManager.LimitControl.GetInstance().UpdateOperationalLimitBovespa(account, to.TipoLimite, valorAlocado, ultimoPreco, Convert.ToInt32(er.Side.ToString()), er.OrdStatus.getValue());
                                            if (0 != ret.ErrorCode)
                                            {
                                                logger.Info("Erro na atualizacao do limite operacional Bovespa (Filled / Partially Filled): " + ret.ErrorMessage);
                                            }
                                        }
                                        else
                                        {
                                            logger.Info("RefOrder não encontrada (New): " + chaveAtual);
                                        }
                                        break;
                                    }
                                }
                                else
                                {
                                    string symbol = er.IsSetSymbol() ? er.Symbol.getValue() : string.Empty;
                                    logger.Info("Preco base (ultimo preco) zerado, ignorando o calculo do limite: " + symbol);
                                }
                            }
                            //bmf
                            else
                            {
                                // BMF
                                // account = er.IsSetField(Tags.Account)?  Convert.ToInt32(er.Account.getValue()): 0;
                                LimitResponse ret  = null;
                                string        side = er.Side.getValue() == '1' ? "C" : "V";
                                switch (er.OrdStatus.getValue())
                                {
                                case OrdStatus.NEW:
                                    ret = LimiteManager.LimitControl.GetInstance()
                                          .UpdateOperationalLimitBMF(Convert.ToInt32(er.Account.getValue()), to.TipoLimite,
                                                                     er.Symbol.getValue(), Convert.ToInt32(er.OrderQty.getValue()), 0, side);
                                    break;

                                case OrdStatus.REPLACED:
                                {
                                    int qtdResult = (-1) * (to.Order.OrderQty - to.Order.CumQty);
                                    ret = LimiteManager.LimitControl.GetInstance()
                                          .UpdateOperationalLimitBMF(Convert.ToInt32(er.Account.getValue()), to.TipoLimite,
                                                                     er.Symbol.getValue(), qtdResult, Convert.ToInt32(er.OrderQty.getValue()), side);
                                }
                                break;

                                case OrdStatus.CANCELED:
                                {
                                    int qtdResult = (-1) * (to.Order.OrderQty - to.Order.CumQty);
                                    ret = LimiteManager.LimitControl.GetInstance()
                                          .UpdateOperationalLimitBMF(Convert.ToInt32(er.Account.getValue()), to.TipoLimite,
                                                                     er.Symbol.getValue(), qtdResult, 0, side);
                                }
                                break;

                                // Atualizando a quantidade de
                                case OrdStatus.FILLED:
                                case OrdStatus.PARTIALLY_FILLED:
                                    if (null != to.Order)
                                    {
                                        to.Order.CumQty = Convert.ToInt32(er.CumQty.getValue());
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    #endregion

                    // Efetuar verificacao da integracao utilizada, para efetuar a conversao do
                    switch (this.Config.IntegrationID)
                    {
                    case IntegrationId.BBG:
                        this._sendMessageBBGIntegration(msgType, msgQF, to, account);
                        break;

                    case IntegrationId.GRD:
                    case IntegrationId.IVF:
                    default:
                        this._sendDefaultMessageIntegration(msgQF, to, account);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("_processMessage(): " + ex.Message, ex);
            }
        }