Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

NormalOATS

by SamCG (Hermit)
on Jun 06, 2005 at 17:05 UTC ( [id://463994]=CUFP: print w/replies, xml ) Need Help??

OATS (Order Audit Trail System) are standardized csv files produced by the NASD for Order tracking purposes. Unfortunately, each record tends to place similar data in vastly different columns, making the file itself basically human-unreadable. The record layout is based on the code in field 2.

I wasn't entirely thrilled with the ways I was imagining to do this, so a query to the chatterbox was rewarded with several monks pointing me to RoyJohnson's piece on function dispatch tables here. I was most pleased.

Comments appreciated.

Caveats:
Done on a windows box, for a windows network. Sorry, I'm not infrastructure.
Oh, the email via blat was forced on me. I've always preferred Mail::Sender myself.
#! perl -w my $blat = 'C:\blat\blat.exe '; @recips = ('scg@yyyy.com'); $whereto="F:/Apps/"; $date = time(); (undef, undef, undef, $day, $mon, $year) = localtime $date; $year = $year + 1900; $mon++; $data = "OATS"; $current=$year.sprintf("%02d",$mon).sprintf("%02d", $day); $data = $whereto.$data; #print $data."\n"; ($currentfile) = reverse glob($data."\\*.lis"); $translate = $data."\\OATS.".$current.".csv"; %disp_table = ('OE'=>\&oentry, 'NW'=>\&nwentry, 'CL'=>\&clentry, 'EX'=>\&exentry, 'OR'=>\&orentry, 'CL'=>\&clentry, 'RT'=>\&rtentry, 'CR'=>\&crentry); open IN, "<".$currentfile; open OUT, "+>$translate"; print OUT 'Record Type, OE Type, Receive Firm ID, Received Date, Order + ID, Routing Firm MP ID, Symbol, Buy/Sell, Shares/Quantity, Limit Pri +ce, Time in Force, Account Type, Method Code, Special Handling, Branc +h Seq #, Event Timestamp, Cancel Type, Cancel Flag, Received OE ID, O +rder Firm, Action Code, Ex. Time, Routing Firm, Replaced Order ID, Re +placed Order time'."\n"; while (<IN>){ &initvar; @row = split /,/; if ($row[0] eq '#OE#'){ (($disp_table{$row[1]}->(@row))||&deft); &prtout; } } close IN; close OUT; open TXT, ">$data\\msg.txt"; print TXT "OATS feed file report for ".$date; close TXT; for (@recips){ system ($blat.$data."\\msg.txt".' -to "'.$_.'" -attach "'.$transla +te.'"'); } sub exentry { ($rectype, $oetype, $recdate, $orderid, $timestamp, $branchseq, $qua +ntity, $symbol) = @_[0, 1, 7, 8, 9, 10, 11, 14]; } sub rtentry{ ($rectype, $oetype, $action, $ROEID, $orfirm, $recdate, $orderid) = @_[0, 1, 2, 3, 6, 7,8]; ($rtfirm, $symbol, $xtime, $quantity, $method)= @_[9, 11, 12, 13, 14]; } sub clentry{ ($rectype, $oetype, $action, $ROEID, $orfirm, $recdate, $orderid, $sy +mbol, $timestamp) = @_[0, 1, 2, 3, 6, 7,8, 9, 10]; ($ccltype, $cclflag) = @_[11, 14]; } sub crentry{ ($rectype, $oetype, $action, $ROEID, $orfirm, $recdate, $orderid) = @_[0, 1, 2, 3, 6, 7,8]; ($ordertimer, $orderidr, $orderid, $rtfirm, $xtime, $method, $symbol, $side, $quantity, $limit, $tif, $spechand, $accttype) = @_[7, 8, 10, 11, 13, 14, 15, 16, 17, 18, 21, 25, 33]; } sub nwentry{ ($rectype, $oetype, $recdate, $orderid, $mpid, $timestamp, $method, $symbol, $side, $quantity, $limit, $tif, $accttype) = @_[0, 1, 7, 8, 9, 10, 12, 13, 14, 15, 16, 19, 31]; } sub oentry{ ($rectype, $oetype, $action, $recdate, $orderid, $mpid, $timestamp, $symbol, $side, $limit, $tif, $spechand, $accttype, $branchseq, $qu +antity) = @_[0, 1, 2, 7, 8, 9, 10,13, 14, 15, 18, 22, 30, 34, 35]; } sub orentry{ ($rectype, $oetype, $recdate, $orderid, $mpid, $timestamp, $symbol, $side, $limit, $tif, $accttype, $quantity) = @_[0, 1, 7, 8, 9, 10,13, 14, 15, 19, 31, 35]; } sub prtout{ $recdate = &formDate($recdate); $timestamp = &formDate($timestamp); $xtime = &formDate($xtime); $ordertimer = &formDate($orderTimer); print OUT join ', ', ($rectype, $oetype, $recid, $recdate, $orderid, + $mpid, $symbol, $side, $quantity, $limit, $tif, $accttype, $method, $spechand, $bran +chseq, $timestamp, $ccltype, $cclflag, $ROEID, $orfirm, $action, $xtime, $rtfirm, $orderidr, $ordertimer); print OUT "\n"; } sub initvar{ $rectype=$oetype= $recid= $recdate= $orderid= $mpid= $symbol= $side= $quantity= $limit= $tif=$accttype= $method= $spechand= $times +tamp = $branchseq= $action= $ROEID= $orfirm= $ccltype= $cclflag=$xtime=$rtfirm= '';} sub deft{ return 1; } sub formDate{ my $enter = shift; $enter =~ s!(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})!$2/$3/$1:$4:$ +5:$6!; return $enter; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://463994]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-03-19 07:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found