pub mod accounts;
pub mod client;
pub(crate) mod transport;
pub mod contracts;
pub mod errors;
pub mod market_data;
mod messages;
pub mod news;
pub mod orders;
pub mod scanner;
pub mod wsh;
pub mod prelude;
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;