Trade

Struct Trade 

Source
pub struct Trade {
Show 36 fields pub account_id: String, pub transaction_id: Option<String>, pub ib_order_id: Option<String>, pub exec_id: Option<String>, pub trade_id: Option<String>, pub conid: String, pub symbol: String, pub description: Option<String>, pub asset_category: AssetCategory, pub multiplier: Option<Decimal>, pub underlying_conid: Option<String>, pub underlying_symbol: Option<String>, pub strike: Option<Decimal>, pub expiry: Option<NaiveDate>, pub put_call: Option<PutCall>, pub trade_date: NaiveDate, pub trade_time: Option<String>, pub settle_date: NaiveDate, pub buy_sell: Option<BuySell>, pub open_close: Option<OpenClose>, pub order_type: Option<OrderType>, pub quantity: Option<Decimal>, pub price: Option<Decimal>, pub amount: Option<Decimal>, pub proceeds: Decimal, pub commission: Decimal, pub commission_currency: Option<String>, pub taxes: Option<Decimal>, pub net_cash: Option<Decimal>, pub cost: Option<Decimal>, pub fifo_pnl_realized: Option<Decimal>, pub mtm_pnl: Option<Decimal>, pub fx_pnl: Option<Decimal>, pub currency: String, pub fx_rate_to_base: Option<Decimal>, pub listing_exchange: Option<String>,
}
Expand description

A single trade execution

Represents one trade execution from the Activity FLEX statement. Includes all trade details: security info, quantities, prices, fees, and P&L.

§Example

use ib_flex::parse_activity_flex;
use ib_flex::{AssetCategory, BuySell};

let xml = std::fs::read_to_string("activity.xml")?;
let statement = parse_activity_flex(&xml)?;

for trade in &statement.trades.items {
    // Access basic trade info
    println!("Symbol: {}", trade.symbol);
    println!("Asset: {:?}", trade.asset_category);

    // Check trade direction
    match trade.buy_sell {
        Some(BuySell::Buy) => println!("Bought"),
        Some(BuySell::Sell) => println!("Sold"),
        _ => {}
    }

    // Calculate total cost
    let quantity = trade.quantity.unwrap_or_default();
    let price = trade.price.unwrap_or_default();
    let cost = quantity * price;
    println!("Cost: {}", cost);

    // Access P&L if available
    if let Some(pnl) = trade.fifo_pnl_realized {
        println!("Realized P&L: {}", pnl);
    }

    // Check for options
    if trade.asset_category == AssetCategory::Option {
        println!("Strike: {:?}", trade.strike);
        println!("Expiry: {:?}", trade.expiry);
        println!("Put/Call: {:?}", trade.put_call);
    }
}

Fields§

§account_id: String

IB account number

§transaction_id: Option<String>

IB transaction ID (unique identifier for idempotency)

§ib_order_id: Option<String>

IB order ID (may be shared across multiple executions)

§exec_id: Option<String>

Execution ID

§trade_id: Option<String>

Trade ID

§conid: String

IB contract ID (unique per security)

§symbol: String

Ticker symbol

§description: Option<String>

Security description

§asset_category: AssetCategory

Asset category (stock, option, future, etc.)

§multiplier: Option<Decimal>

Contract multiplier (for futures/options)

§underlying_conid: Option<String>

Underlying security’s contract ID (for derivatives)

§underlying_symbol: Option<String>

Underlying symbol

§strike: Option<Decimal>

Strike price (for options)

§expiry: Option<NaiveDate>

Expiry date (for options/futures)

§put_call: Option<PutCall>

Put or Call (for options)

§trade_date: NaiveDate

Trade date

§trade_time: Option<String>

Trade time (date + time) - parsed from dateTime field

§settle_date: NaiveDate

Settlement date

§buy_sell: Option<BuySell>

Buy or Sell

§open_close: Option<OpenClose>

Open or Close indicator (for options/futures)

§order_type: Option<OrderType>

Order type (market, limit, stop, etc.)

§quantity: Option<Decimal>

Quantity (number of shares/contracts)

§price: Option<Decimal>

Trade price per share/contract

§amount: Option<Decimal>

Trade amount

§proceeds: Decimal

Trade proceeds (negative for buys, positive for sells)

§commission: Decimal

Commission paid

§commission_currency: Option<String>

Commission currency

§taxes: Option<Decimal>

Taxes paid

§net_cash: Option<Decimal>

Net cash (proceeds + commission + taxes)

§cost: Option<Decimal>

Cost

§fifo_pnl_realized: Option<Decimal>

FIFO realized P&L (for closing trades)

§mtm_pnl: Option<Decimal>

Mark-to-market P&L

§fx_pnl: Option<Decimal>

FX P&L (for multi-currency)

§currency: String

Trade currency

§fx_rate_to_base: Option<Decimal>

FX rate to base currency

§listing_exchange: Option<String>

Listing exchange

Trait Implementations§

Source§

impl Clone for Trade

Source§

fn clone(&self) -> Trade

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Trade

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Trade

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Trade

Source§

fn eq(&self, other: &Trade) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Trade

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Trade

Auto Trait Implementations§

§

impl Freeze for Trade

§

impl RefUnwindSafe for Trade

§

impl Send for Trade

§

impl Sync for Trade

§

impl Unpin for Trade

§

impl UnwindSafe for Trade

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,