63 lines
2.0 KiB
Python
63 lines
2.0 KiB
Python
# Copyright (c) 2009 Andreas Balogh
|
|
# See LICENSE for details.
|
|
|
|
''' flatex broker server '''
|
|
|
|
import getopt
|
|
import sys
|
|
import os
|
|
import re
|
|
import datetime as dt
|
|
|
|
import logging
|
|
|
|
logging.basicConfig(level=logging.DEBUG,
|
|
format='%(asctime)s.%(msecs)03d %(levelname)-8s %(message)s',
|
|
datefmt='%H:%M:%S')
|
|
|
|
LOG = logging.getLogger()
|
|
|
|
|
|
re_line = r'(\d+)-(\d+)-(\d+);(\d+):(\d+):(\d+);(\d+);(.+);(.+);(.+);(.+)'
|
|
MDF_REO = re.compile(re_line)
|
|
|
|
|
|
def dukas2ticks(ifn, odir):
|
|
ifh = open(ifn, "r")
|
|
# ofh = open(argv[2], "w")
|
|
ofh = None
|
|
tdate = None
|
|
tz = 1
|
|
for raw_line in ifh:
|
|
line = raw_line.strip('\n\r')
|
|
mobj = MDF_REO.match(line)
|
|
if mobj is None:
|
|
LOG.info('skipped [%s]', line)
|
|
continue
|
|
(dd, mm, yy, hh, mi, ss, vol, p_open, p_cls, p_low, p_high) = mobj.groups()
|
|
iyy = int(yy)
|
|
imm = int(mm)
|
|
idd = int(dd)
|
|
if tdate is None or tdate != dt.date(iyy, imm, idd):
|
|
tdate = dt.date(iyy, imm, idd)
|
|
if idd == 8:
|
|
tz = 2
|
|
if ofh is not None:
|
|
ofh.close()
|
|
ofn = '846900-%s%s%s.csv' % (yy, mm, dd)
|
|
ofp = os.path.join(odir, ofn)
|
|
ofh = open(ofp, 'w')
|
|
lhh = int(hh) + tz
|
|
print >>ofh, '%.02i:%02s:%02i,846900,LAST,%s,0.0' % (lhh, mi, 0, p_open)
|
|
print >>ofh, '%.02i:%02s:%s,846900,LAST,%s,0.0' % (lhh, mi, 15, p_low)
|
|
print >>ofh, '%.02i:%02s:%s,846900,LAST,%s,0.0' % (lhh, mi, 30, p_high)
|
|
print >>ofh, '%.02i:%02s:%s,846900,LAST,%s,0.0' % (lhh, mi, 45, p_cls)
|
|
ifh.close()
|
|
ofh.close()
|
|
# throw away first line of file (close price from previous day)
|
|
return
|
|
|
|
if __name__ == '__main__':
|
|
# dukas2ticks(r'E:\rttrd-dev-var\dukascopy\DAX 06-04 bis 09-04.csv', r'E:\rttrd-dev-var\dukascopy')
|
|
dukas2ticks(r'E:\rttrd-dev-var\dukascopy\DAX 29-03 bis 01-04.csv', r'E:\rttrd-dev-var\dukascopy')
|