Skip to content

Commit 9fce9bb

Browse files
committed
[Fix] bugs in binancehistmktdata convert
1 parent 6e867df commit 9fce9bb

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

py-hftbacktest/hftbacktest/data/utils/binancehistmktdata.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ def convert_snapshot(
120120

121121
ss_bid = ss_bid[:ss_bid_rn]
122122
ss_ask = ss_ask[:ss_ask_rn]
123-
snapshot = np.zeros(len(ss_bid) + len(ss_ask), event_dtype)
123+
snapshot = np.empty(len(ss_bid) + len(ss_ask), event_dtype)
124124

125-
snapshot += [cols for cols in sorted(ss_bid, key=lambda v: -float(v[4]))]
126-
snapshot += [cols for cols in sorted(ss_ask, key=lambda v: float(v[4]))]
125+
snapshot[:len(ss_bid)] = sorted(ss_bid, key=lambda v: -float(v[4]))
126+
snapshot[len(ss_bid):len(ss_bid)+len(ss_ask)] = sorted(ss_ask, key=lambda v: float(v[4]))
127127

128128
if output_filename is not None:
129129
np.savez(output_filename, data=snapshot)
@@ -271,7 +271,7 @@ def convert(
271271
qty = float(row[qty_col])
272272

273273
# Insert TRADE_EVENT
274-
tmp[row_num] = [
274+
tmp[row_num] = (
275275
TRADE_EVENT | (SELL_EVENT if row[side_col] else BUY_EVENT), # trade initiator's side
276276
exch_ts,
277277
local_ts,
@@ -280,7 +280,7 @@ def convert(
280280
0,
281281
0,
282282
0
283-
]
283+
)
284284
row_num += 1
285285
tmp = tmp[:row_num]
286286

0 commit comments

Comments
 (0)