Skip to content

Commit

Permalink
Merge pull request #691 from petedmarsh/read-historical-files-as-bytes
Browse files Browse the repository at this point in the history
Open historical data files in binary mode (it's faster)
  • Loading branch information
liampauling authored Sep 11, 2023
2 parents c6a06f0 + 6bb96f5 commit 5c97a15
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions flumine/streams/historicalstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def _add_stream(self, unique_id: int, operation: str):
else:
raise ListenerError("Unable to process '{0}' stream".format(operation))

def on_data(self, raw_data: str) -> Optional[bool]:
def on_data(self, raw_data: bytes) -> Optional[bool]:
try:
data = json.loads(raw_data)
except ValueError:
Expand All @@ -216,7 +216,7 @@ def _read_loop(self) -> dict:
self.listener.register_stream(self.unique_id, self.operation)
listener_on_data = self.listener.on_data # cache functions
stream_snap = self.listener.stream.snap
with open(self.file_path, "r") as f:
with open(self.file_path, "rb") as f:
for update in f:
if listener_on_data(update):
yield stream_snap()
Expand Down
2 changes: 1 addition & 1 deletion flumine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_file_md(file_dir: Union[str, tuple]) -> Optional[MarketDefinition]:
# get value from raw streaming file marketDefinition
if isinstance(file_dir, tuple):
file_dir = file_dir[0]
with open(file_dir, "r") as f:
with open(file_dir, "rb") as f:
first_line = f.readline()
update = json.loads(first_line)
if "mc" not in update or not isinstance(update["mc"], list) or not update["mc"]:
Expand Down

0 comments on commit 5c97a15

Please sign in to comment.