Question

I am trying to parse a file which has ITCH messages in it:

http://www.nasdaqtrader.com/Trader.aspx?id=DPSpecs_USEquities#TVITCH¬ http://www.nasdaqtrader.com/content/technicalsupport/specifications/dataproducts/NQTV-ITCH-V4_1.pdf¬

Each price is represented as a 32bit fixed point number with 18 whole part bits and 14 decimal part bits. (6 whole number digits followed by 4 decimal digits)

e.g.

200,000.0000
110000110101000000 00000000000000

I have had a look at the struct class but this only deals with whole bytes as its for converting from binary encoded c structs.

I have had a look at the decimal.Decimal module but it seems that you can only instantiate it using a string and this assumes that you already have the number in string format.

Was it helpful?

Solution

Python's struct.unpack() is exactly what you need. You just need to formulate the appropriate format string so the module can know what fields are where and what binary format they have, and you should quickly be able to decode your data.

You explained things in terms of bits, but that's not how ITCH really works. The fixed-decimal fields really are N bytes long, with some decimal shift implied. So you can read a price field as an integer and then divide it by 1e4 to get the float value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top