pub(crate) mod common;
pub mod builder;
pub mod conditions;
pub use common::order_builder;
pub use builder::{BracketOrderBuilder, BracketOrderIds, OrderBuilder, OrderId};
pub use conditions::{
ExecutionCondition, ExecutionConditionBuilder, MarginCondition, MarginConditionBuilder, PercentChangeCondition, PercentChangeConditionBuilder,
PriceCondition, PriceConditionBuilder, TimeCondition, TimeConditionBuilder, VolumeCondition, VolumeConditionBuilder,
};
use std::convert::From;
use std::fmt::Debug;
use serde::{Deserialize, Serialize};
use crate::contracts::Contract;
use crate::{encode_option_field, ToField};
pub use crate::contracts::TagValue;
pub(crate) const COMPETE_AGAINST_BEST_OFFSET_UP_TO_MID: Option<f64> = Some(f64::INFINITY);
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Order {
pub order_id: i32,
pub solicited: bool,
pub client_id: i32,
pub perm_id: i32,
pub action: Action,
pub total_quantity: f64,
pub order_type: String,
pub limit_price: Option<f64>,
pub aux_price: Option<f64>,
pub tif: TimeInForce,
pub oca_group: String,
pub oca_type: OcaType,
pub order_ref: String,
pub transmit: bool,
pub parent_id: i32,
pub block_order: bool,
pub sweep_to_fill: bool,
pub display_size: Option<i32>,
pub trigger_method: conditions::TriggerMethod,
pub outside_rth: bool,
pub hidden: bool,
pub good_after_time: String,
pub good_till_date: String,
pub override_percentage_constraints: bool,
pub rule_80_a: Option<Rule80A>,
pub all_or_none: bool,
pub min_qty: Option<i32>,
pub percent_offset: Option<f64>,
pub trail_stop_price: Option<f64>,
pub trailing_percent: Option<f64>,
pub fa_group: String,
pub fa_profile: String,
pub fa_method: String,
pub fa_percentage: String,
pub open_close: Option<OrderOpenClose>,
pub origin: OrderOrigin,
pub short_sale_slot: ShortSaleSlot,
pub designated_location: String,
pub exempt_code: i32,
pub discretionary_amt: f64,
pub opt_out_smart_routing: bool,
pub auction_strategy: Option<AuctionStrategy>,
pub starting_price: Option<f64>,
pub stock_ref_price: Option<f64>,
pub delta: Option<f64>,
pub stock_range_lower: Option<f64>,
pub stock_range_upper: Option<f64>,
pub volatility: Option<f64>,
pub volatility_type: Option<VolatilityType>,
pub continuous_update: bool,
pub reference_price_type: Option<ReferencePriceType>,
pub delta_neutral_order_type: String,
pub delta_neutral_aux_price: Option<f64>,
pub delta_neutral_con_id: i32,
pub delta_neutral_settling_firm: String,
pub delta_neutral_clearing_account: String,
pub delta_neutral_clearing_intent: String,
pub delta_neutral_open_close: String,
pub delta_neutral_short_sale: bool,
pub delta_neutral_short_sale_slot: i32,
pub delta_neutral_designated_location: String,
pub basis_points: Option<f64>,
pub basis_points_type: Option<i32>,
pub scale_init_level_size: Option<i32>,
pub scale_subs_level_size: Option<i32>,
pub scale_price_increment: Option<f64>,
pub scale_price_adjust_value: Option<f64>,
pub scale_price_adjust_interval: Option<i32>,
pub scale_profit_offset: Option<f64>,
pub scale_auto_reset: bool,
pub scale_init_position: Option<i32>,
pub scale_init_fill_qty: Option<i32>,
pub scale_random_percent: bool,
pub hedge_type: String,
pub hedge_param: String,
pub account: String,
pub settling_firm: String,
pub clearing_account: String,
pub clearing_intent: String,
pub algo_strategy: String,
pub algo_params: Vec<TagValue>,
pub what_if: bool,
pub algo_id: String,
pub not_held: bool,
pub smart_combo_routing_params: Vec<TagValue>,
pub order_combo_legs: Vec<OrderComboLeg>,
pub order_misc_options: Vec<TagValue>,
pub active_start_time: String,
pub active_stop_time: String,
pub scale_table: String,
pub model_code: String,
pub ext_operator: String,
pub cash_qty: Option<f64>,
pub mifid2_decision_maker: String,
pub mifid2_decision_algo: String,
pub mifid2_execution_trader: String,
pub mifid2_execution_algo: String,
pub dont_use_auto_price_for_hedge: bool,
pub auto_cancel_date: String, pub filled_quantity: f64,
pub ref_futures_con_id: Option<i32>,
pub auto_cancel_parent: bool,
pub shareholder: String,
pub imbalance_only: bool,
pub route_marketable_to_bbo: bool,
pub parent_perm_id: Option<i64>,
pub advanced_error_override: String,
pub manual_order_time: String,
pub min_trade_qty: Option<i32>,
pub min_compete_size: Option<i32>,
pub compete_against_best_offset: Option<f64>,
pub mid_offset_at_whole: Option<f64>,
pub mid_offset_at_half: Option<f64>,
pub randomize_size: bool,
pub randomize_price: bool,
pub reference_contract_id: i32,
pub is_pegged_change_amount_decrease: bool,
pub pegged_change_amount: Option<f64>,
pub reference_change_amount: Option<f64>,
pub reference_exchange: String,
pub adjusted_order_type: String,
pub trigger_price: Option<f64>,
pub limit_price_offset: Option<f64>,
pub adjusted_stop_price: Option<f64>,
pub adjusted_stop_limit_price: Option<f64>,
pub adjusted_trailing_amount: Option<f64>,
pub adjustable_trailing_unit: i32,
pub conditions: Vec<OrderCondition>,
pub conditions_ignore_rth: bool,
pub conditions_cancel_order: bool,
pub soft_dollar_tier: SoftDollarTier,
pub is_oms_container: bool,
pub discretionary_up_to_limit_price: bool,
pub use_price_mgmt_algo: bool,
pub duration: Option<i32>, pub post_to_ats: Option<i32>,
pub customer_account: String,
pub professional_customer: bool,
pub bond_accrued_interest: String,
pub include_overnight: bool,
pub manual_order_indicator: Option<i32>,
pub submitter: String,
}
impl Default for Order {
fn default() -> Self {
Self {
order_id: 0,
solicited: false,
client_id: 0,
perm_id: 0,
action: Action::Buy,
total_quantity: 0.0,
order_type: "".to_owned(),
limit_price: None,
aux_price: None,
tif: TimeInForce::Day,
oca_group: "".to_owned(),
oca_type: OcaType::None,
order_ref: "".to_owned(),
transmit: true,
parent_id: 0,
block_order: false,
sweep_to_fill: false,
display_size: Some(0), trigger_method: conditions::TriggerMethod::Default,
outside_rth: false,
hidden: false,
good_after_time: "".to_owned(),
good_till_date: "".to_owned(),
override_percentage_constraints: false,
rule_80_a: None,
all_or_none: false,
min_qty: None,
percent_offset: None,
trail_stop_price: None,
trailing_percent: None,
fa_group: "".to_owned(),
fa_profile: "".to_owned(),
fa_method: "".to_owned(),
fa_percentage: "".to_owned(),
open_close: None,
origin: OrderOrigin::Customer,
short_sale_slot: ShortSaleSlot::None,
designated_location: "".to_owned(),
exempt_code: -1,
discretionary_amt: 0.0,
opt_out_smart_routing: false,
auction_strategy: None,
starting_price: None,
stock_ref_price: None,
delta: None,
stock_range_lower: None,
stock_range_upper: None,
volatility: None,
volatility_type: None,
continuous_update: false,
reference_price_type: None,
delta_neutral_order_type: "".to_owned(),
delta_neutral_aux_price: None,
delta_neutral_con_id: 0,
delta_neutral_settling_firm: "".to_owned(),
delta_neutral_clearing_account: "".to_owned(),
delta_neutral_clearing_intent: "".to_owned(),
delta_neutral_open_close: "".to_owned(),
delta_neutral_short_sale: false,
delta_neutral_short_sale_slot: 0,
delta_neutral_designated_location: "".to_owned(),
basis_points: Some(0.0),
basis_points_type: Some(0),
scale_init_level_size: None,
scale_subs_level_size: None,
scale_price_increment: None,
scale_price_adjust_value: None,
scale_price_adjust_interval: None,
scale_profit_offset: None,
scale_auto_reset: false,
scale_init_position: None,
scale_init_fill_qty: None,
scale_random_percent: false,
hedge_type: "".to_owned(),
hedge_param: "".to_owned(),
account: "".to_owned(),
settling_firm: "".to_owned(),
clearing_account: "".to_owned(),
clearing_intent: "".to_owned(),
algo_strategy: "".to_owned(),
algo_params: vec![],
what_if: false,
algo_id: "".to_owned(),
not_held: false,
smart_combo_routing_params: vec![],
order_combo_legs: vec![],
order_misc_options: vec![],
active_start_time: "".to_owned(),
active_stop_time: "".to_owned(),
scale_table: "".to_owned(),
model_code: "".to_owned(),
ext_operator: "".to_owned(),
cash_qty: None,
mifid2_decision_maker: "".to_owned(),
mifid2_decision_algo: "".to_owned(),
mifid2_execution_trader: "".to_owned(),
mifid2_execution_algo: "".to_owned(),
dont_use_auto_price_for_hedge: false,
auto_cancel_date: "".to_owned(),
filled_quantity: 0.0,
ref_futures_con_id: Some(0),
auto_cancel_parent: false,
shareholder: "".to_owned(),
imbalance_only: false,
route_marketable_to_bbo: false,
parent_perm_id: None,
advanced_error_override: "".to_owned(),
manual_order_time: "".to_owned(),
min_trade_qty: None,
min_compete_size: None,
compete_against_best_offset: None,
mid_offset_at_whole: None,
mid_offset_at_half: None,
randomize_size: false,
randomize_price: false,
reference_contract_id: 0,
is_pegged_change_amount_decrease: false,
pegged_change_amount: Some(0.0),
reference_change_amount: Some(0.0),
reference_exchange: "".to_owned(),
adjusted_order_type: "".to_owned(),
trigger_price: None,
limit_price_offset: None,
adjusted_stop_price: None,
adjusted_stop_limit_price: None,
adjusted_trailing_amount: None,
adjustable_trailing_unit: 0,
conditions: vec![],
conditions_ignore_rth: false,
conditions_cancel_order: false,
soft_dollar_tier: SoftDollarTier::default(),
is_oms_container: false,
discretionary_up_to_limit_price: false,
use_price_mgmt_algo: false,
duration: None,
post_to_ats: None,
customer_account: String::new(),
professional_customer: false,
bond_accrued_interest: String::new(),
include_overnight: false,
manual_order_indicator: None,
submitter: String::new(),
}
}
}
impl Order {
pub fn is_delta_neutral(&self) -> bool {
!self.delta_neutral_order_type.is_empty()
}
pub fn is_scale_order(&self) -> bool {
match self.scale_price_increment {
Some(price_increment) => price_increment > 0.0,
_ => false,
}
}
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Clone, Debug, Default, PartialEq, Eq, Copy, Serialize, Deserialize)]
pub enum Action {
#[default]
Buy,
Sell,
SellShort,
SellLong,
}
impl ToField for Action {
fn to_field(&self) -> String {
self.to_string()
}
}
impl std::fmt::Display for Action {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let text = match self {
Action::Buy => "BUY",
Action::Sell => "SELL",
Action::SellShort => "SSHORT",
Action::SellLong => "SLONG",
};
write!(f, "{text}")
}
}
impl Action {
pub fn reverse(self) -> Action {
match self {
Action::Buy => Action::Sell,
Action::Sell => Action::Buy,
Action::SellShort => Action::SellLong,
Action::SellLong => Action::SellShort,
}
}
pub fn from(name: &str) -> Self {
match name {
"BUY" => Self::Buy,
"SELL" => Self::Sell,
"SSHORT" => Self::SellShort,
"SLONG" => Self::SellLong,
&_ => todo!(),
}
}
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub enum TimeInForce {
#[default]
Day,
GoodTilCanceled,
ImmediateOrCancel,
GoodTilDate,
OnOpen,
FillOrKill,
DayTilCanceled,
Auction,
}
impl ToField for TimeInForce {
fn to_field(&self) -> String {
self.to_string()
}
}
impl std::fmt::Display for TimeInForce {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let text = match self {
TimeInForce::Day => "DAY",
TimeInForce::GoodTilCanceled => "GTC",
TimeInForce::ImmediateOrCancel => "IOC",
TimeInForce::GoodTilDate => "GTD",
TimeInForce::OnOpen => "OPG",
TimeInForce::FillOrKill => "FOK",
TimeInForce::DayTilCanceled => "DTC",
TimeInForce::Auction => "AUC",
};
write!(f, "{text}")
}
}
impl From<String> for TimeInForce {
fn from(value: String) -> Self {
Self::from(value.as_str())
}
}
impl From<&str> for TimeInForce {
fn from(value: &str) -> Self {
match value {
"DAY" => TimeInForce::Day,
"GTC" => TimeInForce::GoodTilCanceled,
"IOC" => TimeInForce::ImmediateOrCancel,
"GTD" => TimeInForce::GoodTilDate,
"OPG" => TimeInForce::OnOpen,
"FOK" => TimeInForce::FillOrKill,
"DTC" => TimeInForce::DayTilCanceled,
"AUC" => TimeInForce::Auction,
_ => TimeInForce::Day, }
}
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub enum OcaType {
#[default]
None = 0,
CancelWithBlock = 1,
ReduceWithBlock = 2,
ReduceWithoutBlock = 3,
}
impl ToField for OcaType {
fn to_field(&self) -> String {
i32::from(*self).to_string()
}
}
impl From<OcaType> for i32 {
fn from(value: OcaType) -> i32 {
value as i32
}
}
impl From<i32> for OcaType {
fn from(value: i32) -> Self {
match value {
0 => OcaType::None,
1 => OcaType::CancelWithBlock,
2 => OcaType::ReduceWithBlock,
3 => OcaType::ReduceWithoutBlock,
_ => OcaType::None,
}
}
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub enum OrderOrigin {
#[default]
Customer = 0,
Firm = 1,
}
impl ToField for OrderOrigin {
fn to_field(&self) -> String {
i32::from(*self).to_string()
}
}
impl From<OrderOrigin> for i32 {
fn from(value: OrderOrigin) -> i32 {
value as i32
}
}
impl From<i32> for OrderOrigin {
fn from(value: i32) -> Self {
match value {
0 => OrderOrigin::Customer,
1 => OrderOrigin::Firm,
_ => OrderOrigin::Customer,
}
}
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub enum ShortSaleSlot {
#[default]
None = 0,
Broker = 1,
ThirdParty = 2,
}
impl ToField for ShortSaleSlot {
fn to_field(&self) -> String {
i32::from(*self).to_string()
}
}
impl From<ShortSaleSlot> for i32 {
fn from(value: ShortSaleSlot) -> i32 {
value as i32
}
}
impl From<i32> for ShortSaleSlot {
fn from(value: i32) -> Self {
match value {
0 => ShortSaleSlot::None,
1 => ShortSaleSlot::Broker,
2 => ShortSaleSlot::ThirdParty,
_ => ShortSaleSlot::None,
}
}
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum VolatilityType {
Daily = 1,
Annual = 2,
}
impl ToField for VolatilityType {
fn to_field(&self) -> String {
i32::from(*self).to_string()
}
}
impl ToField for Option<VolatilityType> {
fn to_field(&self) -> String {
encode_option_field(self)
}
}
impl From<VolatilityType> for i32 {
fn from(value: VolatilityType) -> i32 {
value as i32
}
}
impl From<i32> for VolatilityType {
fn from(value: i32) -> Self {
match value {
1 => VolatilityType::Daily,
2 => VolatilityType::Annual,
_ => VolatilityType::Daily,
}
}
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum ReferencePriceType {
AverageOfNBBO = 1,
NBBO = 2,
}
impl ToField for ReferencePriceType {
fn to_field(&self) -> String {
i32::from(*self).to_string()
}
}
impl ToField for Option<ReferencePriceType> {
fn to_field(&self) -> String {
encode_option_field(self)
}
}
impl From<ReferencePriceType> for i32 {
fn from(value: ReferencePriceType) -> i32 {
value as i32
}
}
impl From<i32> for ReferencePriceType {
fn from(value: i32) -> Self {
match value {
1 => ReferencePriceType::AverageOfNBBO,
2 => ReferencePriceType::NBBO,
_ => ReferencePriceType::AverageOfNBBO,
}
}
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum Rule80A {
Individual,
Agency,
AgentOtherMember,
IndividualPTIA,
AgencyPTIA,
AgentOtherMemberPTIA,
IndividualPT,
AgencyPT,
AgentOtherMemberPT,
}
impl ToField for Rule80A {
fn to_field(&self) -> String {
self.to_string()
}
}
impl ToField for Option<Rule80A> {
fn to_field(&self) -> String {
encode_option_field(self)
}
}
impl std::fmt::Display for Rule80A {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let text = match self {
Rule80A::Individual => "I",
Rule80A::Agency => "A",
Rule80A::AgentOtherMember => "W",
Rule80A::IndividualPTIA => "J",
Rule80A::AgencyPTIA => "U",
Rule80A::AgentOtherMemberPTIA => "M",
Rule80A::IndividualPT => "K",
Rule80A::AgencyPT => "Y",
Rule80A::AgentOtherMemberPT => "N",
};
write!(f, "{text}")
}
}
impl Rule80A {
pub fn from(source: &str) -> Option<Self> {
match source {
"I" => Some(Rule80A::Individual),
"A" => Some(Rule80A::Agency),
"W" => Some(Rule80A::AgentOtherMember),
"J" => Some(Rule80A::IndividualPTIA),
"U" => Some(Rule80A::AgencyPTIA),
"M" => Some(Rule80A::AgentOtherMemberPTIA),
"K" => Some(Rule80A::IndividualPT),
"Y" => Some(Rule80A::AgencyPT),
"N" => Some(Rule80A::AgentOtherMemberPT),
_ => None,
}
}
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum AuctionStrategy {
Match = 1,
Improvement = 2,
Transparent = 3,
}
impl ToField for AuctionStrategy {
fn to_field(&self) -> String {
i32::from(*self).to_string()
}
}
impl ToField for Option<AuctionStrategy> {
fn to_field(&self) -> String {
encode_option_field(self)
}
}
impl From<AuctionStrategy> for i32 {
fn from(value: AuctionStrategy) -> i32 {
value as i32
}
}
impl From<i32> for AuctionStrategy {
fn from(value: i32) -> Self {
match value {
1 => AuctionStrategy::Match,
2 => AuctionStrategy::Improvement,
3 => AuctionStrategy::Transparent,
_ => AuctionStrategy::Match,
}
}
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct OrderComboLeg {
pub price: Option<f64>,
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum OrderCondition {
Price(PriceCondition),
Time(TimeCondition),
Margin(MarginCondition),
Execution(ExecutionCondition),
Volume(VolumeCondition),
PercentChange(PercentChangeCondition),
}
impl OrderCondition {
pub fn condition_type(&self) -> i32 {
match self {
Self::Price(_) => 1,
Self::Time(_) => 3,
Self::Margin(_) => 4,
Self::Execution(_) => 5,
Self::Volume(_) => 6,
Self::PercentChange(_) => 7,
}
}
pub fn is_conjunction(&self) -> bool {
match self {
Self::Price(c) => c.is_conjunction,
Self::Time(c) => c.is_conjunction,
Self::Margin(c) => c.is_conjunction,
Self::Execution(c) => c.is_conjunction,
Self::Volume(c) => c.is_conjunction,
Self::PercentChange(c) => c.is_conjunction,
}
}
}
impl ToField for OrderCondition {
fn to_field(&self) -> String {
self.condition_type().to_string()
}
}
impl ToField for Option<OrderCondition> {
fn to_field(&self) -> String {
encode_option_field(self)
}
}
impl From<i32> for OrderCondition {
fn from(val: i32) -> Self {
match val {
1 => OrderCondition::Price(PriceCondition::default()),
3 => OrderCondition::Time(TimeCondition::default()),
4 => OrderCondition::Margin(MarginCondition::default()),
5 => OrderCondition::Execution(ExecutionCondition::default()),
6 => OrderCondition::Volume(VolumeCondition::default()),
7 => OrderCondition::PercentChange(PercentChangeCondition::default()),
_ => panic!("OrderCondition({val}) is unsupported"),
}
}
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct SoftDollarTier {
pub name: String,
pub value: String,
pub display_name: String,
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct OrderData {
pub order_id: i32,
pub contract: Contract,
pub order: Order,
pub order_state: OrderState,
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct OrderState {
pub status: String,
pub initial_margin_before: Option<f64>,
pub maintenance_margin_before: Option<f64>,
pub equity_with_loan_before: Option<f64>,
pub initial_margin_change: Option<f64>,
pub maintenance_margin_change: Option<f64>,
pub equity_with_loan_change: Option<f64>,
pub initial_margin_after: Option<f64>,
pub maintenance_margin_after: Option<f64>,
pub equity_with_loan_after: Option<f64>,
pub commission: Option<f64>,
pub minimum_commission: Option<f64>,
pub maximum_commission: Option<f64>,
pub commission_currency: String,
pub margin_currency: String,
pub initial_margin_before_outside_rth: Option<f64>,
pub maintenance_margin_before_outside_rth: Option<f64>,
pub equity_with_loan_before_outside_rth: Option<f64>,
pub initial_margin_change_outside_rth: Option<f64>,
pub maintenance_margin_change_outside_rth: Option<f64>,
pub equity_with_loan_change_outside_rth: Option<f64>,
pub initial_margin_after_outside_rth: Option<f64>,
pub maintenance_margin_after_outside_rth: Option<f64>,
pub equity_with_loan_after_outside_rth: Option<f64>,
pub suggested_size: Option<f64>,
pub reject_reason: String,
pub order_allocations: Vec<OrderAllocation>,
pub warning_text: String,
pub completed_time: String,
pub completed_status: String,
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct OrderAllocation {
pub account: String,
pub position: Option<f64>,
pub position_desired: Option<f64>,
pub position_after: Option<f64>,
pub desired_alloc_qty: Option<f64>,
pub allowed_alloc_qty: Option<f64>,
pub is_monetary: bool,
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum OrderOpenClose {
Open,
Close,
}
impl ToField for OrderOpenClose {
fn to_field(&self) -> String {
self.to_string()
}
}
impl ToField for Option<OrderOpenClose> {
fn to_field(&self) -> String {
encode_option_field(self)
}
}
impl std::fmt::Display for OrderOpenClose {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let text = match self {
OrderOpenClose::Open => "O",
OrderOpenClose::Close => "C",
};
write!(f, "{text}")
}
}
impl OrderOpenClose {
pub fn from(source: &str) -> Option<Self> {
match source {
"O" => Some(OrderOpenClose::Open),
"C" => Some(OrderOpenClose::Close),
_ => None,
}
}
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Clone, Debug, Default)]
pub struct CommissionReport {
pub execution_id: String,
pub commission: f64,
pub currency: String,
pub realized_pnl: Option<f64>,
pub yields: Option<f64>,
pub yield_redemption_date: String,
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Clone, Debug, Default, PartialEq)]
pub enum Liquidity {
#[default]
None = 0,
AddedLiquidity = 1,
RemovedLiquidity = 2,
LiquidityRoutedOut = 3,
}
impl From<i32> for Liquidity {
fn from(val: i32) -> Self {
match val {
1 => Liquidity::AddedLiquidity,
2 => Liquidity::RemovedLiquidity,
3 => Liquidity::LiquidityRoutedOut,
_ => Liquidity::None,
}
}
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Clone, Debug, Default)]
pub struct Execution {
pub order_id: i32,
pub client_id: i32,
pub execution_id: String,
pub time: String,
pub account_number: String,
pub exchange: String,
pub side: String,
pub shares: f64,
pub price: f64,
pub perm_id: i32,
pub liquidation: i32,
pub cumulative_quantity: f64,
pub average_price: f64,
pub order_reference: String,
pub ev_rule: String,
pub ev_multiplier: Option<f64>,
pub model_code: String,
pub last_liquidity: Liquidity,
pub pending_price_revision: bool,
pub submitter: String,
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Clone, Debug, Default)]
pub struct ExecutionData {
pub request_id: i32,
pub contract: Contract,
pub execution: Execution,
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Clone, Debug)]
#[allow(clippy::large_enum_variant)]
pub enum PlaceOrder {
OrderStatus(OrderStatus),
OpenOrder(OrderData),
ExecutionData(ExecutionData),
CommissionReport(CommissionReport),
Message(crate::messages::Notice),
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Clone, Debug)]
#[allow(clippy::large_enum_variant)]
pub enum OrderUpdate {
OrderStatus(OrderStatus),
OpenOrder(OrderData),
ExecutionData(ExecutionData),
CommissionReport(CommissionReport),
Message(crate::messages::Notice),
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq)]
pub struct OrderStatus {
pub order_id: i32,
pub status: String,
pub filled: f64,
pub remaining: f64,
pub average_fill_price: f64,
pub perm_id: i32,
pub parent_id: i32,
pub last_fill_price: f64,
pub client_id: i32,
pub why_held: String,
pub market_cap_price: f64,
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Debug)]
pub enum CancelOrder {
OrderStatus(OrderStatus),
Notice(crate::messages::Notice),
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Debug)]
#[allow(clippy::large_enum_variant)]
pub enum Orders {
OrderData(OrderData),
OrderStatus(OrderStatus),
Notice(crate::messages::Notice),
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Debug, Default)]
pub struct ExecutionFilter {
pub client_id: Option<i32>,
pub account_code: String,
pub time: String,
pub symbol: String,
pub security_type: String,
pub exchange: String,
pub side: String,
pub last_n_days: i32,
pub specific_dates: Vec<String>,
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Debug)]
#[allow(clippy::large_enum_variant)]
pub enum Executions {
ExecutionData(ExecutionData),
CommissionReport(CommissionReport),
Notice(crate::messages::Notice),
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Debug, Clone, Copy)]
pub enum ExerciseAction {
Exercise = 1,
Lapse = 2,
}
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[allow(clippy::large_enum_variant)]
pub enum ExerciseOptions {
OpenOrder(OrderData),
OrderStatus(OrderStatus),
Notice(crate::messages::Notice),
}
#[cfg(feature = "sync")]
mod sync;
#[cfg(feature = "async")]
mod r#async;
#[cfg(feature = "sync")]
pub mod blocking {
pub(crate) use super::sync::{
all_open_orders, auto_open_orders, cancel_order, completed_orders, executions, exercise_options, global_cancel, next_valid_order_id,
open_orders, order_update_stream, place_order, submit_order,
};
}
#[cfg(feature = "async")]
pub(crate) use r#async::{
all_open_orders, auto_open_orders, cancel_order, completed_orders, executions, exercise_options, global_cancel, next_valid_order_id, open_orders,
order_update_stream, place_order, submit_order,
};