Skip to main content

nautilus_interactive_brokers/common/enums/
misc.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16use std::fmt::Display;
17
18/// Interactive Brokers order origin values.
19#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
20#[cfg_attr(
21    feature = "python",
22    pyo3::pyclass(
23        module = "nautilus_trader.adapters.interactive_brokers",
24        from_py_object,
25        rename_all = "SCREAMING_SNAKE_CASE"
26    )
27)]
28#[cfg_attr(
29    feature = "python",
30    pyo3_stub_gen::derive::gen_stub_pyclass_enum(
31        module = "nautilus_trader.adapters.interactive_brokers"
32    )
33)]
34pub enum IbOrderOrigin {
35    #[default]
36    Customer,
37    Firm,
38}
39
40impl IbOrderOrigin {
41    #[must_use]
42    pub const fn as_i32(self) -> i32 {
43        match self {
44            Self::Customer => 0,
45            Self::Firm => 1,
46        }
47    }
48}
49
50impl From<i32> for IbOrderOrigin {
51    fn from(value: i32) -> Self {
52        match value {
53            0 => Self::Customer,
54            1 => Self::Firm,
55            _ => Self::default(),
56        }
57    }
58}
59
60impl Display for IbOrderOrigin {
61    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
62        write!(f, "{}", self.as_i32())
63    }
64}
65
66impl IbOrderOrigin {
67    #[must_use]
68    pub fn ibapi_order_origin(self) -> ibapi::orders::OrderOrigin {
69        ibapi::orders::OrderOrigin::from(self.as_i32())
70    }
71}
72
73/// Interactive Brokers institutional short-sale slot values.
74#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
75#[cfg_attr(
76    feature = "python",
77    pyo3::pyclass(
78        module = "nautilus_trader.adapters.interactive_brokers",
79        from_py_object,
80        rename_all = "SCREAMING_SNAKE_CASE"
81    )
82)]
83#[cfg_attr(
84    feature = "python",
85    pyo3_stub_gen::derive::gen_stub_pyclass_enum(
86        module = "nautilus_trader.adapters.interactive_brokers"
87    )
88)]
89pub enum IbShortSaleSlot {
90    #[default]
91    None,
92    Broker,
93    ThirdParty,
94}
95
96impl IbShortSaleSlot {
97    #[must_use]
98    pub const fn as_i32(self) -> i32 {
99        match self {
100            Self::None => 0,
101            Self::Broker => 1,
102            Self::ThirdParty => 2,
103        }
104    }
105}
106
107impl From<i32> for IbShortSaleSlot {
108    fn from(value: i32) -> Self {
109        match value {
110            0 => Self::None,
111            1 => Self::Broker,
112            2 => Self::ThirdParty,
113            _ => Self::default(),
114        }
115    }
116}
117
118impl Display for IbShortSaleSlot {
119    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
120        write!(f, "{}", self.as_i32())
121    }
122}
123
124impl IbShortSaleSlot {
125    #[must_use]
126    pub fn ibapi_short_sale_slot(self) -> ibapi::orders::ShortSaleSlot {
127        ibapi::orders::ShortSaleSlot::from(self.as_i32())
128    }
129}
130
131/// Interactive Brokers volatility type values.
132#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
133#[cfg_attr(
134    feature = "python",
135    pyo3::pyclass(
136        module = "nautilus_trader.adapters.interactive_brokers",
137        from_py_object,
138        rename_all = "SCREAMING_SNAKE_CASE"
139    )
140)]
141#[cfg_attr(
142    feature = "python",
143    pyo3_stub_gen::derive::gen_stub_pyclass_enum(
144        module = "nautilus_trader.adapters.interactive_brokers"
145    )
146)]
147pub enum IbVolatilityType {
148    #[default]
149    Daily,
150    Annual,
151}
152
153impl IbVolatilityType {
154    #[must_use]
155    pub const fn as_i32(self) -> i32 {
156        match self {
157            Self::Daily => 1,
158            Self::Annual => 2,
159        }
160    }
161}
162
163impl From<i32> for IbVolatilityType {
164    fn from(value: i32) -> Self {
165        match value {
166            1 => Self::Daily,
167            2 => Self::Annual,
168            _ => Self::default(),
169        }
170    }
171}
172
173impl Display for IbVolatilityType {
174    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
175        write!(f, "{}", self.as_i32())
176    }
177}
178
179impl IbVolatilityType {
180    #[must_use]
181    pub fn ibapi_volatility_type(self) -> ibapi::orders::VolatilityType {
182        ibapi::orders::VolatilityType::from(self.as_i32())
183    }
184}
185
186/// Interactive Brokers VOL order reference price type values.
187#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
188#[cfg_attr(
189    feature = "python",
190    pyo3::pyclass(
191        module = "nautilus_trader.adapters.interactive_brokers",
192        from_py_object,
193        rename_all = "SCREAMING_SNAKE_CASE"
194    )
195)]
196#[cfg_attr(
197    feature = "python",
198    pyo3_stub_gen::derive::gen_stub_pyclass_enum(
199        module = "nautilus_trader.adapters.interactive_brokers"
200    )
201)]
202pub enum IbReferencePriceType {
203    #[default]
204    AverageOfNbbo,
205    Nbbo,
206}
207
208impl IbReferencePriceType {
209    #[must_use]
210    pub const fn as_i32(self) -> i32 {
211        match self {
212            Self::AverageOfNbbo => 1,
213            Self::Nbbo => 2,
214        }
215    }
216}
217
218impl From<i32> for IbReferencePriceType {
219    fn from(value: i32) -> Self {
220        match value {
221            1 => Self::AverageOfNbbo,
222            2 => Self::Nbbo,
223            _ => Self::default(),
224        }
225    }
226}
227
228impl Display for IbReferencePriceType {
229    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
230        write!(f, "{}", self.as_i32())
231    }
232}
233
234impl IbReferencePriceType {
235    #[must_use]
236    pub fn ibapi_reference_price_type(self) -> ibapi::orders::ReferencePriceType {
237        ibapi::orders::ReferencePriceType::from(self.as_i32())
238    }
239}
240
241/// Interactive Brokers BOX auction strategy values.
242#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
243#[cfg_attr(
244    feature = "python",
245    pyo3::pyclass(
246        module = "nautilus_trader.adapters.interactive_brokers",
247        from_py_object,
248        rename_all = "SCREAMING_SNAKE_CASE"
249    )
250)]
251#[cfg_attr(
252    feature = "python",
253    pyo3_stub_gen::derive::gen_stub_pyclass_enum(
254        module = "nautilus_trader.adapters.interactive_brokers"
255    )
256)]
257pub enum IbAuctionStrategy {
258    #[default]
259    Match,
260    Improvement,
261    Transparent,
262}
263
264impl IbAuctionStrategy {
265    #[must_use]
266    pub const fn as_i32(self) -> i32 {
267        match self {
268            Self::Match => 1,
269            Self::Improvement => 2,
270            Self::Transparent => 3,
271        }
272    }
273}
274
275impl From<i32> for IbAuctionStrategy {
276    fn from(value: i32) -> Self {
277        match value {
278            1 => Self::Match,
279            2 => Self::Improvement,
280            3 => Self::Transparent,
281            _ => Self::default(),
282        }
283    }
284}
285
286impl Display for IbAuctionStrategy {
287    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
288        write!(f, "{}", self.as_i32())
289    }
290}
291
292impl IbAuctionStrategy {
293    #[must_use]
294    pub fn ibapi_auction_strategy(self) -> ibapi::orders::AuctionStrategy {
295        ibapi::orders::AuctionStrategy::from(self.as_i32())
296    }
297}
298
299/// Interactive Brokers option exercise action values.
300#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
301#[cfg_attr(
302    feature = "python",
303    pyo3::pyclass(
304        module = "nautilus_trader.adapters.interactive_brokers",
305        from_py_object,
306        rename_all = "SCREAMING_SNAKE_CASE"
307    )
308)]
309#[cfg_attr(
310    feature = "python",
311    pyo3_stub_gen::derive::gen_stub_pyclass_enum(
312        module = "nautilus_trader.adapters.interactive_brokers"
313    )
314)]
315pub enum IbExerciseAction {
316    #[default]
317    Exercise,
318    Lapse,
319}
320
321impl IbExerciseAction {
322    #[must_use]
323    pub const fn as_i32(self) -> i32 {
324        match self {
325            Self::Exercise => 1,
326            Self::Lapse => 2,
327        }
328    }
329}
330
331impl From<i32> for IbExerciseAction {
332    fn from(value: i32) -> Self {
333        match value {
334            1 => Self::Exercise,
335            2 => Self::Lapse,
336            _ => Self::default(),
337        }
338    }
339}
340
341impl Display for IbExerciseAction {
342    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
343        write!(f, "{}", self.as_i32())
344    }
345}
346
347impl IbExerciseAction {
348    #[must_use]
349    pub const fn ibapi_exercise_action(self) -> ibapi::orders::ExerciseAction {
350        match self {
351            Self::Exercise => ibapi::orders::ExerciseAction::Exercise,
352            Self::Lapse => ibapi::orders::ExerciseAction::Lapse,
353        }
354    }
355}
356
357/// Interactive Brokers news article type values.
358#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
359#[cfg_attr(
360    feature = "python",
361    pyo3::pyclass(
362        module = "nautilus_trader.adapters.interactive_brokers",
363        from_py_object,
364        rename_all = "SCREAMING_SNAKE_CASE"
365    )
366)]
367#[cfg_attr(
368    feature = "python",
369    pyo3_stub_gen::derive::gen_stub_pyclass_enum(
370        module = "nautilus_trader.adapters.interactive_brokers"
371    )
372)]
373pub enum IbArticleType {
374    #[default]
375    Text,
376    Binary,
377}
378
379impl IbArticleType {
380    #[must_use]
381    pub const fn as_i32(self) -> i32 {
382        match self {
383            Self::Text => 0,
384            Self::Binary => 1,
385        }
386    }
387}
388
389impl From<i32> for IbArticleType {
390    fn from(value: i32) -> Self {
391        match value {
392            0 => Self::Text,
393            1 => Self::Binary,
394            _ => Self::default(),
395        }
396    }
397}
398
399impl Display for IbArticleType {
400    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
401        write!(f, "{}", self.as_i32())
402    }
403}
404
405impl IbArticleType {
406    #[must_use]
407    pub fn ibapi_article_type(self) -> ibapi::news::ArticleType {
408        ibapi::news::ArticleType::from(self.as_i32())
409    }
410}
411
412/// Interactive Brokers builder auction type values.
413#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
414#[cfg_attr(
415    feature = "python",
416    pyo3::pyclass(
417        module = "nautilus_trader.adapters.interactive_brokers",
418        from_py_object,
419        rename_all = "SCREAMING_SNAKE_CASE"
420    )
421)]
422#[cfg_attr(
423    feature = "python",
424    pyo3_stub_gen::derive::gen_stub_pyclass_enum(
425        module = "nautilus_trader.adapters.interactive_brokers"
426    )
427)]
428pub enum IbAuctionType {
429    #[default]
430    Opening,
431    Closing,
432    Volatility,
433}
434
435impl IbAuctionType {
436    #[must_use]
437    pub const fn as_i32(self) -> i32 {
438        match self {
439            Self::Opening => 1,
440            Self::Closing => 2,
441            Self::Volatility => 4,
442        }
443    }
444}
445
446impl From<i32> for IbAuctionType {
447    fn from(value: i32) -> Self {
448        match value {
449            1 => Self::Opening,
450            2 => Self::Closing,
451            4 => Self::Volatility,
452            _ => Self::default(),
453        }
454    }
455}
456
457impl Display for IbAuctionType {
458    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
459        write!(f, "{}", self.as_i32())
460    }
461}
462
463#[derive(Debug, Clone, Copy, PartialEq, Eq)]
464#[cfg_attr(
465    feature = "python",
466    pyo3::pyclass(
467        module = "nautilus_trader.adapters.interactive_brokers",
468        from_py_object,
469        rename_all = "SCREAMING_SNAKE_CASE"
470    )
471)]
472#[cfg_attr(
473    feature = "python",
474    pyo3_stub_gen::derive::gen_stub_pyclass_enum(
475        module = "nautilus_trader.adapters.interactive_brokers"
476    )
477)]
478pub enum IbRule80A {
479    Individual,
480    Agency,
481    AgentOtherMember,
482    IndividualPtia,
483    AgencyPtia,
484    AgentOtherMemberPtia,
485    IndividualPt,
486    AgencyPt,
487    AgentOtherMemberPt,
488}
489
490impl IbRule80A {
491    #[must_use]
492    pub const fn as_str(self) -> &'static str {
493        match self {
494            Self::Individual => "I",
495            Self::Agency => "A",
496            Self::AgentOtherMember => "W",
497            Self::IndividualPtia => "J",
498            Self::AgencyPtia => "U",
499            Self::AgentOtherMemberPtia => "M",
500            Self::IndividualPt => "K",
501            Self::AgencyPt => "Y",
502            Self::AgentOtherMemberPt => "N",
503        }
504    }
505}
506
507impl Display for IbRule80A {
508    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
509        f.write_str(self.as_str())
510    }
511}
512
513#[derive(Debug, Clone, Copy, PartialEq, Eq)]
514#[cfg_attr(
515    feature = "python",
516    pyo3::pyclass(
517        module = "nautilus_trader.adapters.interactive_brokers",
518        from_py_object,
519        rename_all = "SCREAMING_SNAKE_CASE"
520    )
521)]
522#[cfg_attr(
523    feature = "python",
524    pyo3_stub_gen::derive::gen_stub_pyclass_enum(
525        module = "nautilus_trader.adapters.interactive_brokers"
526    )
527)]
528pub enum IbOrderOpenClose {
529    Open,
530    Close,
531}
532
533impl IbOrderOpenClose {
534    #[must_use]
535    pub const fn as_str(self) -> &'static str {
536        match self {
537            Self::Open => "O",
538            Self::Close => "C",
539        }
540    }
541}
542
543impl Display for IbOrderOpenClose {
544    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
545        f.write_str(self.as_str())
546    }
547}
548
549#[derive(Debug, Clone, Copy, PartialEq, Eq)]
550#[cfg_attr(
551    feature = "python",
552    pyo3::pyclass(
553        module = "nautilus_trader.adapters.interactive_brokers",
554        from_py_object,
555        rename_all = "SCREAMING_SNAKE_CASE"
556    )
557)]
558#[cfg_attr(
559    feature = "python",
560    pyo3_stub_gen::derive::gen_stub_pyclass_enum(
561        module = "nautilus_trader.adapters.interactive_brokers"
562    )
563)]
564pub enum IbTwapStrategyType {
565    Marketable,
566    MatchingMidpoint,
567    MatchingSameSide,
568    MatchingLast,
569}
570
571impl IbTwapStrategyType {
572    #[must_use]
573    pub const fn as_str(self) -> &'static str {
574        match self {
575            Self::Marketable => "Marketable",
576            Self::MatchingMidpoint => "Matching Midpoint",
577            Self::MatchingSameSide => "Matching Same Side",
578            Self::MatchingLast => "Matching Last",
579        }
580    }
581}
582
583impl Display for IbTwapStrategyType {
584    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
585        f.write_str(self.as_str())
586    }
587}
588
589#[derive(Debug, Clone, Copy, PartialEq, Eq)]
590#[cfg_attr(
591    feature = "python",
592    pyo3::pyclass(
593        module = "nautilus_trader.adapters.interactive_brokers",
594        from_py_object,
595        rename_all = "SCREAMING_SNAKE_CASE"
596    )
597)]
598#[cfg_attr(
599    feature = "python",
600    pyo3_stub_gen::derive::gen_stub_pyclass_enum(
601        module = "nautilus_trader.adapters.interactive_brokers"
602    )
603)]
604pub enum IbRiskAversion {
605    GetDone,
606    Aggressive,
607    Neutral,
608    Passive,
609}
610
611impl IbRiskAversion {
612    #[must_use]
613    pub const fn as_str(self) -> &'static str {
614        match self {
615            Self::GetDone => "Get Done",
616            Self::Aggressive => "Aggressive",
617            Self::Neutral => "Neutral",
618            Self::Passive => "Passive",
619        }
620    }
621}
622
623impl Display for IbRiskAversion {
624    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
625        f.write_str(self.as_str())
626    }
627}
628
629#[derive(Debug, Clone, Copy, PartialEq, Eq)]
630#[cfg_attr(
631    feature = "python",
632    pyo3::pyclass(
633        module = "nautilus_trader.adapters.interactive_brokers",
634        from_py_object,
635        rename_all = "SCREAMING_SNAKE_CASE"
636    )
637)]
638#[cfg_attr(
639    feature = "python",
640    pyo3_stub_gen::derive::gen_stub_pyclass_enum(
641        module = "nautilus_trader.adapters.interactive_brokers"
642    )
643)]
644pub enum IbLegAction {
645    Buy,
646    Sell,
647}
648
649impl IbLegAction {
650    #[must_use]
651    pub const fn as_str(self) -> &'static str {
652        match self {
653            Self::Buy => "BUY",
654            Self::Sell => "SELL",
655        }
656    }
657}
658
659impl Display for IbLegAction {
660    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
661        f.write_str(self.as_str())
662    }
663}
664
665#[derive(Debug, Clone, Copy, PartialEq, Eq)]
666#[cfg_attr(
667    feature = "python",
668    pyo3::pyclass(
669        module = "nautilus_trader.adapters.interactive_brokers",
670        from_py_object,
671        rename_all = "SCREAMING_SNAKE_CASE"
672    )
673)]
674#[cfg_attr(
675    feature = "python",
676    pyo3_stub_gen::derive::gen_stub_pyclass_enum(
677        module = "nautilus_trader.adapters.interactive_brokers"
678    )
679)]
680pub enum IbFundDistributionPolicyIndicator {
681    None,
682    AccumulationFund,
683    IncomeFund,
684}
685
686impl IbFundDistributionPolicyIndicator {
687    #[must_use]
688    pub const fn as_str(self) -> &'static str {
689        match self {
690            Self::None => "",
691            Self::AccumulationFund => "N",
692            Self::IncomeFund => "Y",
693        }
694    }
695}
696
697impl Display for IbFundDistributionPolicyIndicator {
698    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
699        f.write_str(self.as_str())
700    }
701}
702
703#[derive(Debug, Clone, Copy, PartialEq, Eq)]
704#[cfg_attr(
705    feature = "python",
706    pyo3::pyclass(
707        module = "nautilus_trader.adapters.interactive_brokers",
708        from_py_object,
709        rename_all = "SCREAMING_SNAKE_CASE"
710    )
711)]
712#[cfg_attr(
713    feature = "python",
714    pyo3_stub_gen::derive::gen_stub_pyclass_enum(
715        module = "nautilus_trader.adapters.interactive_brokers"
716    )
717)]
718pub enum IbFundAssetType {
719    None,
720    Others,
721    MoneyMarket,
722    FixedIncome,
723    MultiAsset,
724    Equity,
725    Sector,
726    Guaranteed,
727    Alternative,
728}
729
730impl IbFundAssetType {
731    #[must_use]
732    pub const fn as_str(self) -> &'static str {
733        match self {
734            Self::None => "",
735            Self::Others => "000",
736            Self::MoneyMarket => "001",
737            Self::FixedIncome => "002",
738            Self::MultiAsset => "003",
739            Self::Equity => "004",
740            Self::Sector => "005",
741            Self::Guaranteed => "006",
742            Self::Alternative => "007",
743        }
744    }
745}
746
747impl Display for IbFundAssetType {
748    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
749        f.write_str(self.as_str())
750    }
751}
752
753/// Bond identifier discriminator for the rust-ibapi payload enum.
754#[derive(Debug, Clone, Copy, PartialEq, Eq)]
755#[cfg_attr(
756    feature = "python",
757    pyo3::pyclass(
758        module = "nautilus_trader.adapters.interactive_brokers",
759        from_py_object,
760        rename_all = "SCREAMING_SNAKE_CASE"
761    )
762)]
763#[cfg_attr(
764    feature = "python",
765    pyo3_stub_gen::derive::gen_stub_pyclass_enum(
766        module = "nautilus_trader.adapters.interactive_brokers"
767    )
768)]
769pub enum IbBondIdentifierKind {
770    Cusip,
771    Isin,
772}
773
774impl IbBondIdentifierKind {
775    #[must_use]
776    pub const fn as_str(self) -> &'static str {
777        match self {
778            Self::Cusip => "CUSIP",
779            Self::Isin => "ISIN",
780        }
781    }
782}
783
784impl Display for IbBondIdentifierKind {
785    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
786        f.write_str(self.as_str())
787    }
788}