Skip to content

Instantly share code, notes, and snippets.

@atkinson
Last active February 12, 2020 02:43
Show Gist options
  • Save atkinson/4ad9b3e1105fb908439ff54cf0520cdb to your computer and use it in GitHub Desktop.
Save atkinson/4ad9b3e1105fb908439ff54cf0520cdb to your computer and use it in GitHub Desktop.
Sample code to read Zorro t1, t6, t8 files using Python
from ctypes import *
import os
import json
"""
The following c structure came from the Zorro manual.
See here for the structure of other files: https://manual.zorro-project.com/history.htm
"""
ZORRO_T6_FILE_TO_READ = os.path.join('.', 'AUDJPY_2009.t6')
class ZorroT6(Structure):
"""
struct {
DATE time; // timestamp of the end of the tick in UTC, OLE date/time format (double float)
float fHigh,fLow;
float fOpen,fClose;
float fVal,fVol; // additional data, like ask-bid spread, volume etc.
}
"""
_fields_ = [('time', c_double),
('fHigh', c_float),
('fLow', c_float),
('fOpen', c_float),
('fClose', c_float),
('fVal', c_float),
('fVol', c_float)
]
with open(ZORRO_T6_FILE_TO_READ, 'rb') as file:
result = []
x = ZorroT6()
while file.readinto(x) == sizeof(x):
result.append({
'time': x.time,
'fHigh': x.fHigh,
'fLow': x.fLow,
'fOpen': x.fOpen,
'fClose': x.fClose,
'fVal': x.fVal,
'fVol': x.fVol
})
print(json.dumps(result[:6], indent=2))
"""
Sample output:
$ python ./read_zorro_history.py
[
{
"time": 40178.709027777775,
"fHigh": 83.54900360107422,
"fLow": 83.53099822998047,
"fOpen": 83.54900360107422,
"fClose": 83.53099822998047,
"fVal": 0.0,
"fVol": 19.0
},
{
"time": 40178.708333333336,
"fHigh": 83.5530014038086,
"fLow": 83.54499816894531,
"fOpen": 83.54499816894531,
"fClose": 83.5479965209961,
"fVal": 0.0,
"fVol": 28.0
},
{
"time": 40178.70763888889,
"fHigh": 83.5510025024414,
"fLow": 83.5270004272461,
"fOpen": 83.5270004272461,
"fClose": 83.54499816894531,
"fVal": 0.0,
"fVol": 41.0
},
{
"time": 40178.70694444444,
"fHigh": 83.54100036621094,
"fLow": 83.52300262451172,
"fOpen": 83.54000091552734,
"fClose": 83.52400207519531,
"fVal": 0.0,
"fVol": 16.0
},
{
"time": 40178.70625,
"fHigh": 83.54000091552734,
"fLow": 83.52400207519531,
"fOpen": 83.5270004272461,
"fClose": 83.53800201416016,
"fVal": 0.0,
"fVol": 19.0
},
{
"time": 40178.705555555556,
"fHigh": 83.53299713134766,
"fLow": 83.51499938964844,
"fOpen": 83.51899719238281,
"fClose": 83.5270004272461,
"fVal": 0.0,
"fVol": 27.0
}
]
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment