1#![cfg_attr(
25 feature = "async",
26 doc = r#"```no_run
27use ibapi::prelude::*;
28
29#[tokio::main]
30async fn main() {
31 let client = Client::connect("127.0.0.1:4002", 100)
32 .await
33 .expect("connection failed");
34
35 let contract = Contract::stock("AAPL").build();
36 let order_id = client
37 .order(&contract)
38 .buy(100)
39 .market()
40 .submit()
41 .await
42 .expect("order submission failed");
43 println!("submitted order id: {order_id}");
44}
45```"#
46)]
47#![cfg_attr(
48 not(feature = "async"),
49 doc = r#"```no_run
50use ibapi::prelude::*;
51
52fn main() {
53 let client = Client::connect("127.0.0.1:4002", 100).expect("connection failed");
54
55 let contract = Contract::stock("AAPL").build();
56 let order_id = client
57 .order(&contract)
58 .buy(100)
59 .market()
60 .submit()
61 .expect("order submission failed");
62 println!("submitted order id: {order_id}");
63}
64```"#
65)]
66#![warn(missing_docs)]
72#![allow(clippy::octal_escapes)]
74#![allow(clippy::bool_assert_comparison)]
75#![allow(clippy::useless_format)]
76#![allow(clippy::uninlined_format_args)]
77#![allow(clippy::assertions_on_constants)]
78
79#[cfg(not(any(feature = "sync", feature = "async")))]
81compile_error!(
82 "You must enable at least one of the 'sync' or 'async' features to use this crate.\n\
83 The 'async' feature is enabled by default; if you disabled default features, be sure to\n\
84 opt back into either API:\n\
85 ibapi = { version = \"4.0\", default-features = false, features = [\"sync\"] }\n\
86 ibapi = { version = \"4.0\", default-features = false, features = [\"async\"] }\n\
87 You may also enable both to access the synchronous API under `client::blocking`."
88);
89
90#[cfg(all(feature = "utoipa", not(feature = "utoipa-6")))]
96compile_error!("the `utoipa` feature is internal; enable a `utoipa-<major>` feature such as `utoipa-6`");
97
98#[cfg(feature = "utoipa-6")]
99extern crate utoipa6 as utoipa;
100
101#[macro_use]
102mod macros;
103
104pub mod accounts;
106
107pub mod client;
112
113pub(crate) mod transport;
114
115pub(crate) mod connection;
117
118#[cfg_attr(
127 feature = "async",
128 doc = r#"```no_run
129use ibapi::{Client, StartupMessage};
130use std::sync::{Arc, Mutex};
131
132#[tokio::main]
133async fn main() {
134 let order_ids = Arc::new(Mutex::new(Vec::new()));
135 let order_ids_clone = order_ids.clone();
136
137 let client = Client::builder()
138 .address("127.0.0.1:4002")
139 .client_id(100)
140 .startup_callback(move |msg| if let StartupMessage::OpenOrder(o) = msg {
141 order_ids_clone.lock().unwrap().push(o.order_id);
142 })
143 .connect()
144 .await
145 .expect("connection failed");
146
147 println!("Received {} startup open-orders", order_ids.lock().unwrap().len());
148 drop(client);
149}
150```"#
151)]
152#[cfg_attr(
153 not(feature = "async"),
154 doc = r#"```no_run
155use ibapi::{Client, StartupMessage};
156use std::sync::{Arc, Mutex};
157
158fn main() {
159 let order_ids = Arc::new(Mutex::new(Vec::new()));
160 let order_ids_clone = order_ids.clone();
161
162 let client = Client::builder()
163 .address("127.0.0.1:4002")
164 .client_id(100)
165 .startup_callback(move |msg| if let StartupMessage::OpenOrder(o) = msg {
166 order_ids_clone.lock().unwrap().push(o.order_id);
167 })
168 .connect()
169 .expect("connection failed");
170
171 println!("Received {} startup open-orders", order_ids.lock().unwrap().len());
172 drop(client);
173}
174```"#
175)]
176pub use connection::StartupMessage;
177
178pub(crate) mod common;
180
181pub use common::timezone::register_timezone_alias;
182
183pub mod display_groups;
185
186pub mod subscriptions;
188
189pub mod config;
191pub mod contracts;
195pub mod errors;
197pub mod market_data;
199pub(crate) mod messages;
200pub mod news;
202pub mod orders;
204pub mod scanner;
206pub mod wsh;
208
209pub mod prelude;
211
212pub mod protocol;
214
215pub(crate) mod proto;
217
218mod server_versions;
219
220#[doc(inline)]
221pub use errors::Error;
222
223#[doc(inline)]
224pub use client::Client;
225#[doc(inline)]
226pub use client::ClientBuilder;
227
228#[doc(inline)]
229pub use transport::rate_limiter::RateLimiter;
230
231pub(crate) use messages::{encode_option_field, ToField};
232
233#[doc(inline)]
234pub use messages::{ConnectivityStatus, IncomingMessages, Notice, NoticeCategory, OutgoingMessages};
235
236#[doc(inline)]
237pub use messages::{
238 DATA_ADVISORY_CODES, HANDSHAKE_DECODE_FAILURE_CODE, HANDSHAKE_UNKNOWN_FRAME_CODE, NOTICE_STREAM_LAG_CODE, ORDER_CANCELLED_CODE,
239 ORDER_MESSAGE_CODE, ORDER_REJECTION_CODE_RANGE, REQUEST_ERROR_CODES, SUBSCRIPTION_LAG_CODE, SYSTEM_MESSAGE_CODES, TRANSPORT_RECONNECT_CODE,
240 UNKNOWN_MESSAGE_TYPE_CODE, WARNING_CODE_RANGE,
241};
242
243#[cfg(test)]
244pub(crate) mod stubs;
245
246#[cfg(test)]
247pub(crate) mod tests;
248
249#[cfg(test)]
250#[path = "lib_tests.rs"]
251mod lib_tests;
252
253#[cfg(test)]
254pub(crate) mod testdata;