Re: [Quickfix-users] Create Logon Message
Brought to you by:
orenmnero
From: EclipseCap <tob...@ec...> - 2009-08-04 15:12:31
|
Greetings, I am currently working on something kind of like that. I am using c# if that makes any difference for you. I am going to post the code from my app. It will not compile as it is missing a lot of the classes behind it. But I think if you look at the examples provided and then my code you should be able to piece it together. The trick is to do all of your setup during the construction, but not to start the initiator until you have all of your sessions setup. So once all of the setup is completed you simply execute m_Initiator.start() and it should try to startup any connections you have readied. In the EnableSession function there is a line Enable.logon() and Enable.logout(). You can call those before m_Initiator.start() fires. If you call .logout before it .start() then the logged out connection won't even try. Logon and Logout are kind of bad names really. logon/logout is more like a state. While in logon it will try to connect forever until it succeeds not just try once and return. This code is the constructor code. I wrote it to create a list of sessions based upon rows in a database rather than a setup file. m_Settings = new SessionSettings(); //------------------------------------------------------------------------------------- // Get all of the default values set. Then we build each session. //------------------------------------------------------------------------------------- QuickFix.Dictionary defaultDic = m_Settings.get(); defaultDic.setString("ConnectionType", "initiator"); defaultDic.setString("HeartBtInt", "30"); defaultDic.setString("ReconnectInterval", "1"); defaultDic.setString("FileStorePath", "store"); defaultDic.setString("FileLogPath", "log"); defaultDic.setString("StartTime", "00:00:00"); defaultDic.setString("EndTime", "00:00:00"); defaultDic.setString("UseDataDictionary", "N"); defaultDic.setString("HttpAcceptPort", "8080"); m_Settings.set(defaultDic); foreach(SessionData sessionData in m_Hub.DataManager.Sessions.SessionDataList) { //--------------------------------------------------------------------------------- // Setting this session id will fire off session data callbacks. //--------------------------------------------------------------------------------- sessionData.SessionID = BuildSession(sessionData); } m_Application = new FixApplication(); //---------------------------------------------------------------------------------------- // You can probably skip this as it is all about setting up the callbacks from FIX. //---------------------------------------------------------------------------------------- m_Application.FIXLoginStatusUpdateEvent += new FIXLoginStatusEventHandler(Application_LoginStatusUpdate); m_Application.FIXOrderStatusUpdateEvent += new FIXOrderStatusUpdate(Application_FIXOrderStatusUpdate); m_Application.FIXOrderFillUpdateEvent += new FIXOrderFillUpdate(Application_FIXOrderFillUpdate); m_Application.FIXOrderNewUpdateEvent += new FIXOrderNewUpdate(Application_FIXOrderNewUpdate); m_Application.FIXOrderCancelUpdateEvent += new FIXOrderCancelUpdate(Application_FIXOrderCancelUpdate); m_Application.FIXCancelRejectUpdateEvent += new FIXCancelRejectUpdate(Application_FIXCancelRejectUpdateEvent); //---------------------------------------------------------------------------------------- m_StoreFactory = new FileStoreFactory(m_Settings); m_MessageFactory = new DefaultMessageFactory(); m_Initiator = new SocketInitiator(m_Application, m_StoreFactory, m_Settings, m_MessageFactory); //------------------------------------------------------------------------------------- // Enable/Disable sessions. //------------------------------------------------------------------------------------- foreach (SessionData sessionData in m_Hub.DataManager.Sessions.SessionDataList) { EnableSession(sessionData.SessionID, sessionData.Enabled); } private bool EnableSession(string sessionID, bool sessionEnable) { bool retval = false; SessionID ID = new SessionID(); ID.fromString(sessionID.ToString()); if (Session.doesSessionExist(ID) == true) { retval = true; Session Enable = Session.lookupSession(ID); if (sessionEnable == true) { Enable.logon(); } else { Enable.logout(); } } return retval; } public string BuildSession(SessionData sessionData) { QuickFix.Dictionary defaultDic = m_Settings.get(); //------------------------------------------------------------------------------------- // Iterate through the datamanager and build our list of sessions. //------------------------------------------------------------------------------------- SessionID sID = new SessionID(new BeginString(sessionData.FixVersion), new SenderCompID(sessionData.SenderCompID), new TargetCompID(sessionData.TargetCompID)); //------------------------------------------------------------------------------------- // Add all of our session values as well. //------------------------------------------------------------------------------------- foreach (int TagID in sessionData.SessionConnection.SessionValues.Keys) { SessionValue sessionValue = sessionData.SessionConnection.SessionValues[TagID]; if(sessionValue != null) defaultDic.setString(sessionValue.Tag, sessionValue.Value); } m_Settings.set(sID, defaultDic); return sID.toString(); } Feel free to send me a message if you have questions. I can't say I am expert but at least I'm willing to help. -- View this message in context: http://www.nabble.com/Create-Logon-Message-tp24809985p24810491.html Sent from the QuickFIX - User mailing list archive at Nabble.com. |