Skip to content

Commit

Permalink
Merge pull request #8 from vfrazao-ns1/0.0.6/Bug-Fix/TradeBreak-Messa…
Browse files Browse the repository at this point in the history
…ge-Fix

0.0.6/bug fix/trade break message fix
  • Loading branch information
lvfrazao committed May 4, 2019
2 parents 6058305 + 883a840 commit 37d05b3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Folder containing large examples of IEX pcap files
IEX TOPS Sample/
IEXTools/debug/
.vscode/

# Boilerplate:
Expand Down
23 changes: 9 additions & 14 deletions IEXTools/IEXparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ class Parser(object):
"""

def __init__(
self, file_path: str, tops: bool = True, deep: bool = False, tops_version: float = 1.6
self,
file_path: str,
tops: bool = True,
deep: bool = False,
tops_version: float = 1.6,
) -> None:
self.file_path = file_path
self.tops = tops
Expand All @@ -66,10 +70,7 @@ def __init__(
self.version = b"\x01"
self.reserved = b"\x00"
if tops and not deep:
protcol_ids = {
1.5: b"\x02\x80",
1.6: b"\x03\x80",
}
protcol_ids = {1.5: b"\x02\x80", 1.6: b"\x03\x80"}
self.protocol_id = protcol_ids[tops_version]
elif deep:
self.protocol_id = b"\x04\x80"
Expand Down Expand Up @@ -151,19 +152,14 @@ def _get_session_id(self, file_path: str) -> bytes:
return self.session_id
except AttributeError:
iex_header_start = (
self.version
+ self.reserved
+ self.protocol_id
+ self.channel_id
self.version + self.reserved + self.protocol_id + self.channel_id
)
with open(file_path, "rb") as market_file:
for line in market_file:
if iex_header_start in line:
line = line.split(iex_header_start)[1]
return line[:4]
raise ProtocolException(
"Session ID could not be found in the supplied file"
)
raise ProtocolException("Session ID could not be found in the supplied file")

def read_next_line(self) -> bytes:
"""
Expand Down Expand Up @@ -234,8 +230,7 @@ def _seek_header(self) -> None:
)

def get_next_message(
self,
allowed: Optional[Union[List[AllMessages], Tuple[AllMessages]]] = None,
self, allowed: Optional[Union[List[AllMessages], Tuple[AllMessages]]] = None
) -> AllMessages:
"""
Returns the next message in the pcap file. The user may optionally
Expand Down
21 changes: 16 additions & 5 deletions IEXTools/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __init__(self, version: float = 1.6) -> None:
b"\x42": {
"str": "Trade Break Message",
"cls": TradeBreak,
"fmt": "<1sq8sqq",
"fmt": "<1sq8sLqq",
},
b"\x41": {
"str": "Auction Information Message",
Expand All @@ -119,10 +119,12 @@ def __init__(self, version: float = 1.6) -> None:
},
}
self.DECODE_FMT: Dict[int, str] = {
msg[0]: self.message_types[version][msg]["fmt"] for msg in self.message_types[version]
msg[0]: self.message_types[version][msg]["fmt"]
for msg in self.message_types[version]
}
self.MSG_CLS: Dict[int, Type[AllMessages]] = {
msg[0]: self.message_types[version][msg]["cls"] for msg in self.message_types[version]
msg[0]: self.message_types[version][msg]["cls"]
for msg in self.message_types[version]
}

def decode_message(self, msg_type: int, binary_msg: bytes) -> AllMessages:
Expand Down Expand Up @@ -345,10 +347,19 @@ class TradeBreak(Message):
rare and only affect applications that rely upon IEX execution based data."
"""

__slots__ = ("price_type", "timestamp", "symbol", "price_int", "price")
price_type: str # 1 byte
__slots__ = (
"sale_flags",
"timestamp",
"symbol",
"size",
"price_int",
"price",
"trade_id",
)
sale_flags: str # 1 byte
timestamp: int # 8 byte
symbol: str # 8 bytes
size: int # 4 bytes
price_int: int # 8 bytes
trade_id: int # 8 bytes

Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# IEXTools

v 0.0.5
v 0.0.6

This package provides tools for working with data provided by IEX's REST API and tools to decode and use IEX's binary market data (dubbed "HIST"). For more information on the type of data offered by IEX please visit their website: <https://iextrading.com/developer/docs> and <https://iextrading.com/trading/market-data/>

Expand Down Expand Up @@ -280,6 +280,10 @@ By not specifying the `allowed` argument the parser returns 1,000,000 parsed mes
- Added support for version 1.5 TOPS files
- Updated urllib3 version in requirements.txt due to vulnerability

### 0.0.6

- Fixed bug raised in issue #7

### Future Focus

- Additional testing
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
EMAIL = ''
AUTHOR = 'Victor Frazao'
REQUIRES_PYTHON = '>=3.7.0'
VERSION = '0.0.5'
VERSION = '0.0.6'

# What packages are required for this module to be executed?
REQUIRED = ['requests']
Expand Down

0 comments on commit 37d05b3

Please sign in to comment.