File tree 1 file changed +5
-26
lines changed
py-hftbacktest/hftbacktest/data/utils
1 file changed +5
-26
lines changed Original file line number Diff line number Diff line change 18
18
event_dtype
19
19
)
20
20
21
- trade_cols = [
22
- 'exchange' ,
23
- 'symbol' ,
24
- 'timestamp' ,
25
- 'local_timestamp' ,
26
- 'id' ,
27
- 'side' ,
28
- 'price' ,
29
- 'amount'
30
- ]
31
-
32
- depth_cols = [
33
- 'exchange' ,
34
- 'symbol' ,
35
- 'timestamp' ,
36
- 'local_timestamp' ,
37
- 'is_snapshot' ,
38
- 'side' ,
39
- 'price' ,
40
- 'amount'
41
- ]
42
21
43
22
trade_schema = {
44
23
'exchange' : pl .String ,
45
24
'symbol' : pl .String ,
46
25
'timestamp' : pl .Int64 ,
47
26
'local_timestamp' : pl .Int64 ,
48
- 'id' : pl .UInt64 ,
27
+ 'id' : pl .String ,
49
28
'side' : pl .String ,
50
29
'price' : pl .Float64 ,
51
30
'amount' : pl .Float64 ,
@@ -125,16 +104,16 @@ def convert(
125
104
with open (file ) as f :
126
105
line = f .readline ()
127
106
header = line .strip ().split (',' )
128
- if header == trade_cols :
107
+ if header == list ( trade_schema . keys ()) :
129
108
schema = trade_schema
130
- elif header == depth_cols :
109
+ elif header == list ( depth_schema . keys ()) :
131
110
schema = depth_schema
132
111
except :
133
112
# Fails to infer the file type; let Polars infer the schema.
134
113
pass
135
114
136
115
df = pl .read_csv (file , schema = schema )
137
- if df .columns == trade_cols :
116
+ if df .columns == list ( trade_schema . keys ()) :
138
117
arr = (
139
118
df .with_columns (
140
119
pl .when (pl .col ('side' ) == 'buy' )
@@ -171,7 +150,7 @@ def convert(
171
150
)
172
151
tmp [row_num :row_num + len (arr )] = arr [:]
173
152
row_num += len (arr )
174
- elif df .columns == depth_cols :
153
+ elif df .columns == list ( depth_schema . keys ()) :
175
154
arr = (
176
155
df .with_columns (
177
156
(pl .col ('timestamp' ) * 1000 )
You can’t perform that action at this time.
0 commit comments