#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Help in writing a python script


    Hi,

    I am a beginner and work on various messages received from a company server related to different products and so on. I am looking for a python script that can sort messages with unique flag values and give me the output in a text file.

    I get these messages in the form of .zcap file from server and I use an internal tool to filter:
    Step 1) Zcap file to get security types,
    Step 2) then filter each security types file that generate various exchanges files
    Steps 3) lastly filter each exchange files to get message types files.

    For eg: I filtered a .zcap file to get message types as
    BOND-----CVE----- MTR_BOND, MTFD_BOND, MTQ_BQUOTE, MTQ_MBBOQUOTE
    BOND-----NYSE---- MTR_BOND, MTFD_BOND, MTQ_BQUOTE
    BOND-----TSE--- MTR_BOND, MTFD_BOND, MTA_RECAP, MTT_TRADE, MTT_STATUS, MTA_CLOSE

    Step 4) at present, I run a UNIX command on each message type (for eg; MTR_BOND) that generates multiple text files of each unique flag value messages .
    $ awk '/MTQ/,/Quote Condition/{a[i++]=$0;if($0~/Flags:/){sub(":","",$2);fname=$2}if($0~/Quote Condition/){for(j=0;j<=i;j++)print a[j] > fname;i=0}}' MTA.txt

    This is a very tedious job to run this command on each message type file (for eg; MTR_BOND) level, therefore I want a python script that I can run at Security Type level (for eg; BOND).
    Can you please help me to write a python script (preferably) that I can run for each security type that will generate one output text file for each message types under each exchange with only 1 message of unique flag value.

    I am unable to attach sample text files to this thread so, Ive put some sample messages below:

    MTQ_BQUOTE, Length: 49, Timestamp: 7:36:33.000
    MsgKey: symbol: xxxx
    Symbol: xxxx, hash 64555104
    QS Symbol: xxx.xxx, market 28
    Security Type: BOND (5)
    Symbol Type: Bond.Share.Single.None
    Session: CA_Day (4)
    Ticker Exchange: TSE (16) => 16
    Flags: x00000000
    Bid: 9750, frac: 2, pure7 val: 0000
    Bid Size: 6
    Ask: 9995, frac: 2, pure7 val: 0000
    Ask Size: 50
    Quote Condition: x00

    MTA_RECAP, Length: 76, Timestamp: 7:30:02.000
    MsgKey: symbol: xxxx
    Symbol: xxxx, hash 6454414F
    QS Symbol: cNAT.DB, market 28
    Security Type: BOND (5)
    Symbol Type: Bond.Share.Single.None
    Session: CA_Day (4)
    Ticker Exchange: CVE (18) => 18
    Flags: x00000000
    Open: 0, frac: 3, pure7 val: ---
    High: 0, frac: 3, pure7 val: ---
    Low: 0, frac: 3, pure7 val: ---
    Last: 0, frac: 3, pure7 val: ---
    Last Market: 18
    Change: 0, frac: 2, pure7 val: ---
    Total Volume: 0
    Bid: 9500, frac: 2, pure7 val: 00
    Bid Market: 18
    Ask: 9680, frac: 2, pure7 val: 00
    Ask Market: 18
    Bidtick Flag: x00000000

    MTA_CLOSE, Length: 58, Timestamp: 16:05:12.234
    MsgKey: symbol: xxxx
    Symbol: xxxxx, hash 2F00717B
    QS Symbol: xxxxx, market 12
    Security Type: BOND (5)
    Symbol Type: Bond.Share.Single.None
    Session: US_Day (3)
    Ticker Exchange: NYSE (7) => 7
    Flags: x00000000:
    Date: 10/5/2012
    Open: 11425, frac: 2, pure7 val: 000
    High: 11425, frac: 2, pure7 val: 000
    Low: 11425, frac: 2, pure7 val: 000
    Close: 11425, frac: 2, pure7 val: 0000
    Total Volume: 10
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    I suppose you deserve a thoughtful answer but you're employed, and I'm not, and I have no clue what is a zcap file.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Smile


    Originally Posted by b49P23TIvg
    I suppose you deserve a thoughtful answer but you're employed, and I'm not, and I have no clue what is a zcap file.
    Thanks for your response. zcap is nothing but text files (sorry to mention company term). Please let me know if you have trouble understanding anything else in the post.

IMN logo majestic logo threadwatch logo seochat tools logo