Skip to main content

Trade

Struct Trade 

Source
pub struct Trade {
Show 88 fields pub account_id: String, pub transaction_id: Option<String>, pub conid: String, pub symbol: String, pub description: Option<String>, pub asset_category: AssetCategory, pub cusip: Option<String>, pub isin: Option<String>, pub figi: Option<String>, pub security_id: Option<String>, pub security_id_type: Option<String>, pub multiplier: Option<Decimal>, pub strike: Option<Decimal>, pub expiry: Option<NaiveDate>, pub put_call: Option<PutCall>, pub underlying_conid: Option<String>, pub underlying_symbol: Option<String>, pub trade_date: Option<NaiveDate>, pub settle_date: Option<NaiveDate>, pub buy_sell: Option<BuySell>, pub open_close: Option<OpenClose>, pub transaction_type: Option<String>, pub quantity: Option<Decimal>, pub price: Option<Decimal>, pub proceeds: Option<Decimal>, pub cost: Option<Decimal>, pub commission: Option<Decimal>, pub taxes: Option<Decimal>, pub net_cash: 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 orig_trade_date: Option<NaiveDate>, pub orig_trade_price: Option<Decimal>, pub orig_trade_id: Option<String>, pub holding_period_date_time: Option<String>, pub open_date_time: Option<String>, pub when_reopened: Option<String>, pub notes: Option<String>, pub ib_order_id: Option<String>, pub exec_id: Option<String>, pub trade_id: Option<String>, pub orig_transaction_id: Option<String>, pub orig_order_id: Option<String>, pub trade_time: Option<String>, pub when_realized: Option<String>, pub order_time: Option<String>, pub order_type: Option<OrderType>, pub brokerage_order_id: Option<String>, pub order_reference: Option<String>, pub exch_order_id: Option<String>, pub ext_exec_id: Option<String>, pub ib_exec_id: Option<String>, pub issuer: Option<String>, pub issuer_country_code: Option<String>, pub sub_category: Option<String>, pub listing_exchange: Option<String>, pub underlying_listing_exchange: Option<String>, pub underlying_security_id: Option<String>, pub trader_id: Option<String>, pub is_api_order: Option<String>, pub volatility_order_link: Option<String>, pub clearing_firm_id: Option<String>, pub level_of_detail: Option<String>, pub amount: Option<Decimal>, pub trade_money: Option<Decimal>, pub close_price: Option<Decimal>, pub change_in_price: Option<Decimal>, pub change_in_quantity: Option<Decimal>, pub commission_currency: Option<String>, pub related_trade_id: Option<String>, pub related_transaction_id: Option<String>, pub accrued_int: Option<Decimal>, pub principal_adjust_factor: Option<Decimal>, pub serial_number: Option<String>, pub delivery_type: Option<String>, pub commodity_type: Option<String>, pub fineness: Option<Decimal>, pub weight: Option<String>, pub report_date: Option<NaiveDate>, pub exchange: Option<String>, pub model: Option<String>, pub acct_alias: Option<String>, pub rtn: Option<String>, pub position_action_id: Option<String>, pub initial_investment: Option<Decimal>,
}
Expand description

A single trade execution

Represents one trade execution from the Activity FLEX statement. Fields are organized into CORE (essential for tax/portfolio analytics) and EXTENDED (metadata, execution details) sections.

§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)

§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.)

§cusip: Option<String>

CUSIP

§isin: Option<String>

ISIN

§figi: Option<String>

FIGI

§security_id: Option<String>

Security ID

§security_id_type: Option<String>

Security ID type

§multiplier: Option<Decimal>

Contract multiplier (for futures/options)

§strike: Option<Decimal>

Strike price (for options)

§expiry: Option<NaiveDate>

Expiry date (for options/futures)

§put_call: Option<PutCall>

Put or Call (for options)

§underlying_conid: Option<String>

Underlying security’s contract ID (for derivatives)

§underlying_symbol: Option<String>

Underlying symbol

§trade_date: Option<NaiveDate>

Trade date (may be empty for summary records)

§settle_date: Option<NaiveDate>

Settlement date (may be empty for summary records)

§buy_sell: Option<BuySell>

Buy or Sell

§open_close: Option<OpenClose>

Open or Close indicator (for options/futures)

§transaction_type: Option<String>

Transaction type (ExchTrade, BookTrade, etc.)

§quantity: Option<Decimal>

Quantity (number of shares/contracts)

§price: Option<Decimal>

Trade price per share/contract

§proceeds: Option<Decimal>

Trade proceeds (negative for buys, positive for sells)

§cost: Option<Decimal>

Cost basis

§commission: Option<Decimal>

Commission paid

§taxes: Option<Decimal>

Taxes paid

§net_cash: Option<Decimal>

Net cash (proceeds + commission + taxes)

§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

§orig_trade_date: Option<NaiveDate>

Original trade date (for lot tracking and holding period)

§orig_trade_price: Option<Decimal>

Original trade price (cost basis of the lot)

§orig_trade_id: Option<String>

Original trade ID (links closing trade to opening trade)

§holding_period_date_time: Option<String>

Holding period date/time (for long-term vs short-term determination)

§open_date_time: Option<String>

When position was opened

§when_reopened: Option<String>

When position was reopened (for wash sale tracking)

§notes: Option<String>

Trade notes/codes (may contain wash sale indicator “W”)

§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

§orig_transaction_id: Option<String>

Original transaction ID

§orig_order_id: Option<String>

Original order ID

§trade_time: Option<String>

Trade time (date + time)

§when_realized: Option<String>

When P&L was realized

§order_time: Option<String>

Order time

§order_type: Option<OrderType>

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

§brokerage_order_id: Option<String>

Brokerage order ID

§order_reference: Option<String>

Order reference

§exch_order_id: Option<String>

Exchange order ID

§ext_exec_id: Option<String>

External execution ID

§ib_exec_id: Option<String>

IB execution ID

§issuer: Option<String>

Issuer

§issuer_country_code: Option<String>

Issuer country code

§sub_category: Option<String>

Sub-category

§listing_exchange: Option<String>

Listing exchange

§underlying_listing_exchange: Option<String>

Underlying listing exchange

§underlying_security_id: Option<String>

Underlying security ID

§trader_id: Option<String>

Trader ID

§is_api_order: Option<String>

Is API order

§volatility_order_link: Option<String>

Volatility order link

§clearing_firm_id: Option<String>

Clearing firm ID

§level_of_detail: Option<String>

Level of detail (EXECUTION, ORDER, CLOSED_LOT, etc.)

§amount: Option<Decimal>

Trade amount

§trade_money: Option<Decimal>

Trade money (quantity * price)

§close_price: Option<Decimal>

Close price

§change_in_price: Option<Decimal>

Change in price

§change_in_quantity: Option<Decimal>

Change in quantity

§commission_currency: Option<String>

Commission currency

§related_trade_id: Option<String>

Related trade ID

§related_transaction_id: Option<String>

Related transaction ID

§accrued_int: Option<Decimal>

Accrued interest

§principal_adjust_factor: Option<Decimal>

Principal adjust factor

§serial_number: Option<String>

Serial number (for physical delivery)

§delivery_type: Option<String>

Delivery type

§commodity_type: Option<String>

Commodity type

§fineness: Option<Decimal>

Fineness (for precious metals)

§weight: Option<String>

Weight

§report_date: Option<NaiveDate>

Report date

§exchange: Option<String>

Exchange where trade executed

§model: Option<String>

Model (for model portfolios)

§acct_alias: Option<String>

Account alias

§rtn: Option<String>

RTN

§position_action_id: Option<String>

Position action ID

§initial_investment: Option<Decimal>

Initial investment

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>,