mod common;
pub mod types;
use crate::contracts::Contract;
use serde::{Deserialize, Serialize};
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Debug, Default, Serialize, Deserialize)]
pub struct AccountSummary {
pub account: String,
pub tag: String,
pub value: String,
pub currency: String,
}
pub struct AccountSummaryTags {}
impl AccountSummaryTags {
pub const ACCOUNT_TYPE: &'static str = "AccountType";
pub const NET_LIQUIDATION: &'static str = "NetLiquidation";
pub const TOTAL_CASH_VALUE: &'static str = "TotalCashValue";
pub const SETTLED_CASH: &'static str = "SettledCash";
pub const ACCRUED_CASH: &'static str = "AccruedCash";
pub const BUYING_POWER: &'static str = "BuyingPower";
pub const EQUITY_WITH_LOAN_VALUE: &'static str = "EquityWithLoanValue";
pub const PREVIOUS_EQUITY_WITH_LOAN_VALUE: &'static str = "PreviousEquityWithLoanValue";
pub const GROSS_POSITION_VALUE: &'static str = "GrossPositionValue";
pub const REQ_T_EQUITY: &'static str = "RegTEquity";
pub const REQ_T_MARGIN: &'static str = "RegTMargin";
pub const SMA: &'static str = "SMA";
pub const INIT_MARGIN_REQ: &'static str = "InitMarginReq";
pub const MAINT_MARGIN_REQ: &'static str = "MaintMarginReq";
pub const AVAILABLE_FUNDS: &'static str = "AvailableFunds";
pub const EXCESS_LIQUIDITY: &'static str = "ExcessLiquidity";
pub const CUSHION: &'static str = "Cushion";
pub const FULL_INIT_MARGIN_REQ: &'static str = "FullInitMarginReq";
pub const FULL_MAINT_MARGIN_REQ: &'static str = "FullMaintMarginReq";
pub const FULL_AVAILABLE_FUNDS: &'static str = "FullAvailableFunds";
pub const FULL_EXCESS_LIQUIDITY: &'static str = "FullExcessLiquidity";
pub const LOOK_AHEAD_NEXT_CHANGE: &'static str = "LookAheadNextChange";
pub const LOOK_AHEAD_INIT_MARGIN_REQ: &'static str = "LookAheadInitMarginReq";
pub const LOOK_AHEAD_MAINT_MARGIN_REQ: &'static str = "LookAheadMaintMarginReq";
pub const LOOK_AHEAD_AVAILABLE_FUNDS: &'static str = "LookAheadAvailableFunds";
pub const LOOK_AHEAD_EXCESS_LIQUIDITY: &'static str = "LookAheadExcessLiquidity";
pub const HIGHEST_SEVERITY: &'static str = "HighestSeverity";
pub const DAY_TRADES_REMAINING: &'static str = "DayTradesRemaining";
pub const LEVERAGE: &'static str = "Leverage";
pub const LEDGER: &'static str = "$LEDGER";
pub const LEDGER_ALL: &'static str = "$LEDGER:ALL";
pub const ALL: &'static [&'static str] = &[
Self::ACCOUNT_TYPE,
Self::NET_LIQUIDATION,
Self::TOTAL_CASH_VALUE,
Self::SETTLED_CASH,
Self::ACCRUED_CASH,
Self::BUYING_POWER,
Self::EQUITY_WITH_LOAN_VALUE,
Self::PREVIOUS_EQUITY_WITH_LOAN_VALUE,
Self::GROSS_POSITION_VALUE,
Self::REQ_T_EQUITY,
Self::REQ_T_MARGIN,
Self::SMA,
Self::INIT_MARGIN_REQ,
Self::MAINT_MARGIN_REQ,
Self::AVAILABLE_FUNDS,
Self::EXCESS_LIQUIDITY,
Self::CUSHION,
Self::FULL_INIT_MARGIN_REQ,
Self::FULL_MAINT_MARGIN_REQ,
Self::FULL_AVAILABLE_FUNDS,
Self::FULL_EXCESS_LIQUIDITY,
Self::LOOK_AHEAD_NEXT_CHANGE,
Self::LOOK_AHEAD_INIT_MARGIN_REQ,
Self::LOOK_AHEAD_MAINT_MARGIN_REQ,
Self::LOOK_AHEAD_AVAILABLE_FUNDS,
Self::LOOK_AHEAD_EXCESS_LIQUIDITY,
Self::HIGHEST_SEVERITY,
Self::DAY_TRADES_REMAINING,
Self::LEVERAGE,
Self::LEDGER_ALL,
];
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Debug)]
pub enum AccountSummaryResult {
Summary(AccountSummary),
End,
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Debug, Default, Serialize, Deserialize)]
pub struct PnL {
pub daily_pnl: f64,
pub unrealized_pnl: Option<f64>,
pub realized_pnl: Option<f64>,
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Debug, Default, Serialize, Deserialize)]
pub struct PnLSingle {
pub position: f64,
pub daily_pnl: f64,
pub unrealized_pnl: f64,
pub realized_pnl: f64,
pub value: f64,
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct Position {
pub account: String,
pub contract: Contract,
pub position: f64,
pub average_cost: f64,
}
#[allow(clippy::large_enum_variant)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Debug)]
pub enum PositionUpdate {
Position(Position),
PositionEnd,
}
#[allow(clippy::large_enum_variant)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Debug)]
pub enum PositionUpdateMulti {
Position(PositionMulti),
PositionEnd,
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct PositionMulti {
pub account: String,
pub contract: Contract,
pub position: f64,
pub average_cost: f64,
pub model_code: String,
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct FamilyCode {
pub account_id: String,
pub family_code: String,
}
#[allow(clippy::large_enum_variant)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Debug)]
pub enum AccountUpdate {
AccountValue(AccountValue),
PortfolioValue(AccountPortfolioValue),
UpdateTime(AccountUpdateTime),
End,
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Debug, Default, Serialize, Deserialize)]
pub struct AccountValue {
pub key: String,
pub value: String,
pub currency: String,
pub account: Option<String>,
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct AccountPortfolioValue {
pub contract: Contract,
pub position: f64,
pub market_price: f64,
pub market_value: f64,
pub average_cost: f64,
pub unrealized_pnl: f64,
pub realized_pnl: f64,
pub account: Option<String>,
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct AccountUpdateTime {
pub timestamp: String,
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Debug, PartialEq)]
pub enum AccountUpdateMulti {
AccountMultiValue(AccountMultiValue),
End,
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct AccountMultiValue {
pub account: String,
pub model_code: String,
pub key: String,
pub value: String,
pub currency: String,
}
#[cfg(feature = "sync")]
mod sync;
#[cfg(feature = "async")]
mod r#async;
#[cfg(feature = "sync")]
pub mod blocking {
pub use super::sync::{
account_summary, account_updates, account_updates_multi, family_codes, managed_accounts, pnl, pnl_single, positions, positions_multi,
server_time, server_time_millis,
};
}
#[cfg(all(feature = "sync", not(feature = "async")))]
pub use sync::{
account_summary, account_updates, account_updates_multi, family_codes, managed_accounts, pnl, pnl_single, positions, positions_multi,
server_time, server_time_millis,
};
#[cfg(feature = "async")]
pub use r#async::{
account_summary, account_updates, account_updates_multi, family_codes, managed_accounts, pnl, pnl_single, positions, positions_multi,
server_time, server_time_millis,
};