#![warn(missing_docs)]
#![allow(clippy::octal_escapes)]
#![allow(clippy::bool_assert_comparison)]
#![allow(clippy::useless_format)]
#![allow(clippy::uninlined_format_args)]
#![allow(clippy::assertions_on_constants)]
#[cfg(not(any(feature = "sync", feature = "async")))]
compile_error!(
"You must enable at least one of the 'sync' or 'async' features to use this crate.\n\
The 'async' feature is enabled by default; if you disabled default features, be sure to\n\
opt back into either API:\n\
ibapi = { version = \"2.0\", default-features = false, features = [\"sync\"] }\n\
ibapi = { version = \"2.0\", default-features = false, features = [\"async\"] }\n\
You may also enable both to access the synchronous API under `client::blocking`."
);
pub mod accounts;
pub mod client;
pub(crate) mod transport;
pub(crate) mod connection;
pub use connection::ConnectionOptions;
pub use connection::StartupMessageCallback;
pub(crate) mod common;
pub use common::timezone::register_timezone_alias;
pub mod display_groups;
pub mod subscriptions;
pub mod contracts;
pub mod errors;
pub mod market_data;
pub mod messages;
pub mod news;
pub mod orders;
pub mod scanner;
pub mod wsh;
pub mod trace;
pub mod prelude;
pub mod protocol;
#[cfg(feature = "proto")]
pub mod proto;
mod server_versions;
#[doc(inline)]
pub use errors::Error;
#[doc(inline)]
pub use client::Client;
use std::sync::LazyLock;
use time::{
format_description::{self, BorrowedFormatItem},
Date,
};
#[cfg(test)]
pub(crate) mod stubs;
#[cfg(test)]
pub(crate) mod tests;
#[cfg(test)]
pub(crate) mod testdata;
pub(crate) trait ToField {
fn to_field(&self) -> String;
}
impl ToField for bool {
fn to_field(&self) -> String {
if *self {
String::from("1")
} else {
String::from("0")
}
}
}
impl ToField for String {
fn to_field(&self) -> String {
self.clone()
}
}
impl ToField for Option<String> {
fn to_field(&self) -> String {
encode_option_field(self)
}
}
impl ToField for &str {
fn to_field(&self) -> String {
<&str>::clone(self).to_string()
}
}
impl ToField for Option<&str> {
fn to_field(&self) -> String {
encode_option_field(self)
}
}
impl ToField for usize {
fn to_field(&self) -> String {
self.to_string()
}
}
impl ToField for i32 {
fn to_field(&self) -> String {
self.to_string()
}
}
impl ToField for Option<i32> {
fn to_field(&self) -> String {
encode_option_field(self)
}
}
impl ToField for f64 {
fn to_field(&self) -> String {
self.to_string()
}
}
impl ToField for Option<f64> {
fn to_field(&self) -> String {
encode_option_field(self)
}
}
fn date_format() -> Vec<BorrowedFormatItem<'static>> {
format_description::parse("[year][month][day]").unwrap()
}
static DATE_FORMAT: LazyLock<Vec<BorrowedFormatItem<'static>>> = LazyLock::new(date_format);
impl ToField for Date {
fn to_field(&self) -> String {
self.format(&DATE_FORMAT).unwrap()
}
}
impl ToField for Option<Date> {
fn to_field(&self) -> String {
encode_option_field(self)
}
}
fn encode_option_field<T: ToField>(val: &Option<T>) -> String {
match val {
Some(val) => val.to_field(),
None => String::from(""),
}
}
const MAX_RETRIES: i32 = 5;