Support Board
Date/Time: Tue, 26 Nov 2024 15:40:00 +0000
Post From: More information on the binary structure of market depth .depth files?
[2023-11-20 19:27:55] |
Thanthou - Posts: 2 |
Thank your TrumpTradesOil. Here is a modified version with datetime and putting the struct into a dictionary. import struct from datetime import datetime, timedelta def convert_to_datetime(microseconds_since_epoch): epoch_start = datetime(1899, 12, 30) # SCDateTime epoch start return epoch_start + timedelta(microseconds=microseconds_since_epoch) def read_depth_file(file_path): rows = [] with open(file_path, 'rb') as input_file: header = input_file.read(64) headersrc = struct.unpack('4I48s', header) print(headersrc) while True: d = {} tick = input_file.read(24) if not tick: break src = struct.unpack('qbbhfII', tick) d['datetime'] = convert_to_datetime(src[0]) d['command'] = src[1] d['flag'] = src[2] d['orders'] = src[3] d['price'] = src[4] / 100 d['quantity'] = src[5] rows.append(d) return rows file_path = 'your/file/path' rows = read_depth_file(file_path) for row in rows: print(row) Date Time Of Last Edit: 2023-11-20 19:28:42
|