@@ -44,8 +44,20 @@ def get_deriv_ba_types(level: int) -> List[Tuple[str, Union[type, str]]]:
4444 ("ts_event" , np .uint64 ),
4545]
4646
47+ MBO_MSG : List [Tuple [str , Union [type , str ]]] = RECORD_HEADER + [
48+ ("order_id" , np .uint64 ),
49+ ("price" , np .int64 ),
50+ ("size" , np .uint32 ),
51+ ("flags" , np .int8 ),
52+ ("channel_id" , np .uint8 ),
53+ ("action" , "S1" ), # 1 byte chararray
54+ ("side" , "S1" ), # 1 byte chararray
55+ ("ts_recv" , np .uint64 ),
56+ ("ts_in_delta" , np .int32 ),
57+ ("sequence" , np .uint32 ),
58+ ]
4759
48- MBP_MSG : List [Tuple [str , Union [type , str ]]] = [
60+ MBP_MSG : List [Tuple [str , Union [type , str ]]] = RECORD_HEADER + [
4961 ("price" , np .int64 ),
5062 ("size" , np .uint32 ),
5163 ("action" , "S1" ), # 1 byte chararray
@@ -58,32 +70,91 @@ def get_deriv_ba_types(level: int) -> List[Tuple[str, Union[type, str]]]:
5870]
5971
6072
61- OHLCV_MSG : List [Tuple [str , Union [type , str ]]] = [
73+ OHLCV_MSG : List [Tuple [str , Union [type , str ]]] = RECORD_HEADER + [
6274 ("open" , np .int64 ),
6375 ("high" , np .int64 ),
6476 ("low" , np .int64 ),
6577 ("close" , np .int64 ),
6678 ("volume" , np .int64 ),
6779]
6880
81+ STATUS_MSG : List [Tuple [str , Union [type , str ]]] = RECORD_HEADER + [
82+ ("ts_recv" , np .uint64 ),
83+ ("group" , "S1" ), # 1 byte chararray
84+ ("trading_status" , np .uint8 ),
85+ ("halt_reason" , np .uint8 ),
86+ ("trading_event" , np .uint8 ),
87+ ]
88+
89+ DEFINITION_MSG : List [Tuple [str , Union [type , str ]]] = RECORD_HEADER + [
90+ ("ts_recv" , np .uint64 ),
91+ ("min_price_increment" , np .int64 ),
92+ ("display_factor" , np .int64 ),
93+ ("expiration" , np .uint64 ),
94+ ("activation" , np .uint64 ),
95+ ("high_limit_price" , np .int64 ),
96+ ("low_limit_price" , np .int64 ),
97+ ("max_price_variation" , np .int64 ),
98+ ("trading_reference_price" , np .int64 ),
99+ ("unit_of_measure_qty" , np .int64 ),
100+ ("min_price_increment_amount" , np .int64 ),
101+ ("price_ratio" , np .int64 ),
102+ ("inst_attrib_value" , np .int32 ),
103+ ("underlying_id" , np .uint32 ),
104+ ("cleared_volume" , np .int32 ),
105+ ("market_depth_implied" , np .int32 ),
106+ ("market_depth" , np .int32 ),
107+ ("market_segment_id" , np .uint32 ),
108+ ("max_trade_vol" , np .uint32 ),
109+ ("min_lot_size" , np .int32 ),
110+ ("min_lot_size_block" , np .int32 ),
111+ ("min_lot_size_round_lot" , np .int32 ),
112+ ("min_trade_vol" , np .uint32 ),
113+ ("open_interest_qty" , np .int32 ),
114+ ("contract_multiplier" , np .int32 ),
115+ ("decay_quantity" , np .int32 ),
116+ ("original_contract_size" , np .int32 ),
117+ ("related_security_id" , np .uint32 ),
118+ ("trading_reference_date" , np .uint16 ),
119+ ("appl_id" , np .int16 ),
120+ ("maturity_year" , np .uint16 ),
121+ ("decay_start_date" , np .uint16 ),
122+ ("channel_id" , np .uint16 ),
123+ ("currency" , "S4" ), # 4 byte chararray
124+ ("settl_currency" , "S4" ), # 4 byte chararray
125+ ("secsubtype" , "S6" ), # 6 byte chararray
126+ ("symbol" , "S22" ), # 22 byte chararray
127+ ("group" , "S21" ), # 21 byte chararray
128+ ("exchange" , "S5" ), # 5 byte chararray
129+ ("asset" , "S7" ), # 7 byte chararray
130+ ("cfi" , "S7" ), # 7 byte chararray
131+ ("security_type" , "S7" ), # 7 byte chararray
132+ ("unit_of_measure" , "S31" ), # 31 byte chararray
133+ ("underlying" , "S21" ), # 21 byte chararray
134+ ("related" , "S21" ), # 21 byte chararray
135+ ("match_algorithm" , "S1" ), # 1 byte chararray
136+ ("md_security_trading_status" , np .uint8 ),
137+ ("main_fraction" , np .uint8 ),
138+ ("price_display_format" , np .uint8 ),
139+ ("settl_price_type" , np .uint8 ),
140+ ("sub_fraction" , np .uint8 ),
141+ ("underlying_product" , np .uint8 ),
142+ ("security_update_action" , "S1" ), # 1 byte chararray
143+ ("maturity_month" , np .uint8 ),
144+ ("maturity_day" , np .uint8 ),
145+ ("maturity_week" , np .uint8 ),
146+ ("user_defined_instrument" , "S1" ), # 1 byte chararray
147+ ("contract_multiplier_unit" , np .int8 ),
148+ ("flow_schedule_type" , np .int8 ),
149+ ("tick_rule" , np .uint8 ),
150+ ("dummy" , "S3" ), # 3 byte chararray (Adjustment filler for 8-bytes alignment)
151+ ]
152+
69153
70154STRUCT_MAP : Dict [Schema , List [Tuple [str , Union [type , str ]]]] = {
71- Schema .MBO : RECORD_HEADER
72- + [
73- ("order_id" , np .uint64 ),
74- ("price" , np .int64 ),
75- ("size" , np .uint32 ),
76- ("flags" , np .int8 ),
77- ("channel_id" , np .uint8 ),
78- ("action" , "S1" ), # 1 byte chararray
79- ("side" , "S1" ), # 1 byte chararray
80- ("ts_recv" , np .uint64 ),
81- ("ts_in_delta" , np .int32 ),
82- ("sequence" , np .uint32 ),
83- ],
84- Schema .MBP_1 : RECORD_HEADER + MBP_MSG + get_deriv_ba_types (0 ), # 1
85- Schema .MBP_10 : RECORD_HEADER
86- + MBP_MSG
155+ Schema .MBO : MBO_MSG ,
156+ Schema .MBP_1 : MBP_MSG + get_deriv_ba_types (0 ), # 1
157+ Schema .MBP_10 : MBP_MSG
87158 + get_deriv_ba_types (0 ) # 1
88159 + get_deriv_ba_types (1 ) # 2
89160 + get_deriv_ba_types (2 ) # 3
@@ -94,84 +165,14 @@ def get_deriv_ba_types(level: int) -> List[Tuple[str, Union[type, str]]]:
94165 + get_deriv_ba_types (7 ) # 8
95166 + get_deriv_ba_types (8 ) # 9
96167 + get_deriv_ba_types (9 ), # 10
97- Schema .TBBO : RECORD_HEADER + MBP_MSG + get_deriv_ba_types (0 ),
98- Schema .TRADES : RECORD_HEADER + MBP_MSG ,
99- Schema .OHLCV_1S : RECORD_HEADER + OHLCV_MSG ,
100- Schema .OHLCV_1M : RECORD_HEADER + OHLCV_MSG ,
101- Schema .OHLCV_1H : RECORD_HEADER + OHLCV_MSG ,
102- Schema .OHLCV_1D : RECORD_HEADER + OHLCV_MSG ,
103- Schema .STATUS : RECORD_HEADER
104- + [
105- ("ts_recv" , np .uint64 ),
106- ("group" , "S1" ), # 1 byte chararray
107- ("trading_status" , np .uint8 ),
108- ("halt_reason" , np .uint8 ),
109- ("trading_event" , np .uint8 ),
110- ],
111- Schema .DEFINITION : RECORD_HEADER
112- + [
113- ("ts_recv" , np .uint64 ),
114- ("min_price_increment" , np .int64 ),
115- ("display_factor" , np .int64 ),
116- ("expiration" , np .uint64 ),
117- ("activation" , np .uint64 ),
118- ("high_limit_price" , np .int64 ),
119- ("low_limit_price" , np .int64 ),
120- ("max_price_variation" , np .int64 ),
121- ("trading_reference_price" , np .int64 ),
122- ("unit_of_measure_qty" , np .int64 ),
123- ("min_price_increment_amount" , np .int64 ),
124- ("price_ratio" , np .int64 ),
125- ("inst_attrib_value" , np .int32 ),
126- ("underlying_id" , np .uint32 ),
127- ("cleared_volume" , np .int32 ),
128- ("market_depth_implied" , np .int32 ),
129- ("market_depth" , np .int32 ),
130- ("market_segment_id" , np .uint32 ),
131- ("max_trade_vol" , np .uint32 ),
132- ("min_lot_size" , np .int32 ),
133- ("min_lot_size_block" , np .int32 ),
134- ("min_lot_size_round_lot" , np .int32 ),
135- ("min_trade_vol" , np .uint32 ),
136- ("open_interest_qty" , np .int32 ),
137- ("contract_multiplier" , np .int32 ),
138- ("decay_quantity" , np .int32 ),
139- ("original_contract_size" , np .int32 ),
140- ("related_security_id" , np .uint32 ),
141- ("trading_reference_date" , np .uint16 ),
142- ("appl_id" , np .int16 ),
143- ("maturity_year" , np .uint16 ),
144- ("decay_start_date" , np .uint16 ),
145- ("channel_id" , np .uint16 ),
146- ("currency" , "S4" ), # 4 byte chararray
147- ("settl_currency" , "S4" ), # 4 byte chararray
148- ("secsubtype" , "S6" ), # 6 byte chararray
149- ("symbol" , "S22" ), # 22 byte chararray
150- ("group" , "S21" ), # 21 byte chararray
151- ("exchange" , "S5" ), # 5 byte chararray
152- ("asset" , "S7" ), # 7 byte chararray
153- ("cfi" , "S7" ), # 7 byte chararray
154- ("security_type" , "S7" ), # 7 byte chararray
155- ("unit_of_measure" , "S31" ), # 31 byte chararray
156- ("underlying" , "S21" ), # 21 byte chararray
157- ("related" , "S21" ), # 21 byte chararray
158- ("match_algorithm" , "S1" ), # 1 byte chararray
159- ("md_security_trading_status" , np .uint8 ),
160- ("main_fraction" , np .uint8 ),
161- ("price_display_format" , np .uint8 ),
162- ("settl_price_type" , np .uint8 ),
163- ("sub_fraction" , np .uint8 ),
164- ("underlying_product" , np .uint8 ),
165- ("security_update_action" , "S1" ), # 1 byte chararray
166- ("maturity_month" , np .uint8 ),
167- ("maturity_day" , np .uint8 ),
168- ("maturity_week" , np .uint8 ),
169- ("user_defined_instrument" , "S1" ), # 1 byte chararray
170- ("contract_multiplier_unit" , np .int8 ),
171- ("flow_schedule_type" , np .int8 ),
172- ("tick_rule" , np .uint8 ),
173- ("dummy" , "S3" ), # 3 byte chararray (Adjustment filler for 8-bytes alignment)
174- ],
168+ Schema .TBBO : MBP_MSG + get_deriv_ba_types (0 ),
169+ Schema .TRADES : MBP_MSG ,
170+ Schema .OHLCV_1S : OHLCV_MSG ,
171+ Schema .OHLCV_1M : OHLCV_MSG ,
172+ Schema .OHLCV_1H : OHLCV_MSG ,
173+ Schema .OHLCV_1D : OHLCV_MSG ,
174+ Schema .STATUS : STATUS_MSG ,
175+ Schema .DEFINITION : DEFINITION_MSG ,
175176 Schema .GATEWAY_ERROR : RECORD_HEADER
176177 + [
177178 ("error" , "S64" ),
@@ -236,7 +237,7 @@ def get_deriv_ba_fields(level: int) -> List[str]:
236237 ]
237238
238239
239- DERIV_HEADER_FIELDS = [
240+ DERIV_HEADER_COLUMNS = [
240241 "ts_event" ,
241242 "ts_in_delta" ,
242243 "publisher_id" ,
@@ -250,6 +251,23 @@ def get_deriv_ba_fields(level: int) -> List[str]:
250251 "sequence" ,
251252]
252253
254+ OHLCV_HEADER_COLUMNS = [
255+ "publisher_id" ,
256+ "product_id" ,
257+ "open" ,
258+ "high" ,
259+ "low" ,
260+ "close" ,
261+ "volume" ,
262+ ]
263+
264+ STATUS_COLUMNS = [x for x in np .dtype (STATUS_MSG ).names or ()]
265+ STATUS_COLUMNS .remove ("ts_recv" ) # Index
266+
267+ DEFINITION_COLUMNS = [x for x in np .dtype (DEFINITION_MSG ).names or ()]
268+ DEFINITION_COLUMNS .remove ("ts_recv" ) # Index
269+
270+
253271COLUMNS = {
254272 Schema .MBO : [
255273 "ts_event" ,
@@ -265,8 +283,8 @@ def get_deriv_ba_fields(level: int) -> List[str]:
265283 "size" ,
266284 "sequence" ,
267285 ],
268- Schema .MBP_1 : DERIV_HEADER_FIELDS + get_deriv_ba_fields (0 ),
269- Schema .MBP_10 : DERIV_HEADER_FIELDS
286+ Schema .MBP_1 : DERIV_HEADER_COLUMNS + get_deriv_ba_fields (0 ),
287+ Schema .MBP_10 : DERIV_HEADER_COLUMNS
270288 + get_deriv_ba_fields (0 )
271289 + get_deriv_ba_fields (1 )
272290 + get_deriv_ba_fields (2 )
@@ -277,6 +295,12 @@ def get_deriv_ba_fields(level: int) -> List[str]:
277295 + get_deriv_ba_fields (7 )
278296 + get_deriv_ba_fields (8 )
279297 + get_deriv_ba_fields (9 ),
280- Schema .TBBO : DERIV_HEADER_FIELDS + get_deriv_ba_fields (0 ),
281- Schema .TRADES : DERIV_HEADER_FIELDS ,
298+ Schema .TBBO : DERIV_HEADER_COLUMNS + get_deriv_ba_fields (0 ),
299+ Schema .TRADES : DERIV_HEADER_COLUMNS ,
300+ Schema .OHLCV_1S : OHLCV_HEADER_COLUMNS ,
301+ Schema .OHLCV_1M : OHLCV_HEADER_COLUMNS ,
302+ Schema .OHLCV_1H : OHLCV_HEADER_COLUMNS ,
303+ Schema .OHLCV_1D : OHLCV_HEADER_COLUMNS ,
304+ Schema .STATUS : STATUS_COLUMNS ,
305+ Schema .DEFINITION : DEFINITION_COLUMNS ,
282306}
0 commit comments