Preface
FIXEdge offers solution for Business Rules purposed to provide routing, transferring, and data manipulations for FIX messages that go through the Business Layer of FIXEdge. See BL Scripting with JavaScript for more information.
Changing field values in repeating groups using JavaScript
This example describes how to change the Party Role (452) 's value from '1' (Executing Firm) to '17' (Contra Firm) in Execution Report (35=8).
Rule
The rule on the call of the JavaScript. Condition section sets up the condition for filtering messages by field MsgType (35) = 8.
<Rule Description="Save Parties for every incoming Execution Report (35=8)"> <Source Name=".*" /> <Condition> <MsgType> <Val>8</Val> </MsgType> </Condition> <Action> <Script Language="JavaScript" FileName ="updatePartyRole.js"/> <!-- Do other necessary transformations and actions--> <!-- ... --> </Action> </Rule>
See Rule element for more information
JavaScript
Further, use JavaScript "updatePartyRole.js" on repeating group transformation:
parties = getGroup(453); groupSize = getNumField(453); if ( (groupSize > 0) && isGroupValid(parties) ) // check if message is valid { for (i=0; i < groupSize; ++i) // Repeat for all members in the repeating group { if (getNumField(parties, i, 452) == 17) // If PartyRole in the first group equals '17' change it to '1' { setNumField(parties, i, 452, 1) // Notice, that numbering starts from zero. } } }
Storing repeating groups in Database
This example describes how to write the values from the Parties repeating group in Trade Capture Report (35=AE) to specific DB columns.
History Configuration
It is necessary to create the History definition in the Business Layer Configuration file and to register all the fields that are in the database table and in the order in which they are registered in the database.
<History Name="Parties" StorageType="ODBC" MaxNumberOfRecords="15000" TableName="Parties" ColumnSize="256" ConnectionString="DSN=TradeCap;UID= admin;Pwd=temp_pass;"> <KeyField ColumnName="TradeReportID" ColumnSize="128">571</KeyField> <KeyField ColumnName="PartyID" ColumnSize="256">448</KeyField> <Field ColumnName="PartyIDSource" ColumnSize="256">447</Field> <Field ColumnName="PartyRole" ColumnSize="256">452</Field> </History>
See Histories for more information
Rule
The rule on the call of the JavaScript
<Rule Description="Save Parties for every incoming AE message"> <Source Name=".*" /> <Condition> <EqualField Field="35" Value="AE" /> </Condition> <Action> <Script Language="JavaScript" FileName="TrdCapt.js" /> </Action> </Rule>
See Rule element for more information
JavaScript
JavaScript "TrdCapt.js" for storing in a DB
tags = new Array(447, 452); //In this array, we assign non-key tag numbers, below which the loop will go through this array with getStringField. partyKey = new Array(); //An array in which the key fields 571 and 448 will be stored partyKey.push(getStringField(571)); //We write down the first part of the key. In this example, this is TradeReportID hndl = getGroup(453); groupSize = getNumField(453); if (null != groupSize and isGroupValid(hndl)) { for (i = 0; i < groupSize; ++i) { partyData = new Array(); // An array for data to be stored in db. the values of the 447 and 452 tags entry = i; partyKey.push(getStringField(hndl, i, 448)); //Record the second part of the key, PartyID if (null == getRecordFromHistory("Parties", partyKey)) //Check if there is already such an entry in the database { for (j = 0; j < tags.length; ++j) // go through all fields to be stored. { // val = getStringField(hndl, i, tags[j]); if (undefined == val) val = ""; // missing tag = "", In the database for non-key fields it is desirable to enable write NULL partyData.push(val); } saveToHistory("Parties", partyKey, partyData, ""); // Save records to the database } else { //If such a record already exists in the database, then we write a notification and do nothing. print("Do nothing. Party duplicate has found in DB for " + partyKey); } } }
Messages with the same TradeReportID (571) and PartyID (448) tags are considered as duplicates and are filtered.
For changing this behavior, KeyFields in History configuration should be modified/extended