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