Skip to content

Commit 8992508

Browse files
committed
Fixes NameError with unpack()
1 parent 564f3f7 commit 8992508

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

src/fx-data-convert-to-csv.py

+23-23
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def _checkFormat(self):
2929
if (len(self.content) - self.headerLength)%self.rowLength != 0:
3030
print('[ERROR] File length isn\'t valid for this kind of format!')
3131

32-
if self.version != unpack('<i', self.content[0:4])[0]:
32+
if self.version != struct.unpack('<i', self.content[0:4])[0]:
3333
print('[ERROR] Unsupported format version!')
3434
sys.exit(1)
3535

@@ -127,12 +127,12 @@ def _parse(self):
127127
for i in range(0, self.numberOfRows):
128128
base = self.headerLength + i*self.rowLength
129129
self.rows += [{'timestamp': datetime.datetime.fromtimestamp(
130-
unpack('<i', self.content[base :base + 4 ])[0], datetime.timezone.utc),
131-
'open' : unpack('<d', self.content[base + 4:base + 4 + 8])[0],
132-
'low' : unpack('<d', self.content[base + 4 + 8:base + 4 + 2*8])[0],
133-
'high' : unpack('<d', self.content[base + 4 + 2*8:base + 4 + 3*8])[0],
134-
'close' : unpack('<d', self.content[base + 4 + 3*8:base + 4 + 4*8])[0],
135-
'volume' : unpack('<d', self.content[base + 4 + 4*8:base + 4 + 5*8])[0]
130+
struct.unpack('<i', self.content[base :base + 4 ])[0], datetime.timezone.utc),
131+
'open' : struct.unpack('<d', self.content[base + 4:base + 4 + 8])[0],
132+
'low' : struct.unpack('<d', self.content[base + 4 + 8:base + 4 + 2*8])[0],
133+
'high' : struct.unpack('<d', self.content[base + 4 + 2*8:base + 4 + 3*8])[0],
134+
'close' : struct.unpack('<d', self.content[base + 4 + 3*8:base + 4 + 4*8])[0],
135+
'volume' : struct.unpack('<d', self.content[base + 4 + 4*8:base + 4 + 5*8])[0]
136136
}]
137137

138138

@@ -178,14 +178,14 @@ def _parse(self):
178178
for i in range(0, self.numberOfRows):
179179
base = self.headerLength + i*self.rowLength
180180
self.rows += [{'timestamp' : datetime.datetime.fromtimestamp(
181-
unpack('<i', self.content[base :base + 4])[0], datetime.timezone.utc),
182-
'open' : unpack('<d', self.content[base + 8:base + 2*8])[0],
183-
'high' : unpack('<d', self.content[base + 2*8:base + 3*8])[0],
184-
'low' : unpack('<d', self.content[base + 3*8:base + 4*8])[0],
185-
'close' : unpack('<d', self.content[base + 4*8:base + 5*8])[0],
186-
'volume' : unpack('<Q', self.content[base + 5*8:base + 6*8])[0],
187-
'spread' : unpack('<i', self.content[base + 6*8:base + 4 + 6*8])[0],
188-
'realVolume': unpack('<Q', self.content[base + 4 + 6*8:base + 4 + 7*8])[0]
181+
struct.unpack('<i', self.content[base :base + 4])[0], datetime.timezone.utc),
182+
'open' : struct.unpack('<d', self.content[base + 8:base + 2*8])[0],
183+
'high' : struct.unpack('<d', self.content[base + 2*8:base + 3*8])[0],
184+
'low' : struct.unpack('<d', self.content[base + 3*8:base + 4*8])[0],
185+
'close' : struct.unpack('<d', self.content[base + 4*8:base + 5*8])[0],
186+
'volume' : struct.unpack('<Q', self.content[base + 5*8:base + 6*8])[0],
187+
'spread' : struct.unpack('<i', self.content[base + 6*8:base + 4 + 6*8])[0],
188+
'realVolume': struct.unpack('<Q', self.content[base + 4 + 6*8:base + 4 + 7*8])[0]
189189
}]
190190

191191

@@ -237,15 +237,15 @@ def _parse(self):
237237
for i in range(0, self.numberOfRows):
238238
base = self.headerLength + i*self.rowLength
239239
self.rows += [{'barTimestamp' : datetime.datetime.fromtimestamp(
240-
unpack('<i', self.content[base :base + 4])[0], datetime.timezone.utc),
241-
'open' : unpack('<d', self.content[base + 8:base + 2*8])[0],
242-
'high' : unpack('<d', self.content[base + 2*8:base + 3*8])[0],
243-
'low' : unpack('<d', self.content[base + 3*8:base + 4*8])[0],
244-
'close' : unpack('<d', self.content[base + 4*8:base + 5*8])[0],
245-
'volume' : unpack('<Q', self.content[base + 5*8:base + 6*8])[0],
240+
struct.unpack('<i', self.content[base :base + 4])[0], datetime.timezone.utc),
241+
'open' : struct.unpack('<d', self.content[base + 8:base + 2*8])[0],
242+
'high' : struct.unpack('<d', self.content[base + 2*8:base + 3*8])[0],
243+
'low' : struct.unpack('<d', self.content[base + 3*8:base + 4*8])[0],
244+
'close' : struct.unpack('<d', self.content[base + 4*8:base + 5*8])[0],
245+
'volume' : struct.unpack('<Q', self.content[base + 5*8:base + 6*8])[0],
246246
'tickTimestamp': datetime.datetime.fromtimestamp(
247-
unpack('<i', self.content[base + 6*8:base + 4 + 6*8])[0], datetime.timezone.utc),
248-
'flag' : unpack('<i', self.content[base + 4 + 6*8:base + 7*8])[0]
247+
struct.unpack('<i', self.content[base + 6*8:base + 4 + 6*8])[0], datetime.timezone.utc),
248+
'flag' : struct.unpack('<i', self.content[base + 4 + 6*8:base + 7*8])[0]
249249
}]
250250

251251

0 commit comments

Comments
 (0)