Initiates connections and uses a single thread to process messages for all sessions.
Inheritance: AbstractInitiator
Exemplo n.º 1
0
        static void Main(string[] args)
        {
            //SessionSettings settings = new SessionSettings("config.txt");
            SessionSettings settings = new SessionSettings();

            settings.Set(defaults);
            settings.Set(new SessionID("FIX.4.4", Guid.NewGuid().ToString(), "DERIBITSERVER"), new Dictionary("SESSION", new System.Collections.Generic.Dictionary <string, string>()
            {
                { "BeginString", "FIX.4.4" },
                //  {"SenderCompID",Guid.NewGuid().ToString() },
                //  {"ConnectionType","initiator" }
            }));
            // settings.Set(session);

            DerbitFixClient application = new DerbitFixClient();

            IMessageStoreFactory storeFactory = new FileStoreFactory(settings);
            ILogFactory          logFactory   = new FileLogFactory(settings);

            QuickFix.Transport.SocketInitiator initiator = new QuickFix.Transport.SocketInitiator(application, storeFactory, settings, logFactory);

            // this is a developer-test kludge.  do not emulate.
            application.MyInitiator = initiator;

            initiator.Start();
            //application.QuerySecurityListRequest();
            application.Run();
            initiator.Stop();
        }
Exemplo n.º 2
0
        public void Stop()
        {
            try
            {
                logger.Info("FixInitiator Stop(): Finalizando FixInitiator");
                _running             = false;
                _finalizarSinalizado = true;
                logger.Info("FixInitiator Stop(): Finalizando SocketInitiator");
                if (_socketInitiator != null)
                {
                    _socketInitiator.Stop();
                    _socketInitiator = null;
                }
                logger.Info("FixInitiator Stop(): Finalizando Thread thToDb");

                if (_thToDb.IsAlive)
                {
                    _thToDb.Abort();
                    _thToDb = null;
                }
            }
            catch (Exception ex)
            {
                logger.Error("Erro ao parar o Fix Initiator DropCopy", ex);
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("=============");
            Console.WriteLine("This is for evaluating new QF/n builds and features.");
            Console.WriteLine("It's designed to communicate with PilotAcceptor44.");
            Console.WriteLine("=============");

            if (args.Length != 1)
            {
                System.Console.WriteLine("usage: PilotInitiator44.exe CONFIG_FILENAME");
                System.Environment.Exit(2);
            }

            string file = args[0];

            try
            {
                QuickFix.SessionSettings settings = new QuickFix.SessionSettings(file);
                PilotInit44App myApp = new PilotInit44App();
                QuickFix.IMessageStoreFactory storeFactory = new QuickFix.FileStoreFactory(settings);
                QuickFix.ILogFactory logFactory = new QuickFix.FileLogFactory(settings);
                QuickFix.Transport.SocketInitiator initiator = new QuickFix.Transport.SocketInitiator(myApp, storeFactory, settings, logFactory);

                initiator.Start();
                myApp.Run();
                initiator.Stop();
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }
Exemplo n.º 4
0
 public SocketInitiatorThread(Transport.SocketInitiator initiator, Session session, IPEndPoint socketEndPoint)
 {
     initiator_ = initiator;
     session_ = session;
     socketEndPoint_ = socketEndPoint;
     parser_ = new Parser();
     socket_ = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     session_ = session;
 }
Exemplo n.º 5
0
    private void btn_start_fix_Click(object sender, EventArgs e)
    {
        BTCCFIXClientApp     app          = new BTCCFIXClientApp();
        string               sessionFile  = Environment.CurrentDirectory + @"\session_client.txt";
        SessionSettings      settings     = new SessionSettings(sessionFile);
        IMessageStoreFactory storeFactory = new FileStoreFactory(settings);
        ILogFactory          logFactory   = new FileLogFactory(settings);

        QuickFix.Transport.SocketInitiator initiator = new QuickFix.Transport.SocketInitiator(app, storeFactory, settings, logFactory);
        initiator.Start();

        BTCCMarketDataRequest btccDataRequest = new BTCCMarketDataRequest();

        System.Threading.Thread.Sleep(5000);
        //request full snapshot
        MarketDataRequest dataRequest = btccDataRequest.marketDataFullSnapRequest("BTCCNY");
        bool ret = Session.SendToTarget(dataRequest, app.m_sessionID);

        Console.WriteLine("SendToTarget ret={0}", ret);

        //			dataRequest = btccDataRequest.marketDataFullSnapRequest("LTCCNY");
        //			ret = Session.SendToTarget(dataRequest, app.m_sessionID);
        //			Console.WriteLine("SendToTarget ret={0}", ret);

        //			dataRequest = btccDataRequest.marketDataFullSnapRequest("LTCBTC");
        //			ret = Session.SendToTarget(dataRequest, app.m_sessionID);
        //			Console.WriteLine("SendToTarget ret={0}", ret);

        System.Threading.Thread.Sleep(15000);
        //request incremental request
        dataRequest = btccDataRequest.marketDataIncrementalRequest("BTCCNY");
        ret         = Session.SendToTarget(dataRequest, app.m_sessionID);
        Console.WriteLine("SendToTarget ret={0}", ret);

        //			dataRequest = btccDataRequest.marketDataIncrementalRequest("LTCCNY");
        //			ret = Session.SendToTarget(dataRequest, app.m_sessionID);
        //			Console.WriteLine("SendToTarget ret={0}", ret);

        //			dataRequest = btccDataRequest.marketDataIncrementalRequest("LTCBTC");
        //			ret = Session.SendToTarget(dataRequest, app.m_sessionID);
        //			Console.WriteLine("SendToTarget ret={0}", ret);

        System.Threading.Thread.Sleep(40000);
        //unsubscribe incremental request
        dataRequest = btccDataRequest.unsubscribeIncrementalRequest("BTCCNY");
        ret         = Session.SendToTarget(dataRequest, app.m_sessionID);
        Console.WriteLine("SendToTarget ret={0}", ret);

        //			dataRequest = btccDataRequest.unsubscribeIncrementalRequest("LTCCNY");
        //			ret = Session.SendToTarget(dataRequest, app.m_sessionID);
        //			Console.WriteLine("SendToTarget ret={0}", ret);

        //			dataRequest = btccDataRequest.unsubscribeIncrementalRequest("LTCBTC");
        //			ret = Session.SendToTarget(dataRequest, app.m_sessionID);
        //			Console.WriteLine("SendToTarget ret={0}", ret);
    }
 public SocketInitiatorThread(Transport.SocketInitiator initiator, Session session, IPEndPoint socketEndPoint, SocketSettings socketSettings)
 {
     isDisconnectRequested_ = false;
     initiator_ = initiator;
     session_ = session;
     socketEndPoint_ = socketEndPoint;
     parser_ = new Parser();
     session_ = session;
     socketSettings_ = socketSettings;
 }
Exemplo n.º 7
0
 public SocketInitiatorThread(Transport.SocketInitiator initiator, Session session, IPEndPoint socketEndPoint, SocketSettings socketSettings)
 {
     isDisconnectRequested_ = false;
     initiator_             = initiator;
     session_        = session;
     socketEndPoint_ = socketEndPoint;
     parser_         = new Parser();
     socket_         = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     socket_.NoDelay = socketSettings.SocketNodelay;
     session_        = session;
 }
Exemplo n.º 8
0
 public SocketInitiatorThread(Transport.SocketInitiator initiator, Session session, IPEndPoint socketEndPoint, SocketSettings socketSettings)
 {
     _log.Info("initialising SocketInitiatorThread");
     isDisconnectRequested_ = false;
     initiator_ = initiator;
     session_ = session;
     socketEndPoint_ = socketEndPoint;
     parser_ = new Parser();
     session_ = session;
     socketSettings_ = socketSettings;
 }
Exemplo n.º 9
0
        public void Connect(IApplication application)
        {
            var settings = new SessionSettings("session.config");
            var myApp = application;
            var storeFactory = new FileStoreFactory(settings);
            var logFactory = new FileLogFactory(settings);

            initiator = new SocketInitiator(myApp, storeFactory, settings, logFactory);

            initiator.Start();
        }
Exemplo n.º 10
0
 public SocketInitiatorThread(Transport.SocketInitiator initiator, Session session, IPEndPoint socketEndPoint, SocketSettings socketSettings)
 {
     isDisconnectRequested_ = false;
     initiator_ = initiator;
     session_ = session;
     socketEndPoint_ = socketEndPoint;
     parser_ = new Parser();
     socket_ = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     socket_.NoDelay = socketSettings.SocketNodelay;
     session_ = session;
 }
Exemplo n.º 11
0
 public SocketInitiatorThread(Transport.SocketInitiator initiator, Session session, IPEndPoint socketEndPoint, SocketSettings socketSettings, Encoding encoding)
 {
     isDisconnectRequested_ = false;
     initiator_             = initiator;
     session_         = session;
     socketEndPoint_  = socketEndPoint;
     parser_          = new Parser(encoding);
     session_         = session;
     socketSettings_  = socketSettings;
     _messageEncoding = encoding;
 }
 public SocketInitiatorThread(Transport.SocketInitiator initiator, Session session, IPEndPoint socketEndPoint, SocketSettings socketSettings)
 {
     isDisconnectRequested_ = false;
     initiator_ = initiator;
     session_ = session;
     socketEndPoint_ = socketEndPoint;
     parser_ = new Parser();
     if (socketEndPoint.AddressFamily == AddressFamily.InterNetwork)
         socket_ = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     else
     {
         socket_ = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
         socket_.SetSocketOption(SocketOptionLevel.IPv6, (SocketOptionName)23, 10);
     }
     socket_.NoDelay = socketSettings.SocketNodelay;
     session_ = session;
 }
Exemplo n.º 13
0
        public FixInitiatorDropCopy(FixSessionItem config)
        {
            _config              = config;
            _bConectadoBolsa     = false;
            _socketInitiator     = null;
            _finalizarSinalizado = false;
            _intCanal            = _config.Operador;
            _running             = false;

#if _CQUEUE
            _queueToDB = new ConcurrentQueue <TODropCopyDB>();
#else
            _queueToDB = new Queue <TODropCopyDB>();
#endif
            //_db = new DbDropCopy();

            _rulesMsg = new MessageProcessor();
        }
Exemplo n.º 14
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // FIX app settings and related
            var settings = new SessionSettings("C:\\initiator.cfg");

            // FIX application setup
            MessageStoreFactory storeFactory = new FileStoreFactory(settings);
            LogFactory logFactory = new FileLogFactory(settings);
            _client = new FixClient50Sp2(settings);

            IInitiator initiator = new SocketInitiator(_client, storeFactory, settings, logFactory);
            _client.Initiator = initiator;

            _client.OnProgress += _client_OnProgress;
            _client.LogonEvent += ClientLogonEvent;
            _client.MessageEvent += ClientMessageEvent;
            _client.LogoutEvent += ClientLogoutEvent;
            _client.OnMarketDataIncrementalRefresh += Client_OnMarketDataIncrementalRefresh;
        }
Exemplo n.º 15
0
        public void Start()
        {
            try
            {
                logger.Info("FixInitiatorDropCopy Start(): Iniciando FixInitiatorDropCopy....");
                _running = true;


                // Buscar Application Path para compor diretorios de dicionario e afins(Substring(6) para retirar 'file:\')
                string path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(FixInitiatorDropCopy)).CodeBase).Substring(6);
                //logger.Info("Application Path: " + path);

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

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

                mainDic.SetLong("SocketConnectPort", _config.SocketPort);
                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("ConnectionType", _config.ConnectionType.ToLower());
                mainDic.SetString("SocketConnectHost", _config.Host);
                mainDic.SetString("FileStorePath", path + Path.DirectorySeparatorChar + _config.FileStorePath);

                //string  = path + Path.DirectorySeparatorChar + info.DataDictionary;

                logger.Debug("FileLogPath: " + path + Path.DirectorySeparatorChar + _config.FileLogPath);
                mainDic.SetString("FileLogPath", path + Path.DirectorySeparatorChar + _config.FileLogPath);
                mainDic.SetString("DebugFileLogPath", path + Path.DirectorySeparatorChar + _config.DebugFileLogPath);
                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", path + Path.DirectorySeparatorChar + _config.DataDictionary);
                sessDic.SetBool("UseDataDictionary", _config.UseDataDictionary);

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

                settings.Set(mainDic);
                settings.Set(_session, sessDic);

                //FileStoreFactory store = new FileStoreFactory(settings);
                MemoryStoreFactory store = new MemoryStoreFactory();
                FileLogFactory     logs  = new FileLogFactory(settings);
                IMessageFactory    msgs  = new DefaultMessageFactory();
                logger.InfoFormat("Iniciando ThreadedSocketInitiator...  SenderCompID: [{0}] TargetCompID: [{1}] SocketConnectHost:[{2}] SocketConnectPort:[{3}]",
                                  _config.SenderCompID, _config.TargetCompID, _config.Host, _config.SocketPort);
                _socketInitiator = new SocketInitiator(this, store, settings, logs, msgs);
                _socketInitiator.Start();

                // Thread para receber as mensagens de acceptors
                _thToDb = new Thread(new ThreadStart(this._sendtoDb));
                _thToDb.Start();

                logger.Info("FixInitiatorDropCopy Start(): Fim de inicializacao FixInitiator....");
            }

            catch (Exception ex)
            {
                logger.Error("Erro ao inicializar Fix Initiator DropCopy", ex);
                throw ex;
            }
        }
Exemplo n.º 16
0
 public SocketInitiatorThread(Transport.SocketInitiator initiator, Session session, IPEndPoint socketEndPoint, SocketSettings socketSettings)
     : this(initiator, session, socketEndPoint, socketSettings, Encoding.UTF8)
 {
 }
Exemplo n.º 17
0
    private void btn_start_fix_Click(object sender, EventArgs e)
    {
        BTCCFIXClientApp app = new BTCCFIXClientApp();
        string sessionFile = Environment.CurrentDirectory + @"\session_client.txt";
        SessionSettings settings = new SessionSettings(sessionFile);
        IMessageStoreFactory storeFactory = new FileStoreFactory(settings);
        ILogFactory logFactory = new FileLogFactory(settings);
        QuickFix.Transport.SocketInitiator initiator = new QuickFix.Transport.SocketInitiator(app, storeFactory, settings, logFactory);
        initiator.Start();

        BTCCMarketDataRequest btccDataRequest = new BTCCMarketDataRequest();

        System.Threading.Thread.Sleep(5000);
        //request full snapshot
        MarketDataRequest dataRequest = btccDataRequest.marketDataFullSnapRequest("BTCCNY");
        bool ret = Session.SendToTarget(dataRequest, app.m_sessionID);
        Console.WriteLine("SendToTarget ret={0}", ret);

        //			dataRequest = btccDataRequest.marketDataFullSnapRequest("LTCCNY");
        //			ret = Session.SendToTarget(dataRequest, app.m_sessionID);
        //			Console.WriteLine("SendToTarget ret={0}", ret);

        //			dataRequest = btccDataRequest.marketDataFullSnapRequest("LTCBTC");
        //			ret = Session.SendToTarget(dataRequest, app.m_sessionID);
        //			Console.WriteLine("SendToTarget ret={0}", ret);

        System.Threading.Thread.Sleep(15000);
        //request incremental request
        dataRequest = btccDataRequest.marketDataIncrementalRequest("BTCCNY");
        ret = Session.SendToTarget(dataRequest, app.m_sessionID);
        Console.WriteLine("SendToTarget ret={0}", ret);

        //			dataRequest = btccDataRequest.marketDataIncrementalRequest("LTCCNY");
        //			ret = Session.SendToTarget(dataRequest, app.m_sessionID);
        //			Console.WriteLine("SendToTarget ret={0}", ret);

        //			dataRequest = btccDataRequest.marketDataIncrementalRequest("LTCBTC");
        //			ret = Session.SendToTarget(dataRequest, app.m_sessionID);
        //			Console.WriteLine("SendToTarget ret={0}", ret);

        System.Threading.Thread.Sleep(40000);
        //unsubscribe incremental request
        dataRequest = btccDataRequest.unsubscribeIncrementalRequest("BTCCNY");
        ret = Session.SendToTarget(dataRequest, app.m_sessionID);
        Console.WriteLine("SendToTarget ret={0}", ret);

        //			dataRequest = btccDataRequest.unsubscribeIncrementalRequest("LTCCNY");
        //			ret = Session.SendToTarget(dataRequest, app.m_sessionID);
        //			Console.WriteLine("SendToTarget ret={0}", ret);

        //			dataRequest = btccDataRequest.unsubscribeIncrementalRequest("LTCBTC");
        //			ret = Session.SendToTarget(dataRequest, app.m_sessionID);
        //			Console.WriteLine("SendToTarget ret={0}", ret);
    }
Exemplo n.º 18
0
        public void TearDown()
        {
            if (_listenSocket != null)
                _listenSocket.Close();
            if (_initiator != null)
                _initiator.Stop(true);
            if (_acceptor != null)
                _acceptor.Stop(true);

            _initiator = null;
            _acceptor = null;
        }
Exemplo n.º 19
0
        void StartEngine(bool initiator)
        {
            TestApplication application = new TestApplication(LogonCallback, LogoffCallback);
            IMessageStoreFactory storeFactory = new MemoryStoreFactory();
            ILogFactory logFactory = new ScreenLogFactory(false, false, false);
            SessionSettings settings = new SessionSettings();

            if (initiator)
            {
                Dictionary defaults = new Dictionary();
                defaults.SetString(SessionSettings.RECONNECT_INTERVAL, "1");
                settings.Set(defaults);
                settings.Set(CreateSessionID(StaticInitiatorCompID), CreateSessionConfig(StaticInitiatorCompID, true));
                _initiator = new SocketInitiator(application, storeFactory, settings, logFactory);
                _initiator.Start();
            }
            else
            {
                settings.Set(CreateSessionID(StaticAcceptorCompID), CreateSessionConfig(StaticAcceptorCompID, false));
                _acceptor = new ThreadedSocketAcceptor(application, storeFactory, settings, logFactory);
                _acceptor.Start();
            }
        }
Exemplo n.º 20
0
        void StartEngine(bool initiator)
        {
            TestApplication application = new TestApplication(LogonCallback, LogoffCallback);
            IMessageStoreFactory storeFactory = new MemoryStoreFactory();
            SessionSettings settings = new SessionSettings();
            Dictionary defaults = new Dictionary();
            defaults.SetString(QuickFix.SessionSettings.FILE_LOG_PATH, LogPath);

            // Put IP endpoint settings into default section to verify that that defaults get merged into
            // session-specific settings not only for static sessions, but also for dynamic ones
            defaults.SetString(SessionSettings.SOCKET_CONNECT_HOST, Host);
            defaults.SetString(SessionSettings.SOCKET_CONNECT_PORT, ConnectPort.ToString());
            defaults.SetString(SessionSettings.SOCKET_ACCEPT_HOST, Host);
            defaults.SetString(SessionSettings.SOCKET_ACCEPT_PORT, AcceptPort.ToString());

            settings.Set(defaults);
            ILogFactory logFactory = new FileLogFactory(settings);

            if (initiator)
            {
                defaults.SetString(SessionSettings.RECONNECT_INTERVAL, "1");
                settings.Set(CreateSessionID(StaticInitiatorCompID), CreateSessionConfig(StaticInitiatorCompID, true));
                _initiator = new SocketInitiator(application, storeFactory, settings, logFactory);
                _initiator.Start();
            }
            else
            {
                settings.Set(CreateSessionID(StaticAcceptorCompID), CreateSessionConfig(StaticAcceptorCompID, false));
                _acceptor = new ThreadedSocketAcceptor(application, storeFactory, settings, logFactory);
                _acceptor.Start();
            }
        }
Exemplo n.º 21
0
        public void TearDown()
        {
            if (_listenSocket != null)
                _listenSocket.Close();
            if (_initiator != null)
                _initiator.Stop(true);
            if (_acceptor != null)
                _acceptor.Stop(true);

            _initiator = null;
            _acceptor = null;

            Thread.Sleep(500);
            ClearLogs();
        }