1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
use crate::{
pretty::px_to_f64,
record::{c_chars_to_str, ts_to_dt},
Error, InstrumentClass, MatchAlgorithm, SecurityUpdateAction,
};
use super::*;
impl InstrumentDefMsg {
/// Parses the capture-server-received timestamp into a datetime.
/// Returns `None` if `ts_recv` contains the sentinel for a null timestamp.
pub fn ts_recv(&self) -> Option<time::OffsetDateTime> {
ts_to_dt(self.ts_recv)
}
/// Converts the minimum constant tick to a floating point.
///
/// `UNDEF_PRICE` will be converted to NaN.
///
/// <div class="warning">
/// This may introduce floating-point error.
/// </div>
pub fn min_price_increment_f64(&self) -> f64 {
px_to_f64(self.min_price_increment)
}
/// Converts the display factor to a floating point.
///
/// `UNDEF_PRICE` will be converted to NaN.
///
/// <div class="warning">
/// This may introduce floating-point error.
/// </div>
pub fn display_factor_f64(&self) -> f64 {
px_to_f64(self.display_factor)
}
/// Parses the last eligible trade time into a datetime.
/// Returns `None` if `expiration` contains the sentinel for a null timestamp.
pub fn expiration(&self) -> Option<time::OffsetDateTime> {
ts_to_dt(self.expiration)
}
/// Parses the time of instrument activation into a datetime.
/// Returns `None` if `activation` contains the sentinel for a null timestamp.
pub fn activation(&self) -> Option<time::OffsetDateTime> {
ts_to_dt(self.activation)
}
/// Converts the high limit price to a floating point.
///
/// `UNDEF_PRICE` will be converted to NaN.
///
/// <div class="warning">
/// This may introduce floating-point error.
/// </div>
pub fn high_limit_price_f64(&self) -> f64 {
px_to_f64(self.high_limit_price)
}
/// Converts the low limit price to a floating point.
///
/// `UNDEF_PRICE` will be converted to NaN.
///
/// <div class="warning">
/// This may introduce floating-point error.
/// </div>
pub fn low_limit_price_f64(&self) -> f64 {
px_to_f64(self.low_limit_price)
}
/// Converts the differential value for price banding to a floating point.
///
/// `UNDEF_PRICE` will be converted to NaN.
///
/// <div class="warning">
/// This may introduce floating-point error.
/// </div>
pub fn max_price_variation_f64(&self) -> f64 {
px_to_f64(self.max_price_variation)
}
/// Converts the trading session settlement price to a floating point.
///
/// `UNDEF_PRICE` will be converted to NaN.
///
/// <div class="warning">
/// This may introduce floating-point error.
/// </div>
pub fn trading_reference_price_f64(&self) -> f64 {
px_to_f64(self.trading_reference_price)
}
/// Converts the contract size for each instrument to a floating point.
///
/// `UNDEF_PRICE` will be converted to NaN.
///
/// <div class="warning">
/// This may introduce floating-point error.
/// </div>
pub fn unit_of_measure_qty_f64(&self) -> f64 {
px_to_f64(self.unit_of_measure_qty)
}
/// Converts the min price increment amount to a floating point.
///
/// `UNDEF_PRICE` will be converted to NaN.
///
/// <div class="warning">
/// This may introduce floating-point error.
/// </div>
pub fn min_price_increment_amount_f64(&self) -> f64 {
px_to_f64(self.min_price_increment_amount)
}
/// Converts the price ratio to a floating point.
///
/// `UNDEF_PRICE` will be converted to NaN.
///
/// <div class="warning">
/// This may introduce floating-point error.
/// </div>
pub fn price_ratio_f64(&self) -> f64 {
px_to_f64(self.price_ratio)
}
/// Converts the strike price to a floating point.
///
/// `UNDEF_PRICE` will be converted to NaN.
///
/// <div class="warning">
/// This may introduce floating-point error.
/// </div>
pub fn strike_price_f64(&self) -> f64 {
px_to_f64(self.strike_price)
}
/// Parses the currency into a `&str`.
///
/// # Errors
/// This function returns an error if `currency` contains invalid UTF-8.
pub fn currency(&self) -> crate::Result<&str> {
c_chars_to_str(&self.currency)
}
/// Parses the currency used for settlement into a `&str`.
///
/// # Errors
/// This function returns an error if `settl_currency` contains invalid UTF-8.
pub fn settl_currency(&self) -> crate::Result<&str> {
c_chars_to_str(&self.settl_currency)
}
/// Parses the strategy type of the spread into a `&str`.
///
/// # Errors
/// This function returns an error if `secsubtype` contains invalid UTF-8.
pub fn secsubtype(&self) -> crate::Result<&str> {
c_chars_to_str(&self.secsubtype)
}
/// Parses the raw symbol into a `&str`.
///
/// # Errors
/// This function returns an error if `raw_symbol` contains invalid UTF-8.
pub fn raw_symbol(&self) -> crate::Result<&str> {
c_chars_to_str(&self.raw_symbol)
}
/// Parses the security group code into a `&str`.
///
/// # Errors
/// This function returns an error if `group` contains invalid UTF-8.
pub fn group(&self) -> crate::Result<&str> {
c_chars_to_str(&self.group)
}
/// Parses the exchange into a `&str`.
///
/// # Errors
/// This function returns an error if `exchange` contains invalid UTF-8.
pub fn exchange(&self) -> crate::Result<&str> {
c_chars_to_str(&self.exchange)
}
/// Parses the asset into a `&str`.
///
/// # Errors
/// This function returns an error if `asset` contains invalid UTF-8.
pub fn asset(&self) -> crate::Result<&str> {
c_chars_to_str(&self.asset)
}
/// Parses the CFI code into a `&str`.
///
/// # Errors
/// This function returns an error if `cfi` contains invalid UTF-8.
pub fn cfi(&self) -> crate::Result<&str> {
c_chars_to_str(&self.cfi)
}
/// Parses the security type into a `&str`.
///
/// # Errors
/// This function returns an error if `security_type` contains invalid UTF-8.
pub fn security_type(&self) -> crate::Result<&str> {
c_chars_to_str(&self.security_type)
}
/// Parses the unit of measure into a `&str`.
///
/// # Errors
/// This function returns an error if `unit_of_measure` contains invalid UTF-8.
pub fn unit_of_measure(&self) -> crate::Result<&str> {
c_chars_to_str(&self.unit_of_measure)
}
/// Parses the underlying into a `&str`.
///
/// # Errors
/// This function returns an error if `underlying` contains invalid UTF-8.
pub fn underlying(&self) -> crate::Result<&str> {
c_chars_to_str(&self.underlying)
}
/// Parses the strike price currency into a `&str`.
///
/// # Errors
/// This function returns an error if `strike_price_currency` contains invalid UTF-8.
pub fn strike_price_currency(&self) -> crate::Result<&str> {
c_chars_to_str(&self.strike_price_currency)
}
/// Parses the instrument class into an enum.
///
/// # Errors
/// This function returns an error if the `instrument_class` field does not
/// contain a valid [`InstrumentClass`].
pub fn instrument_class(&self) -> crate::Result<InstrumentClass> {
InstrumentClass::try_from(self.instrument_class as u8).map_err(|_| {
Error::conversion::<InstrumentClass>(format!("{:#04X}", self.instrument_class as u8))
})
}
/// Parses the match algorithm into an enum.
///
/// # Errors
/// This function returns an error if the `match_algorithm` field does not
/// contain a valid [`MatchAlgorithm`].
pub fn match_algorithm(&self) -> crate::Result<MatchAlgorithm> {
MatchAlgorithm::try_from(self.match_algorithm as u8).map_err(|_| {
Error::conversion::<MatchAlgorithm>(format!("{:#04X}", self.match_algorithm as u8))
})
}
/// Parses the security update action into an enum.
///
/// # Errors
/// This function returns an error if the `security_update_action` field does not
/// contain a valid [`SecurityUpdateAction`].
pub fn security_update_action(&self) -> crate::Result<SecurityUpdateAction> {
SecurityUpdateAction::try_from(self.security_update_action as u8).map_err(|_| {
Error::conversion::<SecurityUpdateAction>(format!(
"{:#04X}",
self.security_update_action as u8
))
})
}
}