Login Page - Create Account

Support Board


Date/Time: Tue, 26 Nov 2024 15:25:27 +0000



[Programming Help] - More information on the binary structure of market depth .depth files?

View Count: 893

[2021-09-28 02:34:37]
TrumpTradesOil - Posts: 8
Is there any further information on the binary structure of .depth files?

I'm aware of this webpage: Market Depth Data File Format

but that only gives the c++ struct of records and the struct of the header record. Is there any other information available that might help with reading those files from externally written software?

Thanks! :)


Aggregate list of things I know are true about the .depth binary (correct me if I'm wrong)
- the header record is 64 bytes
- the depth record is 24 bytes
- data is stored in the form of each market depth update
- a flag of 01 denotes the end of a batch of market depth updates
Date Time Of Last Edit: 2021-09-28 08:12:31
[2021-09-29 16:06:01]
Sierra Chart Engineering - Posts: 104368
This is all a correct understanding:
Aggregate list of things I know are true about the .depth binary (correct me if I'm wrong)
- the header record is 64 bytes
- the depth record is 24 bytes
- data is stored in the form of each market depth update
- a flag of 01 denotes the end of a batch of market depth updates

Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2021-10-03 21:00:18]
TrumpTradesOil - Posts: 8
Ok cool! Thankyou so much for confirming :)

For others who follow up later, here's what I ended up with in python that can read the market depth file:


import struct

inputfile = open("marketdata.depth",'rb')

rows=[]
with inputfile as f:
header=f.read(64)
headersrc = struct.unpack('4I48s', header)
print(headersrc)

while True:
tick=f.read(24)
if not tick:
break

src = struct.unpack('qbbhfII', tick)
rows.append(src)

for x in rows:
print(x)

Date Time Of Last Edit: 2021-10-03 22:32:46
[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

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account