skip to main | skip to sidebar

Perl Programming Language Tutorial

Pages

  • Home
 
  • RSS
  • Twitter
Monday, October 15, 2012

Fix Message Reader from Log

Posted by Raju Gupta at 9:31 AM – 0 comments
 

Various subroutines of the package FixUtil can be used to read fix message (tag, value pair). Fix message can be extracted. Tag and Value can be identified. Numeric Tag can be converted in to English readable format. It also provide functionality to selectively print only few tags of interest.


 #!/usr/local/bin/perl 

package FixUtil;

# GetTagValue is to convert fix message in to tag value pair. The parameter passed is single fix message or portion of a fix message.

sub GetTagValue
{
  my ($record)=@_;
  my @tagValuePair=split(/;/,$record);
  my $count=0;
  while ($count < @tagValuePair)
  {
    if ( $tagValuePair[$count] =~ /=/)
    {
      ($tag,$value)=split(/=/,$tagValuePair[$count]);
      $tagValue{$tag}=$value;
    }
    $count++;

  }
  return %tagValue;
}

# CleanUp is to convert a log statement to a clean fix message starting with 8=FIX and ending with 10=000 

sub CleanUp {
  my ($record)=@_;
  $record=~s/^.*8=FIX/8=FIX/g;
  $record=~s/10=000.*$/10=000/g;
  return $record;
}

# GetHeader is to get log part before the fix message 

sub GetHeader {
  my ($record)=@_;
  $record=~s/8=FIX.*$//g;
  return $record;
}

# PrintTagValues is to print selected tags from TagValue hash created by GetTagValue. 
# $indent = (integer) number of spaces. This is useful if you would like to indent New, Cancel and Replace messages with different indentation.
# $info = reference to an array which contains list of tags to be printed. e.g. the list should contain 38, 31, 32 if we are interested only in quantities. Following function will only print those three tags.
# $records = reference to hash of tag value created by GetTagValue function 

sub PrintTagValues {
  my ($indent,$info,$records)=@_;
  my $indentation=" ";
  while($indent > 0)
  {
    $indentation=$indentation." ";
    $indent--;
  }
  my $count=0;
  if( $$info[0] =~ "All")
  {
    foreach $tag (keys(%{$records}))
    {
      print "$indentation $tag ($TagValuePair{$tag}) = $records->{$tag} \n";
    }
  }
  else
  {
    while ($count < @{$info})
    {
      print "$indentation $$info[$count] ($TagValuePair{$$info[$count]}) = $records->{$$info[$count]} \n";
      $count++;
    }
  }
  print "\n";
}

%TagValuePair = ( "1","Account",
  "2","AdvId",
  "3","AdvRefID",
  "4","AdvSide",
  "5","AdvTransType",
  "6","AvgPrice",
  "7","BeginSeqNo",
  "8","BeginString",
  "9","BodyLength",
  "10","CheckSum",
  "11","ClOrdID",
  "12","Commission",
  "13","CommType",
  "14","CumQty",
  "15","Currency",
  "16","EndSeqNo",
  "17","ExecID",
  "18","ExecInst",
  "19","ExecRefID",
  "20","ExecTransType",
  "21","HandlInst",
  "22","IDSource",
  "23","IOIid",
  "24","IOIOthSvc",
  "25","IOIQltyInd",
  "26","IOIRefID",
  "27","IOIShares",
  "28","IOITransType",
  "29","LastCapacity",
  "30","LastMkt",
  "31","LastPrice",
  "32","LastShares",
  "33","LinesOfText",
  "34","MsgSeqNum",
  "35","MsgType",
  "36","NewSeqNo",
  "37","OrderID",
  "38","OrderQty",
  "39","OrdStatus",
  "40","OrdType",
  "41","OrigClOrdID",
  "42","OrigTime",
  "43","PossDupFlag",
  "44","Price",
  "45","RefSeqNum",
  "46","RelatdSym",
  "47","Rule80A",
  "48","SecurityID",
  "49","SenderCompID",
  "50","SenderSubID" );
1;

Email This BlogThis! Share to X Share to Facebook

Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments (Atom)
  • Popular
  • Recent
  • Archives

Popular Posts

Powered by Blogger.

Archives

  • ▼  2012 (24)
    • ▼  October (24)
      • Sepearte First name and last name by using PERL re...
      • Validate Info-Perl Script
      • Print Message--Perl Script
      • Password encryption-Perl Script
      • Convert to Seconds--Perl script
      • File size and modified time
      • Convert to minute-Perl script
      • Login screen using Perl
      • Huge text file comparator
      • Parse Input - Perl Script
      • Get colored difference - Perl Script
      • Perl function to compare two dates
      • Script to rotate any log file
      • Cross Referencing script
      • Random Bunch Creation in Perl
      • NASDAQ Status checker using Perl
      • Fix Message Reader from Log
      • Perl script to find files older than x minutes
      • Perl function to check whether the passed path is ...
      • Date Arimatic
      • Perl function to trim leading and trailing spaces ...
      • Perl function to check whether the passed path is ...
      • Perl function to check whether file or dir name pa...
      • Perl function to check whether the passed path is ...
 

Followers

Labels

  • File Searching Example (1)
  • Perl Date Example (2)
  • Perl Encryption Example (1)
  • Perl File Example (2)
  • Validation Example (1)
 
 
© 2011 Perl Programming Language Tutorial | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger