/// <summary> /// The GetDictionaryFromField method is invoked to attempt /// to determine which dictionary associated with a specific /// version definition contains a specific FIX field. /// </summary> /// <param name="version"> /// The FIX version definition to search. /// </param> /// <param name="tag"> /// The FIX tag of the element to search for. /// </param> /// <returns> /// The first dictionary in the version definition that has /// a field definition that matches the specified tag. /// </returns> public FixDictionary GetDictionaryFromField(string version, int tag) { FixDictionary result = null; if (_vxRegistry != null) { VfxFixVxRecord vxDetails = _vxRegistry.Get(version); if (vxDetails != null) { if (_dxRegistry != null) { foreach (VfxFixVersion_Dictionary_Reference dxEntry in vxDetails.Dictionaries) { FixDictionary dxInstance = _dxRegistry.GetEntry(dxEntry.Name); if (dxInstance != null) { if (dxInstance.Fields.GetElement(tag) != null) { result = dxInstance; break; } } } } } } return(result); }
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 PopulateHdrElements method populates the header section /// of a FIX message with the header elements from the specified /// version of the FIX protocol. /// </summary> /// <param name="version"> /// The version of the FIX protocol that is used to populate the /// header elements of the message. /// </param> /// <param name="msg"> /// The FIX message instance that is to be populated with all of /// the header elements from the specific FIX version. /// </param> private void PopulateHdrElements(string version, FixMessage msg) { VfxFixVxRecord vxDetails = _vxRegistry.Get(version); if (vxDetails != null) { // REC: Ensure that there is at least one FIX dictionary // assigned to the specified version definition: if (vxDetails.Dictionaries.Count > 0) { FixDictionary dxEntry = _dxRegistry.GetEntry(vxDetails.Dictionaries[0].Name); if (dxEntry != null) { FixDxCollection hdrElements = dxEntry.Resolve(dxEntry.Header); if (hdrElements != null) { // REC: Create the sort ordering for the elements // and populate any fields and groups that have been // registered with the assembler: Collection <int> ordering = new Collection <int>(); foreach (IFixDxElement dxElement in hdrElements) { ordering.Add(dxElement.Tag); if (dxElement is FixDxResolvedField) { if (_mapFields.ContainsKey(dxElement.Tag)) { msg.Header.SetField(_mapFields[dxElement.Tag]); } } else { if (_mapGroups.ContainsKey(dxElement.Tag)) { msg.Header.AddGroup(_mapGroups[dxElement.Tag]); } } } // REC: Assign the sort ordering for the header // elements to the message's header: msg.Header.SetOrdering(ordering); } } else { string error = string.Format("Dictionary \"{0}\" not registered.", vxDetails.Dictionaries[0]); throw new ArgumentException(error); } } else { string error = string.Format("The version \"{0}\" has no associated dictionaries.", version); throw new ArgumentException(error); } } else { string error = string.Format("The version \"{0}\" is not registered.", version); throw new ArgumentException(error); } }