dbn/v3/
methods.rs

1use std::os::raw::c_char;
2
3use crate::{rtype, v1, v2, RecordHeader};
4
5use super::{InstrumentDefMsg, StatMsg, UNDEF_STAT_QUANTITY};
6
7impl From<&v1::InstrumentDefMsg> for InstrumentDefMsg {
8    fn from(old: &v1::InstrumentDefMsg) -> Self {
9        let mut res = Self {
10            // recalculate length
11            hd: RecordHeader::new::<Self>(
12                rtype::INSTRUMENT_DEF,
13                old.hd.publisher_id,
14                old.hd.instrument_id,
15                old.hd.ts_event,
16            ),
17            ts_recv: old.ts_recv,
18            min_price_increment: old.min_price_increment,
19            display_factor: old.display_factor,
20            expiration: old.expiration,
21            activation: old.activation,
22            high_limit_price: old.high_limit_price,
23            low_limit_price: old.low_limit_price,
24            max_price_variation: old.max_price_variation,
25            unit_of_measure_qty: old.unit_of_measure_qty,
26            min_price_increment_amount: old.min_price_increment_amount,
27            price_ratio: old.price_ratio,
28            inst_attrib_value: old.inst_attrib_value,
29            underlying_id: old.underlying_id,
30            raw_instrument_id: u64::from(old.raw_instrument_id),
31            market_depth_implied: old.market_depth_implied,
32            market_depth: old.market_depth,
33            market_segment_id: old.market_segment_id,
34            max_trade_vol: old.max_trade_vol,
35            min_lot_size: old.min_lot_size,
36            min_lot_size_block: old.min_lot_size_block,
37            min_lot_size_round_lot: old.min_lot_size_round_lot,
38            min_trade_vol: old.min_trade_vol,
39            contract_multiplier: old.contract_multiplier,
40            decay_quantity: old.decay_quantity,
41            original_contract_size: old.original_contract_size,
42            appl_id: old.appl_id,
43            maturity_year: old.maturity_year,
44            decay_start_date: old.decay_start_date,
45            channel_id: old.channel_id,
46            currency: old.currency,
47            settl_currency: old.settl_currency,
48            secsubtype: old.secsubtype,
49            group: old.group,
50            exchange: old.exchange,
51            cfi: old.cfi,
52            security_type: old.security_type,
53            unit_of_measure: old.unit_of_measure,
54            underlying: old.underlying,
55            strike_price_currency: old.strike_price_currency,
56            instrument_class: old.instrument_class,
57            strike_price: old.strike_price,
58            match_algorithm: old.match_algorithm,
59            main_fraction: old.main_fraction,
60            price_display_format: old.price_display_format,
61            sub_fraction: old.sub_fraction,
62            underlying_product: old.underlying_product,
63            security_update_action: old.security_update_action as c_char,
64            maturity_month: old.maturity_month,
65            maturity_day: old.maturity_day,
66            maturity_week: old.maturity_week,
67            user_defined_instrument: old.user_defined_instrument as c_char,
68            contract_multiplier_unit: old.contract_multiplier_unit,
69            flow_schedule_type: old.flow_schedule_type,
70            tick_rule: old.tick_rule,
71            ..Default::default()
72        };
73        res.asset[..v1::ASSET_CSTR_LEN].copy_from_slice(old.asset.as_slice());
74        res.raw_symbol[..v1::SYMBOL_CSTR_LEN].copy_from_slice(old.raw_symbol.as_slice());
75        res
76    }
77}
78
79impl From<&v2::InstrumentDefMsg> for InstrumentDefMsg {
80    fn from(old: &v2::InstrumentDefMsg) -> Self {
81        let mut res = Self {
82            // recalculate length
83            hd: RecordHeader::new::<Self>(
84                rtype::INSTRUMENT_DEF,
85                old.hd.publisher_id,
86                old.hd.instrument_id,
87                old.hd.ts_event,
88            ),
89            ts_recv: old.ts_recv,
90            min_price_increment: old.min_price_increment,
91            display_factor: old.display_factor,
92            expiration: old.expiration,
93            activation: old.activation,
94            high_limit_price: old.high_limit_price,
95            low_limit_price: old.low_limit_price,
96            max_price_variation: old.max_price_variation,
97            unit_of_measure_qty: old.unit_of_measure_qty,
98            min_price_increment_amount: old.min_price_increment_amount,
99            price_ratio: old.price_ratio,
100            inst_attrib_value: old.inst_attrib_value,
101            underlying_id: old.underlying_id,
102            raw_instrument_id: u64::from(old.raw_instrument_id),
103            market_depth_implied: old.market_depth_implied,
104            market_depth: old.market_depth,
105            market_segment_id: old.market_segment_id,
106            max_trade_vol: old.max_trade_vol,
107            min_lot_size: old.min_lot_size,
108            min_lot_size_block: old.min_lot_size_block,
109            min_lot_size_round_lot: old.min_lot_size_round_lot,
110            min_trade_vol: old.min_trade_vol,
111            contract_multiplier: old.contract_multiplier,
112            decay_quantity: old.decay_quantity,
113            original_contract_size: old.original_contract_size,
114            appl_id: old.appl_id,
115            maturity_year: old.maturity_year,
116            decay_start_date: old.decay_start_date,
117            channel_id: old.channel_id,
118            currency: old.currency,
119            settl_currency: old.settl_currency,
120            secsubtype: old.secsubtype,
121            group: old.group,
122            exchange: old.exchange,
123            cfi: old.cfi,
124            security_type: old.security_type,
125            unit_of_measure: old.unit_of_measure,
126            underlying: old.underlying,
127            strike_price_currency: old.strike_price_currency,
128            instrument_class: old.instrument_class,
129            strike_price: old.strike_price,
130            match_algorithm: old.match_algorithm,
131            main_fraction: old.main_fraction,
132            price_display_format: old.price_display_format,
133            sub_fraction: old.sub_fraction,
134            underlying_product: old.underlying_product,
135            security_update_action: old.security_update_action as c_char,
136            maturity_month: old.maturity_month,
137            maturity_day: old.maturity_day,
138            maturity_week: old.maturity_week,
139            user_defined_instrument: old.user_defined_instrument as c_char,
140            contract_multiplier_unit: old.contract_multiplier_unit,
141            flow_schedule_type: old.flow_schedule_type,
142            tick_rule: old.tick_rule,
143            raw_symbol: old.raw_symbol,
144            ..Default::default()
145        };
146        res.asset[..v2::ASSET_CSTR_LEN].copy_from_slice(old.asset.as_slice());
147        res
148    }
149}
150
151impl From<&v1::StatMsg> for StatMsg {
152    fn from(old: &v1::StatMsg) -> Self {
153        Self {
154            // recalculate length
155            hd: RecordHeader::new::<Self>(
156                rtype::STATISTICS,
157                old.hd.publisher_id,
158                old.hd.instrument_id,
159                old.hd.ts_event,
160            ),
161            ts_recv: old.ts_recv,
162            ts_ref: old.ts_ref,
163            price: old.price,
164            quantity: if old.quantity == v1::UNDEF_STAT_QUANTITY {
165                UNDEF_STAT_QUANTITY
166            } else {
167                old.quantity as i64
168            },
169            sequence: old.sequence,
170            ts_in_delta: old.ts_in_delta,
171            stat_type: old.stat_type,
172            channel_id: old.channel_id,
173            update_action: old.update_action,
174            stat_flags: old.stat_flags,
175            _reserved: Default::default(),
176        }
177    }
178}