Login Page - Create Account

Support Board


Date/Time: Thu, 02 May 2024 00:45:50 +0000



Post From: SCID Format

[2013-04-20 22:59:04]
Kiwi - Posts: 374
It turns out that SCID is easy to understand and relatively easy to convert.

I'm posting the code because your choice of date format is the major issue. This one spits out a date and a time field in excel format (first part is days since the end of 1899 and the part after the decimal point is current time divided by 24 hours in seconds (86400)). It also includes code to convert time to Python datetime format (deserialize).

It takes arguments in the form:
python SCID_to_TSV <filename> <time zone adjustment>

It will output the same filename but with a .tsv extension instead of .scid. Time zone adjustment is called with nothing or 0 for UTC, l for local time, and a number for offset from UTC.

It does the conversion of a 10.1Mbyte scid to a 265,529 line tsv file in 1.8 seconds on an i5 system.

I've stopped development on this version because I'm planning to use Pandas Dataframes for analysis so I'm simply creating a Python module to interact with Sierra Chart.

import csv
import sys
import numpy as np
import struct
from time import ctime
from datetime import date, datetime, time, timedelta
# import ipdb # import ipdb; ipdb.set_trace(); ## *** ##


def deserialize(excelDateAndTime):
date_tok = int(excelDateAndTime)
time_tok = round(86400*(excelDateAndTime - date_tok))
d = date(1899, 12, 30) + timedelta(date_tok)
t = time(*helper(time_tok, (24, 60, 60, 1000000)))
return datetime.combine(d, t)


def helper(factor, units):
factor /= 86399.99
result = list()
for unit in units:
value, factor = divmod(factor * unit, 1)
result.append(int(value))
result[3] = int(0)
return result


def excelTimeAdjust(date_and_time, tzAdjust):
return date_and_time + tzAdjust.seconds/86400.0


def getRecords(filename, fileoutput, tzvar):
"""
Read in records from SierraChart .scid data filename
"""
sizeHeader = 0x38
sizeRecord = 0x28
if tzvar == 99999:
tzAdjust = datetime.fromtimestamp(0) - datetime.utcfromtimestamp(0)
else:
tzAdjust = timedelta(hours=tzvar)
trueTime2 = 0

header = ('Date', 'Time', 'O', 'H', 'L', 'C', 'V', 'T')
ftsv = open(fileoutput, 'w')
fileout = csv.writer(ftsv, delimiter='\t')
with open(filename, 'rb') as fscid:
fscid.read(sizeHeader) # discard header
fileout.writerow(header)
for i in xrange(300000):
data = fscid.read(sizeRecord)
if data != "":
dataRow = struct.unpack('d4f4I', data)
adjustedTime = d[0] + tzAdjust.seconds/86400.0
outrow = (str(adjustedTime), str(adjustedTime),
str(dataRow[1]), str(dataRow[2]), str(dataRow[3]),
str(dataRow[4]), str(dataRow[5]), str(dataRow[6]))
fileout.writerow(outrow)
else:
break
return


if __name__ == '__main__':
"""
Takes a SierraChart scid file (input argument 1) and converts
it to a tab separated file (tsv)
Timezone conversion can follow the users local timezone, or a
specified integer (input l or an integer but if the default
filename is being used, "" must be specified for the filename)
"""
filename = '/home/john/zRamdisk/SierraChart/Data/HSI-201303-HKFE-TD.scid'
tzvar = 0
if len(sys.argv) > 1:
if len(sys.argv[1]):
filename = sys.argv[1]
if len(sys.argv) > 2 and len(sys.argv[2]):
print sys.argv[2], type(sys.argv[2])
if sys.argv[2] == 'l':
tzvar = 99999
print tzvar, type(tzvar)
else:
tzvar = float(sys.argv[2])
print tzvar, type(tzvar)
fileoutput = filename[:-4] + 'tsv'
getRecords(filename, fileoutput, tzvar)

Date Time Of Last Edit: 2013-04-21 03:50:55