nautilus_interactive_brokers/common/enums/
misc.rs1use std::fmt::Display;
17
18macro_rules! define_ib_i32_enum {
19 (
20 $(#[$meta:meta])*
21 pub enum $name:ident {
22 $(
23 $(#[$variant_meta:meta])*
24 $variant:ident = $value:expr
25 ),+ $(,)?
26 }
27 ) => {
28 $(#[$meta])*
29 #[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
30 #[cfg_attr(
31 feature = "python",
32 pyo3::pyclass(
33 module = "nautilus_trader.core.nautilus_pyo3.interactive_brokers",
34 from_py_object
35 )
36 )]
37 pub enum $name {
38 $($(#[$variant_meta])* $variant),+
39 }
40
41 impl $name {
42 #[must_use]
43 pub const fn as_i32(self) -> i32 {
44 match self {
45 $(Self::$variant => $value),+
46 }
47 }
48 }
49
50 impl From<i32> for $name {
51 fn from(value: i32) -> Self {
52 match value {
53 $($value => Self::$variant,)+
54 _ => Self::default(),
55 }
56 }
57 }
58
59 impl Display for $name {
60 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
61 write!(f, "{}", self.as_i32())
62 }
63 }
64 };
65}
66
67define_ib_i32_enum! {
68 pub enum IbOrderOrigin {
70 #[default]
71 Customer = 0,
72 Firm = 1,
73 }
74}
75
76impl IbOrderOrigin {
77 #[must_use]
78 pub fn ibapi_order_origin(self) -> ibapi::orders::OrderOrigin {
79 ibapi::orders::OrderOrigin::from(self.as_i32())
80 }
81}
82
83define_ib_i32_enum! {
84 pub enum IbShortSaleSlot {
86 #[default]
87 None = 0,
88 Broker = 1,
89 ThirdParty = 2,
90 }
91}
92
93impl IbShortSaleSlot {
94 #[must_use]
95 pub fn ibapi_short_sale_slot(self) -> ibapi::orders::ShortSaleSlot {
96 ibapi::orders::ShortSaleSlot::from(self.as_i32())
97 }
98}
99
100define_ib_i32_enum! {
101 pub enum IbVolatilityType {
103 #[default]
104 Daily = 1,
105 Annual = 2,
106 }
107}
108
109impl IbVolatilityType {
110 #[must_use]
111 pub fn ibapi_volatility_type(self) -> ibapi::orders::VolatilityType {
112 ibapi::orders::VolatilityType::from(self.as_i32())
113 }
114}
115
116define_ib_i32_enum! {
117 pub enum IbReferencePriceType {
119 #[default]
120 AverageOfNbbo = 1,
121 Nbbo = 2,
122 }
123}
124
125impl IbReferencePriceType {
126 #[must_use]
127 pub fn ibapi_reference_price_type(self) -> ibapi::orders::ReferencePriceType {
128 ibapi::orders::ReferencePriceType::from(self.as_i32())
129 }
130}
131
132define_ib_i32_enum! {
133 pub enum IbAuctionStrategy {
135 #[default]
136 Match = 1,
137 Improvement = 2,
138 Transparent = 3,
139 }
140}
141
142impl IbAuctionStrategy {
143 #[must_use]
144 pub fn ibapi_auction_strategy(self) -> ibapi::orders::AuctionStrategy {
145 ibapi::orders::AuctionStrategy::from(self.as_i32())
146 }
147}
148
149define_ib_i32_enum! {
150 pub enum IbExerciseAction {
152 #[default]
153 Exercise = 1,
154 Lapse = 2,
155 }
156}
157
158impl IbExerciseAction {
159 #[must_use]
160 pub const fn ibapi_exercise_action(self) -> ibapi::orders::ExerciseAction {
161 match self {
162 Self::Exercise => ibapi::orders::ExerciseAction::Exercise,
163 Self::Lapse => ibapi::orders::ExerciseAction::Lapse,
164 }
165 }
166}
167
168define_ib_i32_enum! {
169 pub enum IbArticleType {
171 #[default]
172 Text = 0,
173 Binary = 1,
174 }
175}
176
177impl IbArticleType {
178 #[must_use]
179 pub fn ibapi_article_type(self) -> ibapi::news::ArticleType {
180 ibapi::news::ArticleType::from(self.as_i32())
181 }
182}
183
184define_ib_i32_enum! {
185 pub enum IbAuctionType {
187 #[default]
188 Opening = 1,
189 Closing = 2,
190 Volatility = 4,
191 }
192}
193
194#[derive(Debug, Clone, Copy, PartialEq, Eq)]
195#[cfg_attr(
196 feature = "python",
197 pyo3::pyclass(
198 module = "nautilus_trader.core.nautilus_pyo3.interactive_brokers",
199 from_py_object
200 )
201)]
202pub enum IbRule80A {
203 Individual,
204 Agency,
205 AgentOtherMember,
206 IndividualPtia,
207 AgencyPtia,
208 AgentOtherMemberPtia,
209 IndividualPt,
210 AgencyPt,
211 AgentOtherMemberPt,
212}
213
214impl IbRule80A {
215 #[must_use]
216 pub const fn as_str(self) -> &'static str {
217 match self {
218 Self::Individual => "I",
219 Self::Agency => "A",
220 Self::AgentOtherMember => "W",
221 Self::IndividualPtia => "J",
222 Self::AgencyPtia => "U",
223 Self::AgentOtherMemberPtia => "M",
224 Self::IndividualPt => "K",
225 Self::AgencyPt => "Y",
226 Self::AgentOtherMemberPt => "N",
227 }
228 }
229}
230
231impl Display for IbRule80A {
232 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
233 f.write_str(self.as_str())
234 }
235}
236
237#[derive(Debug, Clone, Copy, PartialEq, Eq)]
238#[cfg_attr(
239 feature = "python",
240 pyo3::pyclass(
241 module = "nautilus_trader.core.nautilus_pyo3.interactive_brokers",
242 from_py_object
243 )
244)]
245pub enum IbOrderOpenClose {
246 Open,
247 Close,
248}
249
250impl IbOrderOpenClose {
251 #[must_use]
252 pub const fn as_str(self) -> &'static str {
253 match self {
254 Self::Open => "O",
255 Self::Close => "C",
256 }
257 }
258}
259
260impl Display for IbOrderOpenClose {
261 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
262 f.write_str(self.as_str())
263 }
264}
265
266#[derive(Debug, Clone, Copy, PartialEq, Eq)]
267#[cfg_attr(
268 feature = "python",
269 pyo3::pyclass(
270 module = "nautilus_trader.core.nautilus_pyo3.interactive_brokers",
271 from_py_object
272 )
273)]
274pub enum IbTwapStrategyType {
275 Marketable,
276 MatchingMidpoint,
277 MatchingSameSide,
278 MatchingLast,
279}
280
281impl IbTwapStrategyType {
282 #[must_use]
283 pub const fn as_str(self) -> &'static str {
284 match self {
285 Self::Marketable => "Marketable",
286 Self::MatchingMidpoint => "Matching Midpoint",
287 Self::MatchingSameSide => "Matching Same Side",
288 Self::MatchingLast => "Matching Last",
289 }
290 }
291}
292
293impl Display for IbTwapStrategyType {
294 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
295 f.write_str(self.as_str())
296 }
297}
298
299#[derive(Debug, Clone, Copy, PartialEq, Eq)]
300#[cfg_attr(
301 feature = "python",
302 pyo3::pyclass(
303 module = "nautilus_trader.core.nautilus_pyo3.interactive_brokers",
304 from_py_object
305 )
306)]
307pub enum IbRiskAversion {
308 GetDone,
309 Aggressive,
310 Neutral,
311 Passive,
312}
313
314impl IbRiskAversion {
315 #[must_use]
316 pub const fn as_str(self) -> &'static str {
317 match self {
318 Self::GetDone => "Get Done",
319 Self::Aggressive => "Aggressive",
320 Self::Neutral => "Neutral",
321 Self::Passive => "Passive",
322 }
323 }
324}
325
326impl Display for IbRiskAversion {
327 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
328 f.write_str(self.as_str())
329 }
330}
331
332#[derive(Debug, Clone, Copy, PartialEq, Eq)]
333#[cfg_attr(
334 feature = "python",
335 pyo3::pyclass(
336 module = "nautilus_trader.core.nautilus_pyo3.interactive_brokers",
337 from_py_object
338 )
339)]
340pub enum IbLegAction {
341 Buy,
342 Sell,
343}
344
345impl IbLegAction {
346 #[must_use]
347 pub const fn as_str(self) -> &'static str {
348 match self {
349 Self::Buy => "BUY",
350 Self::Sell => "SELL",
351 }
352 }
353}
354
355impl Display for IbLegAction {
356 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
357 f.write_str(self.as_str())
358 }
359}
360
361#[derive(Debug, Clone, Copy, PartialEq, Eq)]
362#[cfg_attr(
363 feature = "python",
364 pyo3::pyclass(
365 module = "nautilus_trader.core.nautilus_pyo3.interactive_brokers",
366 from_py_object
367 )
368)]
369pub enum IbFundDistributionPolicyIndicator {
370 None,
371 AccumulationFund,
372 IncomeFund,
373}
374
375impl IbFundDistributionPolicyIndicator {
376 #[must_use]
377 pub const fn as_str(self) -> &'static str {
378 match self {
379 Self::None => "",
380 Self::AccumulationFund => "N",
381 Self::IncomeFund => "Y",
382 }
383 }
384}
385
386impl Display for IbFundDistributionPolicyIndicator {
387 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
388 f.write_str(self.as_str())
389 }
390}
391
392#[derive(Debug, Clone, Copy, PartialEq, Eq)]
393#[cfg_attr(
394 feature = "python",
395 pyo3::pyclass(
396 module = "nautilus_trader.core.nautilus_pyo3.interactive_brokers",
397 from_py_object
398 )
399)]
400pub enum IbFundAssetType {
401 None,
402 Others,
403 MoneyMarket,
404 FixedIncome,
405 MultiAsset,
406 Equity,
407 Sector,
408 Guaranteed,
409 Alternative,
410}
411
412impl IbFundAssetType {
413 #[must_use]
414 pub const fn as_str(self) -> &'static str {
415 match self {
416 Self::None => "",
417 Self::Others => "000",
418 Self::MoneyMarket => "001",
419 Self::FixedIncome => "002",
420 Self::MultiAsset => "003",
421 Self::Equity => "004",
422 Self::Sector => "005",
423 Self::Guaranteed => "006",
424 Self::Alternative => "007",
425 }
426 }
427}
428
429impl Display for IbFundAssetType {
430 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
431 f.write_str(self.as_str())
432 }
433}
434
435#[derive(Debug, Clone, Copy, PartialEq, Eq)]
437#[cfg_attr(
438 feature = "python",
439 pyo3::pyclass(
440 module = "nautilus_trader.core.nautilus_pyo3.interactive_brokers",
441 from_py_object
442 )
443)]
444pub enum IbBondIdentifierKind {
445 Cusip,
446 Isin,
447}
448
449impl IbBondIdentifierKind {
450 #[must_use]
451 pub const fn as_str(self) -> &'static str {
452 match self {
453 Self::Cusip => "CUSIP",
454 Self::Isin => "ISIN",
455 }
456 }
457}
458
459impl Display for IbBondIdentifierKind {
460 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
461 f.write_str(self.as_str())
462 }
463}