itchfeed 1.0.1__py3-none-any.whl → 1.0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
itch/__init__.py CHANGED
@@ -1,6 +1,5 @@
1
1
  """
2
2
  Nasdaq TotalView-ITCH 5.0 Parser
3
- ================================
4
3
  """
5
4
 
6
5
  __author__ = "Bertin Balouki SIMYELI"
itch/messages.py CHANGED
@@ -1,6 +1,6 @@
1
1
  import struct
2
2
  from dataclasses import make_dataclass
3
- from typing import List, Tuple
3
+ from typing import Dict, List, Tuple, Type
4
4
 
5
5
  MESSAGES = b"SAFECXDUBHRYPQINLVWKJhO"
6
6
 
@@ -1573,7 +1573,7 @@ class DLCRMessage(MarketMessage):
1573
1573
  return message
1574
1574
 
1575
1575
 
1576
- messages = {
1576
+ messages: Dict[bytes, Type[MarketMessage]] = {
1577
1577
  b"S": SystemEventMessage,
1578
1578
  b"R": StockDirectoryMessage,
1579
1579
  b"H": StockTradingActionMessage,
itch/parser.py CHANGED
@@ -1,8 +1,10 @@
1
1
  from queue import Queue
2
2
  from typing import BinaryIO, List
3
3
 
4
- import itch.messages as msg
5
- from itch.messages import MarketMessage, MESSAGES
4
+ from itch.messages import MESSAGES, MarketMessage
5
+ from itch.messages import messages as msgs
6
+
7
+
6
8
  class MessageParser(object):
7
9
  """
8
10
  A market message parser for ITCH 5.0 data.
@@ -17,6 +19,43 @@ class MessageParser(object):
17
19
  file: BinaryIO,
18
20
  cachesize: int = 4096,
19
21
  ) -> List[MarketMessage]:
22
+ """
23
+ Reads and parses market messages from a binary file-like object.
24
+
25
+ This method processes binary data in chunks, extracts individual messages
26
+ according to a specific format, and returns a list of successfully decoded
27
+ MarketMessage objects. Parsing stops either when the end of the file is
28
+ reached or when a system message with an end-of-messages event code is encountered.
29
+
30
+ Args:
31
+ file (BinaryIO):
32
+ A binary file-like object (opened in binary mode) from which market messages are read.
33
+ cachesize (int, optional):
34
+ The size (in bytes) of each data chunk read from the file. Defaults to 4096 bytes.
35
+
36
+ Returns:
37
+ List[MarketMessage]:
38
+ A list of parsed MarketMessage objects that match the allowed message types
39
+ defined in self.message_type.
40
+
41
+ Raises:
42
+ ValueError:
43
+ If a message does not start with the expected 0x00 byte, indicating
44
+ an unexpected file format or possible corruption.
45
+
46
+ Message Format:
47
+ - Each message starts with a 0x00 byte.
48
+ - The following byte specifies the message length.
49
+ - The complete message consists of the first 2 bytes and 'message length' bytes of body.
50
+ - If a system message (message_type == b'S') with event_code == b'C' is encountered,
51
+ parsing stops immediately.
52
+
53
+ Example:
54
+ >>> with open('market_data.bin', 'rb') as binary_file:
55
+ >>> messages = reader.read_message_from_file(binary_file, cachesize=4096)
56
+ >>> for message in messages:
57
+ >>> print(message)
58
+ """
20
59
  max_message_size = 52
21
60
  file_end_reached = False
22
61
 
@@ -126,54 +165,9 @@ class MessageParser(object):
126
165
  All message type indicators are single ASCII characters.
127
166
  """
128
167
  message_type = message[0:1]
129
- match message_type:
130
- case b"S":
131
- return msg.SystemEventMessage(message)
132
- case b"R":
133
- return msg.StockDirectoryMessage(message)
134
- case b"H":
135
- return msg.StockTradingActionMessage(message)
136
- case b"Y":
137
- return msg.RegSHOMessage(message)
138
- case b"L":
139
- return msg.MarketParticipantPositionMessage(message)
140
- case b"V":
141
- return msg.MWCBDeclineLeveMessage(message)
142
- case b"W":
143
- return msg.MWCBStatusMessage(message)
144
- case b"K":
145
- return msg.IPOQuotingPeriodUpdateMessage(message)
146
- case b"J":
147
- return msg.LULDAuctionCollarMessage(message)
148
- case b"h":
149
- return msg.OperationalHaltMessage(message)
150
- case b"A":
151
- return msg.AddOrderNoMPIAttributionMessage(message)
152
- case b"F":
153
- return msg.AddOrderMPIDAttribution(message)
154
- case b"E":
155
- return msg.OrderExecutedMessage(message)
156
- case b"C":
157
- return msg.OrderExecutedWithPriceMessage(message)
158
- case b"X":
159
- return msg.OrderCancelMessage(message)
160
- case b"D":
161
- return msg.OrderDeleteMessage(message)
162
- case b"U":
163
- return msg.OrderReplaceMessage(message)
164
- case b"P":
165
- return msg.NonCrossTradeMessage(message)
166
- case b"Q":
167
- return msg.CrossTradeMessage(message)
168
- case b"B":
169
- return msg.BrokenTradeMessage(message)
170
- case b"I":
171
- return msg.NOIIMessage(message)
172
- case b"N":
173
- return msg.RetailPriceImprovementIndicator(message)
174
- case b"O":
175
- return msg.DLCRMessage(message)
176
- case _:
177
- raise ValueError(
178
- f"Unknown message type: {message_type.decode(encoding='ascii')}"
179
- )
168
+ try:
169
+ return msgs[message_type](message)
170
+ except Exception:
171
+ raise ValueError(
172
+ f"Unknown message type: {message_type.decode(encoding='ascii')}"
173
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: itchfeed
3
- Version: 1.0.1
3
+ Version: 1.0.2
4
4
  Summary: Simple parser for ITCH messages
5
5
  Home-page: https://github.com/bbalouki/itch
6
6
  Download-URL: https://pypi.org/project/itchfeed/
@@ -9,7 +9,7 @@ Author-email: <bertin@bbstrader.com>
9
9
  Maintainer: Bertin Balouki SIMYELI
10
10
  License: The MIT License (MIT)
11
11
  Project-URL: Source Code, https://github.com/bbalouki/itch
12
- Keywords: Finance,Financial,Quantitative,Equities,Data,Feed,ETFs,Funds,Trading,Investing,Portfolio,Optimization,Performance
12
+ Keywords: Finance,Financial,Quantitative,Equities,Totalview-ITCH,Totalview,Nasdaq-ITCH,Nasdaq,ITCH,Data,Feed,ETFs,Funds,Trading,Investing
13
13
  Classifier: Development Status :: 5 - Production/Stable
14
14
  Classifier: Intended Audience :: Developers
15
15
  Classifier: Intended Audience :: Financial and Insurance Industry
@@ -38,6 +38,7 @@ Dynamic: summary
38
38
  [![PYPI Version](https://img.shields.io/pypi/v/itchfeed)](https://pypi.org/project/itchfeed/)
39
39
  [![PyPi status](https://img.shields.io/pypi/status/itchfeed.svg?maxAge=60)](https://pypi.python.org/pypi/itchfeed)
40
40
  [![Supported Python Versions](https://img.shields.io/pypi/pyversions/itchfeed)](https://pypi.org/project/itchfeed/)
41
+ [![PyPI Downloads](https://static.pepy.tech/badge/itchfeed)](https://pepy.tech/projects/itchfeed)
41
42
  [![CodeFactor](https://www.codefactor.io/repository/github/bbalouki/itch/badge)](https://www.codefactor.io/repository/github/bbalouki/itch)
42
43
  [![LinkedIn](https://img.shields.io/badge/LinkedIn-grey?logo=Linkedin&logoColor=white)](https://www.linkedin.com/in/bertin-balouki-simyeli-15b17a1a6/)
43
44
  [![PayPal Me](https://img.shields.io/badge/PayPal%20Me-blue?logo=paypal)](https://paypal.me/bertinbalouki?country.x=SN&locale.x=en_US)
@@ -86,7 +87,7 @@ You can install this project using ``pip``
86
87
  This is useful for processing historical ITCH data stored in files. The `MessageParser` handles buffering efficiently.
87
88
 
88
89
  ```python
89
- from itch import MessageParser
90
+ from itch.parser import MessageParser
90
91
  from itch.messages import AddOrderMessage, TradeMessage
91
92
 
92
93
  # Initialize the parser. Optionally filter messages by type.
@@ -135,7 +136,7 @@ except Exception as e:
135
136
  This is suitable for real-time processing, such as reading from a network stream.
136
137
 
137
138
  ```python
138
- from itch import MessageParser
139
+ from itch.parser import MessageParser
139
140
  from itch.messages import AddOrderMessage
140
141
  from queue import Queue
141
142
 
@@ -0,0 +1,9 @@
1
+ itch/__init__.py,sha256=m8ulOH0nET4yLoKcqWJA-VjOEZldGo932t95rHOZh4w,204
2
+ itch/indicators.py,sha256=-Ed2M8I60xGQ1bIPZCGCKGb8ayT87JAnIaosfiBimXI,6542
3
+ itch/messages.py,sha256=UHr4eBTtgiLg9vO53GpciAxiAO9AD9uCu8Xz3WnfadM,61927
4
+ itch/parser.py,sha256=Hn7ixJsvflSGSwvDyK4IO8yCjEd7ctBz-JsBbK7Arl4,6126
5
+ itchfeed-1.0.2.dist-info/licenses/LICENSE,sha256=f2u79rUzh-UcYH0RN0Ph0VvVYHBkYlVxtguhKmrHqsw,1089
6
+ itchfeed-1.0.2.dist-info/METADATA,sha256=0IDg9F5c87rS3KCy-tHstJlYnre9BMNMkfD9004ntpY,12638
7
+ itchfeed-1.0.2.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
8
+ itchfeed-1.0.2.dist-info/top_level.txt,sha256=xwsOYShvy3gc1rfyitCTgSxBZDGG1y6bfQxkdhIGmEM,5
9
+ itchfeed-1.0.2.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (79.0.1)
2
+ Generator: setuptools (80.3.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,9 +0,0 @@
1
- itch/__init__.py,sha256=5EuuYM_NnDS9xuuUc9kTbAI1fwJp8SwpEhb9A9_Ed24,237
2
- itch/indicators.py,sha256=-Ed2M8I60xGQ1bIPZCGCKGb8ayT87JAnIaosfiBimXI,6542
3
- itch/messages.py,sha256=YBULa6flXYqoicpzgU248eKO8NqEG0mbkReMj9WWU-s,61881
4
- itch/parser.py,sha256=7wUo10vcfNFJQfNYNZmc4XDqnBxn3KcFn7jN12KV8bs,6211
5
- itchfeed-1.0.1.dist-info/licenses/LICENSE,sha256=f2u79rUzh-UcYH0RN0Ph0VvVYHBkYlVxtguhKmrHqsw,1089
6
- itchfeed-1.0.1.dist-info/METADATA,sha256=6F95bHHx01MgIRU-hCb2FV2LowLOmrlF29cQT2DJr_E,12512
7
- itchfeed-1.0.1.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
8
- itchfeed-1.0.1.dist-info/top_level.txt,sha256=xwsOYShvy3gc1rfyitCTgSxBZDGG1y6bfQxkdhIGmEM,5
9
- itchfeed-1.0.1.dist-info/RECORD,,