1use std::ffi::c_char;
2
3use crate::{
4 ErrorCode, Schema, StatusAction, StatusReason, SystemCode, TradingEvent, TriState,
5 UNDEF_ORDER_SIZE, UNDEF_PRICE, UNDEF_STAT_QUANTITY, UNDEF_TIMESTAMP,
6};
7
8use super::*;
9
10impl RecordHeader {
11 pub const fn default<R: HasRType>(rtype: u8) -> Self {
14 Self::new::<R>(rtype, 0, 0, UNDEF_TIMESTAMP)
15 }
16}
17
18impl Default for MboMsg {
19 fn default() -> Self {
20 Self {
21 hd: RecordHeader::default::<Self>(rtype::MBO),
22 order_id: 0,
23 price: UNDEF_PRICE,
24 size: UNDEF_ORDER_SIZE,
25 flags: Default::default(),
26 channel_id: u8::MAX,
27 action: Action::default() as c_char,
28 side: Side::default() as c_char,
29 ts_recv: UNDEF_TIMESTAMP,
30 ts_in_delta: 0,
31 sequence: 0,
32 }
33 }
34}
35
36impl Default for BidAskPair {
37 fn default() -> Self {
38 Self {
39 bid_px: UNDEF_PRICE,
40 ask_px: UNDEF_PRICE,
41 bid_sz: 0,
42 ask_sz: 0,
43 bid_ct: 0,
44 ask_ct: 0,
45 }
46 }
47}
48
49impl Default for ConsolidatedBidAskPair {
50 fn default() -> Self {
51 Self {
52 bid_px: UNDEF_PRICE,
53 ask_px: UNDEF_PRICE,
54 bid_sz: 0,
55 ask_sz: 0,
56 bid_pb: 0,
57 _reserved1: Default::default(),
58 ask_pb: 0,
59 _reserved2: Default::default(),
60 }
61 }
62}
63
64impl Default for TradeMsg {
65 fn default() -> Self {
66 Self {
67 hd: RecordHeader::default::<Self>(rtype::MBP_0),
68 price: UNDEF_PRICE,
69 size: UNDEF_ORDER_SIZE,
70 action: Action::default() as c_char,
71 side: Side::default() as c_char,
72 flags: Default::default(),
73 depth: 0,
74 ts_recv: UNDEF_TIMESTAMP,
75 ts_in_delta: 0,
76 sequence: 0,
77 }
78 }
79}
80
81impl Default for Mbp1Msg {
82 fn default() -> Self {
83 Self {
84 hd: RecordHeader::default::<Self>(rtype::MBP_1),
85 price: UNDEF_PRICE,
86 size: UNDEF_ORDER_SIZE,
87 action: Action::default() as c_char,
88 side: Side::default() as c_char,
89 flags: Default::default(),
90 depth: 0,
91 ts_recv: UNDEF_TIMESTAMP,
92 ts_in_delta: 0,
93 sequence: 0,
94 levels: Default::default(),
95 }
96 }
97}
98
99impl Default for Mbp10Msg {
100 fn default() -> Self {
101 Self {
102 hd: RecordHeader::default::<Self>(rtype::MBP_10),
103 price: UNDEF_PRICE,
104 size: UNDEF_ORDER_SIZE,
105 action: Action::default() as c_char,
106 side: Side::default() as c_char,
107 flags: Default::default(),
108 depth: 0,
109 ts_recv: UNDEF_TIMESTAMP,
110 ts_in_delta: 0,
111 sequence: 0,
112 levels: Default::default(),
113 }
114 }
115}
116
117impl BboMsg {
118 pub fn default_for_schema(schema: Schema) -> Self {
120 Self {
121 hd: RecordHeader::default::<Self>(RType::from(schema) as u8),
122 price: UNDEF_PRICE,
123 size: UNDEF_ORDER_SIZE,
124 _reserved1: 0,
125 side: Side::default() as c_char,
126 flags: Default::default(),
127 _reserved2: 0,
128 ts_recv: UNDEF_TIMESTAMP,
129 _reserved3: Default::default(),
130 sequence: 0,
131 levels: Default::default(),
132 }
133 }
134}
135
136impl Cmbp1Msg {
137 pub fn default_for_schema(schema: Schema) -> Self {
139 Self {
140 hd: RecordHeader::default::<Self>(RType::from(schema) as u8),
141 price: UNDEF_PRICE,
142 size: UNDEF_ORDER_SIZE,
143 action: Action::default() as c_char,
144 side: Side::default() as c_char,
145 flags: Default::default(),
146 _reserved1: Default::default(),
147 ts_recv: UNDEF_TIMESTAMP,
148 ts_in_delta: 0,
149 _reserved2: Default::default(),
150 levels: Default::default(),
151 }
152 }
153}
154
155impl CbboMsg {
156 pub fn default_for_schema(schema: Schema) -> Self {
158 Self {
159 hd: RecordHeader::default::<Self>(RType::from(schema) as u8),
160 price: UNDEF_PRICE,
161 size: UNDEF_ORDER_SIZE,
162 _reserved1: 0,
163 side: Side::default() as c_char,
164 flags: Default::default(),
165 _reserved2: 0,
166 ts_recv: UNDEF_TIMESTAMP,
167 _reserved3: Default::default(),
168 levels: Default::default(),
169 }
170 }
171}
172
173impl OhlcvMsg {
174 pub fn default_for_schema(schema: Schema) -> Self {
176 Self {
177 hd: RecordHeader::default::<Self>(RType::from(schema) as u8),
178 open: UNDEF_PRICE,
179 high: UNDEF_PRICE,
180 low: UNDEF_PRICE,
181 close: UNDEF_PRICE,
182 volume: 0,
183 }
184 }
185}
186
187impl Default for StatusMsg {
188 fn default() -> Self {
189 Self {
190 hd: RecordHeader::default::<Self>(rtype::STATUS),
191 ts_recv: UNDEF_TIMESTAMP,
192 action: StatusAction::default() as u16,
193 reason: StatusReason::default() as u16,
194 trading_event: TradingEvent::default() as u16,
195 is_trading: TriState::default() as c_char,
196 is_quoting: TriState::default() as c_char,
197 is_short_sell_restricted: TriState::default() as c_char,
198 _reserved: Default::default(),
199 }
200 }
201}
202
203impl Default for InstrumentDefMsg {
204 fn default() -> Self {
205 Self {
206 hd: RecordHeader::default::<Self>(rtype::INSTRUMENT_DEF),
207 ts_recv: UNDEF_TIMESTAMP,
208 min_price_increment: UNDEF_PRICE,
209 display_factor: UNDEF_PRICE,
210 expiration: UNDEF_TIMESTAMP,
211 activation: UNDEF_TIMESTAMP,
212 high_limit_price: UNDEF_PRICE,
213 low_limit_price: UNDEF_PRICE,
214 max_price_variation: UNDEF_PRICE,
215 unit_of_measure_qty: UNDEF_PRICE,
216 min_price_increment_amount: UNDEF_PRICE,
217 price_ratio: UNDEF_PRICE,
218 strike_price: UNDEF_PRICE,
219 raw_instrument_id: 0,
220 leg_price: UNDEF_PRICE,
221 leg_delta: UNDEF_PRICE,
222 inst_attrib_value: i32::MAX,
223 underlying_id: 0,
224 market_depth_implied: i32::MAX,
225 market_depth: i32::MAX,
226 market_segment_id: u32::MAX,
227 max_trade_vol: u32::MAX,
228 min_lot_size: i32::MAX,
229 min_lot_size_block: i32::MAX,
230 min_lot_size_round_lot: i32::MAX,
231 min_trade_vol: u32::MAX,
232 contract_multiplier: i32::MAX,
233 decay_quantity: i32::MAX,
234 original_contract_size: i32::MAX,
235 leg_instrument_id: 0,
236 leg_ratio_price_numerator: 0,
237 leg_ratio_price_denominator: 0,
238 leg_ratio_qty_numerator: 0,
239 leg_ratio_qty_denominator: 0,
240 leg_underlying_id: 0,
241 appl_id: i16::MAX,
242 maturity_year: u16::MAX,
243 decay_start_date: u16::MAX,
244 channel_id: u16::MAX,
245 leg_count: 0,
246 leg_index: 0,
247 currency: [0; 4],
248 settl_currency: [0; 4],
249 secsubtype: [0; 6],
250 raw_symbol: [0; SYMBOL_CSTR_LEN],
251 group: [0; 21],
252 exchange: [0; 5],
253 asset: [0; ASSET_CSTR_LEN],
254 cfi: [0; 7],
255 security_type: [0; 7],
256 unit_of_measure: [0; 31],
257 underlying: [0; 21],
258 strike_price_currency: [0; 4],
259 leg_raw_symbol: [0; SYMBOL_CSTR_LEN],
260 instrument_class: 0,
261 match_algorithm: MatchAlgorithm::default() as c_char,
262 main_fraction: u8::MAX,
263 price_display_format: u8::MAX,
264 sub_fraction: u8::MAX,
265 underlying_product: u8::MAX,
266 security_update_action: SecurityUpdateAction::default() as c_char,
267 maturity_month: u8::MAX,
268 maturity_day: u8::MAX,
269 maturity_week: u8::MAX,
270 user_defined_instrument: UserDefinedInstrument::default() as c_char,
271 contract_multiplier_unit: i8::MAX,
272 flow_schedule_type: i8::MAX,
273 tick_rule: u8::MAX,
274 leg_instrument_class: 0,
275 leg_side: Side::default() as c_char,
276 _reserved: Default::default(),
277 }
278 }
279}
280
281impl Default for ImbalanceMsg {
282 fn default() -> Self {
283 Self {
284 hd: RecordHeader::default::<Self>(rtype::IMBALANCE),
285 ts_recv: UNDEF_TIMESTAMP,
286 ref_price: UNDEF_PRICE,
287 auction_time: UNDEF_TIMESTAMP,
288 cont_book_clr_price: UNDEF_PRICE,
289 auct_interest_clr_price: UNDEF_PRICE,
290 ssr_filling_price: UNDEF_PRICE,
291 ind_match_price: UNDEF_PRICE,
292 upper_collar: UNDEF_PRICE,
293 lower_collar: UNDEF_PRICE,
294 paired_qty: UNDEF_ORDER_SIZE,
295 total_imbalance_qty: UNDEF_ORDER_SIZE,
296 market_imbalance_qty: UNDEF_ORDER_SIZE,
297 unpaired_qty: UNDEF_ORDER_SIZE,
298 auction_type: b'~' as c_char,
299 side: Side::default() as c_char,
300 auction_status: 0,
301 freeze_status: 0,
302 num_extensions: 0,
303 unpaired_side: Side::default() as c_char,
304 significant_imbalance: b'~' as c_char,
305 _reserved: Default::default(),
306 }
307 }
308}
309
310impl Default for StatMsg {
311 fn default() -> Self {
312 Self {
313 hd: RecordHeader::default::<Self>(rtype::STATISTICS),
314 ts_recv: UNDEF_TIMESTAMP,
315 ts_ref: UNDEF_TIMESTAMP,
316 price: UNDEF_PRICE,
317 quantity: UNDEF_STAT_QUANTITY,
318 sequence: 0,
319 ts_in_delta: 0,
320 stat_type: 0,
321 channel_id: u16::MAX,
322 update_action: StatUpdateAction::default() as u8,
323 stat_flags: 0,
324 _reserved: Default::default(),
325 }
326 }
327}
328
329impl Default for ErrorMsg {
330 fn default() -> Self {
331 Self {
332 hd: RecordHeader::default::<Self>(rtype::ERROR),
333 err: [0; 302],
334 code: ErrorCode::default() as u8,
335 is_last: u8::MAX,
336 }
337 }
338}
339
340impl Default for SymbolMappingMsg {
341 fn default() -> Self {
342 Self {
343 hd: RecordHeader::default::<Self>(rtype::SYMBOL_MAPPING),
344 stype_in: u8::MAX,
345 stype_in_symbol: [0; SYMBOL_CSTR_LEN],
346 stype_out: u8::MAX,
347 stype_out_symbol: [0; SYMBOL_CSTR_LEN],
348 start_ts: UNDEF_TIMESTAMP,
349 end_ts: UNDEF_TIMESTAMP,
350 }
351 }
352}
353
354impl Default for SystemMsg {
355 fn default() -> Self {
356 Self {
357 hd: RecordHeader::default::<Self>(rtype::SYSTEM),
358 msg: [0; 303],
359 code: SystemCode::default() as u8,
360 }
361 }
362}