Skip to content

Commit

Permalink
Merge branch 'pr/16'
Browse files Browse the repository at this point in the history
  • Loading branch information
davclark committed Apr 26, 2016
2 parents 79658ee + db0dd2f commit 591719d
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion marketflow/ITCHbin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import struct
import gzip
import csv


class ITCHv5:
Expand Down Expand Up @@ -103,6 +104,23 @@ def print_records(self):
# 6-byte integer
print(','.join(self.to_string(r) for r in rec))

def base_fname(self):
'''Get the file name, excluding any filepath chars,
file extensions, and version numbers
'''
return self.fname[self.fname.rfind('/')+1 : self.fname.find('-')]

def to_fixed_width(self):
'''Output the records to a fixed-width text for each message type'''
base = self.base_fname()
for rec in self.records():
rec = [self.to_string(r) for r in rec]
msg_type = rec[0]
with open(base+'_'+rec[0]+'.txt', 'a') as outfile:
writer = csv.writer(outfile)
writer.writerow([' '.join(rec[3:])])


def main():
from sys import argv, exit

Expand All @@ -112,4 +130,8 @@ def main():
print('Usage: ITCHbin.py <ITCH v5.0 file>')
exit(1)

itch.print_records()
# itch.print_records()
itch.to_fixed_width()

if __name__ == '__main__':
main()

0 comments on commit 591719d

Please sign in to comment.