Exemplo n.º 1
0
        public void Run()
        {
            try
            {
                logger.Info("*** Iniciado Retransmissor BMF!");



                // Cria sessao que será usada para mandar as mensagens
                SessionID _session =
                    new SessionID(
                        new BeginString(_config.BeginString),
                        new SenderCompID(_config.SenderCompID),
                        new TargetCompID(_config.TargetCompID));

                // Cria dicionario da configuracao
                Dictionary mainDic = new Dictionary();

                mainDic.setLong("SocketConnectPort", _config.SocketConnectPort);
                mainDic.setLong("HeartBtInt", _config.HeartBtInt);
                mainDic.setLong("ReconnectInterval", _config.ReconnectInterval);

                mainDic.setBool("ResetOnLogon", _config.ResetSeqNum);
                mainDic.setBool("PersistMessages", _config.PersistMessages);

                // Ver
                // ret.setString("ConnectionType", ConnectionType.ToLower());
                mainDic.setString("SocketConnectHost", _config.Host);
                mainDic.setString("FileStorePath", _config.FileStorePath);

                logger.Debug("FileLogPath: " + _config.FileLogPath);

                mainDic.setString("FileLogPath", _config.FileLogPath);
                mainDic.setString("StartTime", _config.StartTime);
                mainDic.setString("EndTime", _config.EndTime);
                mainDic.setString("ConnectionType", "initiator");

                Dictionary sessDic = new Dictionary();

                sessDic.setString("BeginString", _config.BeginString);
                sessDic.setString("SenderCompID", _config.SenderCompID);
                sessDic.setString("TargetCompID", _config.TargetCompID);
                sessDic.setString("DataDictionary", _config.DataDictionary);
                sessDic.setBool("UseDataDictionary", true);

                if (_config.RawData != null && _config.RawData.Length > 0)
                {
                    sessDic.setString(SessaoFIX.FIX_RAWDATA, _config.RawData);
                }

                if (_config.NewPassword != null && _config.NewPassword.Length > 0)
                {
                    sessDic.setString(SessaoFIX.FIX_NEWPASSWORD, _config.NewPassword);
                }

                if (_config.FiltroListaInstrumentos != null && _config.FiltroListaInstrumentos.Length > 0)
                {
                    sessDic.setString(SessaoFIX.FIX_FILTRO_LISTA_INSTRUMENTOS, _config.FiltroListaInstrumentos);
                }

                if (_config.MdReqID != null && _config.MdReqID.Length > 0)
                {
                    sessDic.setString(SessaoFIX.FIX_MDREQID_PADRAO, _config.MdReqID);
                }

                // Configure the session settings
                SessionSettings sessionSettings = new SessionSettings();

                sessionSettings.set(mainDic);
                sessionSettings.set(_session, sessDic);

                //MemoryStoreFactory fileStore = new MemoryStoreFactory();
                FileStoreFactory          fileStore = new FileStoreFactory(sessionSettings);
                FileLogFactory            fileLog   = new FileLogFactory(sessionSettings);
                QuickFix44.MessageFactory message   = new QuickFix44.MessageFactory();


                SessaoFIX sessaoFIX = new SessaoFIX(
                    sessionSettings,
                    dadosGlobais,
                    filaMensagensFIXInstantaneo,
                    filaMensagensFIXIncremental,
                    filaMensagensRetransmissorBMF);

                while (this.dadosGlobais.KeepRunning)
                {
                    Initiator sessao =
                        new ThreadedSocketInitiator(
                            sessaoFIX, fileStore, sessionSettings, fileLog, message);

                    try
                    {
                        logger.Info("Iniciando Sessao FIX...");

                        sessao.start();

                        string mensagem = filaFeeder.Pop();
                        if (mensagem.Contains(ConstantesMDS.TIPOMSG_FIM_CONEXAO))
                        {
                            break;
                        }

                        logger.Info("Finalizando Sessao FIX...");
                        sessao.stop();
                    }

                    catch (Exception ex)
                    {
                        logger.Error("Falha ao enviar mensagem na fila do Retransmissor BMF: " +
                                     ex.Message, ex);
                        continue;
                    }
                }
            }
            catch (ConfigError e)
            {
                logger.Error("Falha durante configuracao do QuickFix:" + e.Message);
                return;
            }
            catch (Exception ex)
            {
                logger.Error("Run(): " + ex.Message, ex);
                return;
            }
        }
Exemplo n.º 2
0
        private static bool Startup_FixConnection(string strKnightSessionSettingsPath)
        {
            bool bReturnValue = false;

            // CONNECT TO KNIGHT
            try
            {
                _mSettings    = new SessionSettings(strKnightSessionSettingsPath); // Settings File
                _mApplication = new GATUtils.Connection.Fix.MlFixApplication(/*this*/);
                //m_application.Set_Reference_to_OrderManager(this);
                _mStoreFactory   = new FileStoreFactory(_mSettings);        // Our Storage Settings
                _mLogFactoryFile = new FileLogFactory(_mSettings);
                _mMessageFactory = new DefaultMessageFactory();             // Our Messaging Settings
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message + "\n" + e.StackTrace);
                return(bReturnValue);
            }

            try
            {
                _gatInitiatorHandle = new ThreadedSocketInitiator(
                    _mApplication,
                    _mStoreFactory,
                    _mSettings,
                    _mLogFactoryFile,
                    _mMessageFactory);
            }
            catch (Exception e)
            {
                Console.WriteLine("Initiator Failed to be Created: " + e.Message + "\n" + e.StackTrace);
                return(bReturnValue);
            }

            if (_gatInitiatorHandle != null)
            {
                // Get Session ID.  This will be used to send Orders.
                ArrayList oList = _gatInitiatorHandle.getSessions();
                if (oList.Count > 0)
                {
                    _oGatSessionId = (QuickFix.SessionID)oList[0];

                    /*/ Get login id.  This is used to make order IDs unique across principle manager application instances.
                     * if (oKnightSessionID.getSenderCompID().Length > 2)
                     *  strUserID = oKnightSessionID.getSenderCompID().Substring(oKnightSessionID.getSenderCompID().Length - 2);
                     * else if (oKnightSessionID.getSenderCompID().Length == 1)
                     *  strUserID = oKnightSessionID.getSenderCompID().PadLeft(2, '0');
                     * // If the SenderCompID is empty, shutdown (should never happen)
                     * else
                     * {
                     *  bReturnValue = false;
                     *  Shutdown_ConnectionToFixSessions();
                     * }
                     *
                     * // Start Execution Feed Listener; this starts its own thread.//*/
                    try
                    {
                        _gatInitiatorHandle.start();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Could not Start Initiator: " + e.Message + "\n" + e.StackTrace);
                        return(bReturnValue);
                    }

                    for (int i = 0; i < 15; ++i)
                    {
                        Console.WriteLine("Checking");
                        if (_mApplication.IsLoggedOn())
                        {
                            bReturnValue = true;
                            break;
                        }
                        Thread.Sleep(1000); // Wait 1 second (1,000 miliseconds) on each loop
                    }
                    if (!_mApplication.IsLoggedOn())
                    {
                        bReturnValue = false;
                        //Shutdown_ConnectionToFixSessions();
                        Console.WriteLine("Could not LogOn");
                    }
                }
                else
                {
                    bReturnValue = false;
                }
                if (bReturnValue == true)
                {
                    Console.WriteLine("Logon Successful");

                    /*/ Clear out any Daily Order Manager info (we do it here in case the Position Manager is left on overnight.  The PMgr should always be reconnected each morning.
                     * if (dtLastRun != null)
                     * {
                     *  if (dtLastRun.Value.Month == DateTime.Now.Month && dtLastRun.Value.Day == DateTime.Now.Day)
                     *  {
                     *  }
                     *  else
                     *  {
                     *      ClearDailyPositionInfoOnNewDay();
                     *  }
                     * } //*/
                    //while (true) { }
                }
            }
            return(bReturnValue);
        }