Routing Rules and Session Events: XML Transformation Language
Overview
Routing rules are main elements in FIXEdge configuration file. They contain FIXEdge instructions for:
- Routing of incoming and outgoing FIX messages (via the correspondence between ClientID and FIX Session).
- Filtering of incoming and outgoing FIX messages.
- Transformation of incoming and outgoing FIX messages
More than one rule can be applied to a message. It is also possible to route one message to multiple destinations or to the same destination multiple times. See section 'Cases of Routing Rules' for details. All rules are applied to each FIX message separately (independently) in the order set in the configuration file. Even if a set of transformation actions is applied to messages, the next rule will be applied to the original message. Details are described in the Rule element section.
Session Events are a special kind of business rules that handle events launched during execution. The following FIXEdge events can be processed:
- New session was created. See 'Element CreateSessionEvent'.
- Session was destroyed. See 'Element DestroySessionEvent'.
- Inability to route a message to a specified target. See 'Element OnUndeliveredMessageEvent'.
- Session level reject was received in response to the sent application message. See 'Element OnSessionLevelRejectEvent'.
- Session level reject was received with unexpectedly high sequence numbers. See 'Element OnSessionLevelRejectWithSeqNumTooHighEvent'.
- Session level reject was sent in response to the received application message. See 'Element OnOutgoingSessionLevelRejectEvent'.
- Routing rule failed during execution. See 'Element OnRuleFailEvent'.
Allowed memory usage is reached and exceeded. See 'Element OnNotificationEvent'.
Be careful, while Routing rules mechanism is very flexible, you can even implement loops, and, as a case infinite loops. For example, you create a route message from client "The client" - > "Some another client" - > "The client". And if "The client" is able to process its own message and output is the same or meet the rule above, you will take a risk to get infinite loop. To take more detailed description and ways to avoid such behavior, see the 'BL loops and finite control' section.
Rule element
Element <Rule> is meant to describe one Routing rule. Each <Rule> element consists of 3 sections (XML elements):
Name | Section Description |
---|---|
<Source> | Mandatory section. This section defines instructions for primary filtering of messages. <Source> element defines a source from which the FIX message can come. If the message source coincides with the source defined in the section <Source> then the rule will be applied to the message. See part 'Source element' for details. |
<Condition> | Optional section. This section contains a set of pre-defined criteria. The application checks FIX messages on the criteria and if the criteria is met the instructions are to be executed; otherwise section <Action> is ignored. See part 'Condition element' for details. |
<Action> | Mandatory section. The section denotes the instructions that must be performed when a Rule is being applied to a message. It must contain at least one instruction. See part 'Action element' for details. |
<Rule> element has two attributes:
Attribute | Description |
---|---|
Enabled | Optional. Possible values "true" or "false". <Rule Enabled=”false”> disables rule parsing by Business Layer and the rule is not loaded into the memory. By default the attribute value has a "true" value. |
Description | Optional. Used for naming of rules |
Example:
<Rule Enabled="true" Description="Save order data"> <Source> <!-- Source (FIX session or Transport Client) definition --> </Source> <Condition> <!-- conditions definition --> </Condition> <Action> <!-- actions definition --> </Action> </Rule>
Note: Any XML comments cannot be inside <Rule> structure, only outside the rule. If the formed rules do not meet the syntax requirements, FIXEdge stops loading and records an error message in the log file.
Source element
Source from which the FIX message can come for processing, defines either a FIX Session or a Transport Client (i.e. Transport Adaptor Session) by means of one of 3 variants:
by the element FIXSession
Defines FIX session as a source; FIX session is identified either by the pair of attributes "SenderCompID" and "TargetCompID" or by the set of attributes "SenderCompID", "TargetCompID" and "SessionQualifier".
Example:
<Source> <FixSession SenderCompID="Sender" TargetCompID="Target" SessionQualifier="Q1" /> </Source>
The values of the attributes have to coincide with values defined for properties: FixLayer.FixEngine.Session.<Name>.SenderCompID and FixLayer.FixEngine.Session.<Name>.TargetCompID (and optionally FixLayer.FixEngine.Session.<Name>.SessionQualifierValue) which were configured for FIX Sessions.
by the element Client
Defines Transport Client as source; The attribute "name" of the element <Client> is used
Example:
<Source> <Client Name="TestClient"/> </Source>
See also configuring Transport Adaptors (for example: property TransportLayer.SmtpTA.SMTPSessions)
by the attribute "Name"
Defines the identifier of FIX session or Transport Client as source; The attribute "name" of the element <Source> is used
Example:
<Source Name="SourceID"/>
Note: It is possible to use the rule for all configured sessions. In this case it is necessary to use pair of symbols ".*" in the attributes' values.
For example:
<!-- Messages from any transport adaptors will be processed --> <Source> <Client Name=".*"/> </Source> <!-- Messages from any FIX sessions related to TargetCompID="Target" will be processed --> <Source> <FixSession SenderCompID=".*" TargetCompID="Target"/> </Source>
Note: Source identifier has the following restrictions:
- The name of source identifier must be unique for each FIX session;
- The source identifier of TA client must be represented as Client ID;
- It must contain characters with codes from ASCII [30] to ASCII [128];
- It must begin with a letter, digit or underlining symbol ‘_’ ;
Whitespace characters in the beginning or in the end of name will be ignored by rule parsing.
Condition element
The <Condition> element is not required for the routing rule. But if the element is required, it may contain several criteria described below in this part. In fact, each criterion (specified as an XML element) is a function which can be applied to the whole FIX message as well as to particular fields of the FIX message. The function returns "true" or "false". Input variables of this function are defined via XML element's attributes: 'Field', 'Value', etc. <Condition> is met when all the criteria (functions) return "true". It means that condition criteria are joined by "AND".
Example:
<Rule> <Source Name=".*"/> <Condition> <!-- set of criteria, criteria are joined by "AND" --> <NotExistField Field="41" /> <MatchField Value="G|AC" Field="35"/> <EqualDestination Value="CME1" Strategy="OrderFlow100"/> </Condition> <Action> <!-- any action ... --> </Action> </Rule>
Condition element extensions
Combine conditions by "OR"
If it is necessary to join several criteria by "OR", another <Condition> element has to be added into the business rule.
Example: Condition 1 and Condition 2 are joined by "OR"
<Rule Description="Condition: ORed"> <Source> <FixSession SenderCompID="Target42" TargetCompID="Sender42" /> </Source> <Condition> <!-- Condition 1 --> <!-- set of criteria for Condition 1 --> <MsgType> <Val>F</Val> </MsgType> <MsgType> <Val>D</Val> </MsgType> </Condition> <Condition> <!-- Condition 2 --> <FieldLengthGreaterOrEqual Field="55" Length="3" /> </Condition> <Action> <!-- any set of actions --> </Action> </Rule>
The added <Condition> element can be empty, for example:
<Rule Description="Condition: ORed"> <Source> <FixSession SenderCompID="Target42" TargetCompID="Sender42" /> </Source> <Condition> <!-- Condition 1 --> <!-- set of criteria for Condition 1 --> <MsgType> <Val>F</Val> </MsgType> <MsgType> <Val>D</Val> </MsgType> </Condition> <Condition> <!-- Condition 2 --> <FieldLengthGreaterOrEqual Field="55" Length="3" /> </Condition> <Condition/> <!-- Condition 3 is empty --> <Action> <!-- any set of actions --> </Action> </Rule>
Inclusion and Exclusion blocks within Condition element
There are two XML-elements for grouping of criteria (functions) inside the <Condition>: <Inclusion> and <Exclusion>. XML-element <Exclusion> is used in the <Condition> to invert the result of set of criteria specified in the section <Exclusion>. I.e. <Exclusion> is a logical negation.
The element <Exclusion> can be used separately or in combination with <Inclusion>. The lement <Inclusion> is used for grouping of set of the rest criteria when <Exclusion> is used. Usage of <Inclusion> separately from <Exclusion> is not needed.
<Condition> <Inclusion> <!-- function A "AND" function B --> <A/> <B/> </Inclusion> <Exclusion> <!-- NOT (function C "AND" function D) --> <C/> <D/> </Exclusion> </Condition> <!-- Result = (A AND B) AND NOT (C AND D) -->
Examples:
<Condition> <EqualField Field="35" Value="D"/> </Condition> | Means (35 = “D”) |
<Condition> <Inclusion> <EqualField Field="35" Value="D"/> </Inclusion> </Condition> | Means the same as previous example |
<Condition> <Exclusion> <EqualField Field="55" Value="MSFT"/> <EqualField Field="40" Value="2"/> </Exclusion> </Condition> | Means NOT(55 = “MSFT” AND 40 = “2”) |
<Condition> <Inclusion> <EqualField Field="35" Value="D"/> </Inclusion> <Exclusion> <EqualField Field="55" Value="MSFT"/> <EqualField Field="40" Value="2"/> </Exclusion> </Condition> | Means (35=”D” AND NOT(55 = “MSFT” AND 40 = “2”)) |
Functions of Condition element
EqualField
Compares two values as strings and returns "true" when they are equal:
<EqualField Field="35" Value="D" />
Allowed to use a list of values for comparison. In this case xml-element <Val> has to be used, hereinafter "<Val> list". Returns "true" if given 'Field' is equal one of the value from given <Val> list:
<EqualField Field = "35"> <Val>D</Val> <Val>G</Val> <Val>F</Val> </EqualField>
NotEqualField
Compares two values as strings and returns "true" when they are not equal:
<NotEqualField Field="35" Value="asd"/>
Allowed to use a list of values for comparison. In this case the function returns "true" if the 'Field' is not equal to any value from the given <Val> list:
<NotEqualField Field = "35"> <Val>D</Val> <Val>G</Val> <Val>F</Val> </NotEqualField>
FieldIsLessThan
Compares two values as float numbers and returns "true" when given 'Field' less than 'Value':
<FieldIsLessThan Field