/// <summary> /// The Init method is invoked to initialize an instance of /// the session class with the services, setttings, and handler /// that it requires in order to be activated. All instances of /// a session must be initialized before they can start managing /// a FIX session for their owner. /// </summary> /// <param name="services"> /// The service container that contains the references to all of /// the system services that an instance of the session needs. /// </param> /// <param name="handler"> /// The callback interface that the session directs all of its /// events to as they occur. /// </param> public void Init(IVfxServices services, IVfxFixSessionHandler handler) { // REC: Retrieve the version registry that the session // has been configured to use: IVfxFixVxRegistry vxRegistry = services.GetService(typeof(IVfxFixVxRegistry)) as IVfxFixVxRegistry; // REC: Retrieve the dictionary registry that the session // has been configured to use: IVfxFixDxRegistry dxRegistry = services.GetService(typeof(IVfxFixDxRegistry)) as IVfxFixDxRegistry; // REC: Retrieve the session database service from the // set of services provided by the session's owner: _fixDatabase = services.GetService(typeof(IVfxFixDatabase)) as IVfxFixDatabase; // REC: Retrieve the session configuration from the // service container for relevant settings: IVfxSettings settings = services.GetService(typeof(IVfxSettings)) as IVfxSettings; // REC: Temporary container to simplify accessing the // session settings from the XML configuration document: Dictionary <string, string> mapSettings = new Dictionary <string, string>(); XPathNavigator xpn = settings.Document.CreateNavigator(); XPathNodeIterator xpi; xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.Sx.Version']"); if ((xpi.Count > 0) && (xpi.MoveNext())) { this._sxVersion = xpi.Current.GetAttribute("content", "").Trim(); } xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.Ax.Version']"); if ((xpi.Count > 0) && (xpi.MoveNext())) { this._axVersion = xpi.Current.GetAttribute("content", "").Trim(); } // REC: Retrieve application layer details: VfxFixVxRecord axDetails = vxRegistry.Get(_axVersion); // REC: Adjust the session layer, if one has not been // specified for the connection. if (string.IsNullOrEmpty(this._sxVersion)) { if (axDetails.Layer.ToLower().CompareTo("combined") == 0) { this._sxVersion = this._axVersion; } } // REC: Retrieve the session layer details: VfxFixVxRecord sxDetails = vxRegistry.Get(_sxVersion); // REC: Construct a local instance of a version definition // registry so that the session relies only on the specific // versions that have been specified for the service: VfxFixVxRegistry localVxRegistry = new VfxFixVxRegistry(); // REC: Add the session layer to the local registry: localVxRegistry.Add(this._sxVersion, sxDetails); // REC: Add the application layer to the local registry: localVxRegistry.Add(this._axVersion, axDetails); // REC: Construct a new instance of the service container // and populate it with the services for the session: IVfxServices localServices = new VfxServices(); // REC: The session can use the global dictionaries: localServices.AddService(typeof(IVfxFixDxRegistry), dxRegistry); // REC: The session can use its own version registry: localServices.AddService(typeof(IVfxFixVxRegistry), localVxRegistry); // REC: Initialize the parser with the local services: _fixParser.Init(localServices); // REC: Configure the FIX session timer to fire every // second for conducting timeout checks, etc. _fixTimer.Interval = 1000; // REC: Subscribe to the timer in order to determine if // the session has timed out: this._fixTimer.Elapsed += HandleElapsed_Timer; // REC: Initialize the FIX message assembler: _fixAssembler.Init(localServices); // REC: Register required fields for messages: this._fixBeginString = sxDetails.FixBs; _fixAssembler.SetField(new FixField(8, this._fixBeginString)); _fixAssembler.SetField(new FixField(9, "")); _fixAssembler.SetField(new FixField(98, "0")); _fixAssembler.SetField(new FixField(108, "60")); xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.Heartbeat']"); if ((xpi.Count > 0) && (xpi.MoveNext())) { string fixTimeout = xpi.Current.GetAttribute("content", "").Trim(); // REC: The client sessions need to maintain their own // reference to the heartbeat value: this._fixTimeout = int.Parse(fixTimeout); // REC: Assign the timeout value to the assembler so it // becomes the default for any message that needs it: _fixAssembler.SetField(new FixField(108, fixTimeout)); } xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.SenderCompID']"); if ((xpi.Count > 0) && (xpi.MoveNext())) { // REC: The client sessions need to maintain an independent // reference to the SenderCompID for identification: this._fixSenderCompID = xpi.Current.GetAttribute("content", ""); // REC: Add the field to the assembler so that it gets put // into each outgoing message: _fixAssembler.SetField(new FixField(49, this._fixSenderCompID)); } xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.TargetCompID']"); if ((xpi.Count > 0) && (xpi.MoveNext())) { // REC: The client sessions need to maintain an independent // reference to the TargetCompID for identification: this._fixTargetCompID = xpi.Current.GetAttribute("content", ""); // REC: Add the field to the assembler so that it gets put // into each outgoing message: _fixAssembler.SetField(new FixField(56, this._fixTargetCompID)); } _fixAssembler.SetField(new FixField(10, "")); // REC: The client session knows the FIX TargetCompID of the // peer system in advance, unlike the server sessions, so we // can construct the session id in the initialization code: _sessionId = string.Format("{0}-{1}", _fixSenderCompID, _fixTargetCompID); // REC: Maintain a reference to the supplied callback // handler for issuing event notifications: _handler = handler; }
void IVfxFixSession.Init(IVfxServices services, IVfxFixSessionHandler handler) { // REC: Maintain a reference to the set of configuration settings // that are supplied to the session instance: _localServices = services; // REC: Retrieve the version registry that the session // has been configured to use: IVfxFixVxRegistry vxRegistry = services.GetService(typeof(IVfxFixVxRegistry)) as IVfxFixVxRegistry; // REC: Retrieve the dictionary registry that the session // has been configured to use: IVfxFixDxRegistry dxRegistry = services.GetService(typeof(IVfxFixDxRegistry)) as IVfxFixDxRegistry; // REC: Retrieve the session database service from the // set of services provided by the session's owner: _fixDatabase = services.GetService(typeof(IVfxFixDatabase)) as IVfxFixDatabase; // REC: Retrieve the configuration settings and extract // the FIX session and application layer versions: IVfxSettings settings = this._localServices.GetService(typeof(IVfxSettings)) as IVfxSettings; XPathNavigator xpn = settings.Document.CreateNavigator(); XPathNodeIterator xpi; xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.Sx.Version']"); if ((xpi.Count > 0) && (xpi.MoveNext())) { this._sxVersion = xpi.Current.GetAttribute("content", "").Trim(); } xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.Ax.Version']"); if ((xpi.Count > 0) && (xpi.MoveNext())) { this._axVersion = xpi.Current.GetAttribute("content", "").Trim(); } // REC: Retrieve application layer details: VfxFixVxRecord axDetails = vxRegistry.Get(_axVersion); // REC: Adjust the session layer, if it was not specified // and the application layer is FIX 4.0-4.4: if (string.IsNullOrEmpty(this._sxVersion)) { if (axDetails.Layer.ToLower().CompareTo("combined") == 0) { this._sxVersion = this._axVersion; } } // REC: Retrieve the session layer details: VfxFixVxRecord sxDetails = vxRegistry.Get(_sxVersion); // REC: Construct a local instance of a version definition // registry so that the session relies only on the specific // versions that have been specified for the service: VfxFixVxRegistry localVxRegistry = new VfxFixVxRegistry(); // REC: Add the session layer to the local registry: localVxRegistry.Add(this._sxVersion, sxDetails); // REC: Add the application layer to the local registry: localVxRegistry.Add(this._axVersion, axDetails); // REC: Construct a new service container and initialize // it with the appropriate services: IVfxServices localServices = new VfxServices(); localServices.AddService(typeof(IVfxFixDxRegistry), dxRegistry); localServices.AddService(typeof(IVfxFixVxRegistry), localVxRegistry); // REC: Initialize the parser with the local services: _fixParser.Init(localServices); // REC: Configure the FIX session timer to fire every // second for conducting timeout checks, etc. _fixTimer.Interval = 1000; // REC: Subscribe to the timer in order to determine if // the session has timed out: _fixTimer.Elapsed += HandleElapsed_Timer; // REC: Construct the FIX BeginString using the major // and minor version numbers from the primary dictionary // that is assigned to the version: FixDictionary dxPrimary = dxRegistry.GetEntry(sxDetails.Dictionaries[0].Name); // REC: Construct the appropriate begin string, based on the // major and minor version numbers of the dictionary: this._fixBeginString = sxDetails.FixBs; _fixAssembler.SetField(new FixField(8, this._fixBeginString)); // REC: Initialize the FIX message assembler: _fixAssembler.Init(localServices); // REC: Register required fields for messages: _fixAssembler.SetField(new FixField(8, _fixBeginString)); _fixAssembler.SetField(new FixField(9, "")); _fixAssembler.SetField(new FixField(98, "0")); _fixAssembler.SetField(new FixField(10, "")); xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.SenderCompID']"); if ((xpi.Count > 0) && (xpi.MoveNext())) { // REC: The client sessions need to maintain an independent // reference to the SenderCompID for identification: this._fixSenderCompID = xpi.Current.GetAttribute("content", ""); // REC: Add the field to the assembler so that it gets put // into each outgoing message: _fixAssembler.SetField(new FixField(49, this._fixSenderCompID)); } xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.Reset']"); if ((xpi.Count > 0) && (xpi.MoveNext())) { string resetSequence = xpi.Current.GetAttribute("content", ""); if (resetSequence.CompareTo("true") == 0) { this._resetSequence = true; } } // REC: Maintain a reference to the supplied callback // handler for issuing event notifications: _handler = handler; }
/// <summary> /// The Init method is invoked to initialize an instance of /// the session class with the services, setttings, and handler /// that it requires in order to be activated. All instances of /// a session must be initialized before they can start managing /// a FIX session for their owner. /// </summary> /// <param name="services"> /// The service container that contains the references to all of /// the system services that an instance of the session needs. /// </param> /// <param name="handler"> /// The callback interface that the session directs all of its /// events to as they occur. /// </param> public void Init(IVfxServices services, IVfxFixSessionHandler handler) { // REC: Retrieve the version registry that the session // has been configured to use: IVfxFixVxRegistry vxRegistry = services.GetService(typeof(IVfxFixVxRegistry)) as IVfxFixVxRegistry; // REC: Retrieve the dictionary registry that the session // has been configured to use: IVfxFixDxRegistry dxRegistry = services.GetService(typeof(IVfxFixDxRegistry)) as IVfxFixDxRegistry; // REC: Retrieve the session database service from the // set of services provided by the session's owner: _fixDatabase = services.GetService(typeof(IVfxFixDatabase)) as IVfxFixDatabase; // REC: Retrieve the session configuration from the // service container for relevant settings: IVfxSettings settings = services.GetService(typeof(IVfxSettings)) as IVfxSettings; // REC: Temporary container to simplify accessing the // session settings from the XML configuration document: Dictionary<string, string> mapSettings = new Dictionary<string, string>(); XPathNavigator xpn = settings.Document.CreateNavigator(); XPathNodeIterator xpi = null; xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.Sx.Version']"); if ((xpi.Count > 0) && (xpi.MoveNext())) { this._sxVersion = xpi.Current.GetAttribute("content", "").Trim(); } xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.Ax.Version']"); if ((xpi.Count > 0) && (xpi.MoveNext())) { this._axVersion = xpi.Current.GetAttribute("content", "").Trim(); } xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.Ax.Default']"); if ((xpi.Count > 0) && (xpi.MoveNext())) { this._axDefault = xpi.Current.GetAttribute("content", "").Trim(); } // REC: Retrieve application layer details: VfxFixVxRecord axDetails = vxRegistry.Get(_axVersion); // REC: Adjust the session layer, if one has not been // specified for the connection. if (string.IsNullOrEmpty(this._sxVersion)) { if (axDetails.Layer.ToLower().CompareTo("combined") == 0) { this._sxVersion = this._axVersion; } } // REC: Retrieve the session layer details: VfxFixVxRecord sxDetails = vxRegistry.Get(_sxVersion); // REC: Construct a local instance of a version definition // registry so that the session relies only on the specific // versions that have been specified for the service: VfxFixVxRegistry localVxRegistry = new VfxFixVxRegistry(); // REC: Add the session layer to the local registry: localVxRegistry.Add(this._sxVersion, sxDetails); // REC: Add the application layer to the local registry: localVxRegistry.Add(this._axVersion, axDetails); // REC: Construct a new instance of the service container // and populate it with the services for the session: IVfxServices localServices = new VfxServices(); // REC: The session can use the global dictionaries: localServices.AddService(typeof(IVfxFixDxRegistry), dxRegistry); // REC: The session can use its own version registry: localServices.AddService(typeof(IVfxFixVxRegistry), localVxRegistry); // REC: Initialize the parser with the local services: _fixParser.Init(localServices); // REC: Configure the FIX session timer to fire every // second for conducting timeout checks, etc. _fixTimer.Interval = 1000; // REC: Subscribe to the timer in order to determine if // the session has timed out: this._fixTimer.Elapsed += HandleElapsed_Timer; // REC: Initialize the FIX message assembler: _fixAssembler.Init(localServices); // REC: Register required fields for messages: this._fixBeginString = sxDetails.FixBs; _fixAssembler.SetField(new FixField(8, this._fixBeginString)); _fixAssembler.SetField(new FixField(9, "")); _fixAssembler.SetField(new FixField(98, "0")); _fixAssembler.SetField(new FixField(108, "60")); xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.Heartbeat']"); if ((xpi.Count > 0) && (xpi.MoveNext())) { string fixTimeout = xpi.Current.GetAttribute("content", "").Trim(); // REC: The client sessions need to maintain their own // reference to the heartbeat value: this._fixTimeout = int.Parse(fixTimeout); // REC: Assign the timeout value to the assembler so it // becomes the default for any message that needs it: _fixAssembler.SetField(new FixField(108, fixTimeout)); } xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.SenderCompID']"); if ((xpi.Count > 0) && (xpi.MoveNext())) { // REC: The client sessions need to maintain an independent // reference to the SenderCompID for identification: this._fixSenderCompID = xpi.Current.GetAttribute("content", ""); // REC: Add the field to the assembler so that it gets put // into each outgoing message: _fixAssembler.SetField(new FixField(49, this._fixSenderCompID)); } xpi = xpn.Select("/Session/Protocol/Settings/Setting[@name='Fix.Session.TargetCompID']"); if ((xpi.Count > 0) && (xpi.MoveNext())) { // REC: The client sessions need to maintain an independent // reference to the TargetCompID for identification: this._fixTargetCompID = xpi.Current.GetAttribute("content", ""); // REC: Add the field to the assembler so that it gets put // into each outgoing message: _fixAssembler.SetField(new FixField(56, this._fixTargetCompID)); } _fixAssembler.SetField(new FixField(10, "")); // REC: The client session knows the FIX TargetCompID of the // peer system in advance, unlike the server sessions, so we // can construct the session id in the initialization code: _sessionId = string.Format("{0}-{1}", _fixSenderCompID, _fixTargetCompID); // REC: Maintain a reference to the supplied callback // handler for issuing event notifications: _handler = handler; }